-
Pet Projects
Category Archives: General
For example, when you want to save an image from a URL. https://github.com/images/modules/header/logov3-hover.png f = urllib.urlopen(request.POST[’url’]) p = os.path.join(settings.UPLOAD_DIRECTORY, "saved_file.jpg") filesize = 0 with open(p,’wb’) as output: while True: buf = f.read(65536) filesize += len(buf) if not buf: break output.write(buf)
In some cases you would want to have “private” images for your logged-in users, you will not be able to store the images in the public accessible directory. For example, if you have “my_private_photo.png” stored in your normal “images” directory, … Continue reading
Here is how to setup/install mod_xsendfile in Apache2 + Django (mod_wsgi). First do this to install apxs2 $> sudo apt-get install apache2-prefork-dev Download mod_xsendfile: http://tn123.ath.cx/mod_xsendfile/ Install it by doing this: $> apxs2 -cia mod_xsendfile.c If you get an error compiling … Continue reading
I am planning to build something involving serving large files over HTTP. Putting the files in a public accessible directory is not an option since I need to monitor the users who download the file. Users will need to login … Continue reading
What is Tkinter? Tkinter is Python’s de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk. Here is a simple Tkinter example. The code below should generate a very simple GUI with a … Continue reading
This is the basic structure of a Python class. >>> class Simplex: … "An example class""" … def __init__(self, x, y): … self.a = x … self.b = y … def addition(self): … return self.a + self.b … >>> z … Continue reading
Lists A list is a sequence of values. [ and ] like numerically indexed arrays in PHP >>> # a list of numbers >>> my_numbers = [10, 15, 20, 25] >>> print my_numbers [10, 15, 20, 25] >>> >>> #a … Continue reading
Another Python post! I am still learning the language. Since I cannot remember everything, I am posting it here for future reference. Get the Current Working Directory To get the “current working directory” do this: import os current_dir = os.getcwd() … Continue reading
This is probably my first post for Django. I have only been using it for a few weeks and I am already falling in love with it. Here is how to do an AJAX “save” using jQuery and Django. My … Continue reading
This is probably in the WordPress documentation but to enable widgets in your own customized theme, do this: … rest of PHP and HTML code in your here … <div id="sidebar"> <ul> <?php if ( ! dynamic_sidebar( ‘primary-widget-area’ ) ) … Continue reading