Recently Posted Content
Dear blog, Post on Nov 22, 2011
I know I haven't been spending much time with you lately, I've been very busy at work tinkering with Django and Node.js. I really do love you...
Python, PIL and Gaussian Blur Post on May 28, 2011
I have been searching high and low for a good gaussian blur for Python, I looked at ScyPy, Numpy, a bunch of random hand-coded versions around the internet, and it turns out that there's one built into PIL (v1.1.5). Not sure how fast it is compared to other versions, but the important part for me is, it's there. Just not documented (that I could find...)
The other problem
Turns out, if you look at the source, ImageFilter.py line 156(ish).
class GaussianBlur(Filter):
name = "GaussianBlur"
def __init__(self, radius=2):
self.radius = 2
def filter(self, image):
return image.gaussian_blur(self.radius)
...but if you look closely under the constructor, self.radius isn't assigned to the value passed into to method, it's hard-coded to 2!!! Blasphemy!
So I borrowed theirs and fixed it:
class MyGaussianBlur(ImageFilter.Filter):
name = "GaussianBlur"
def __init__(self, radius=2):
self.radius = radius
def filter(self, image):
return image.gaussian_blur(self.radius)
Sweetness, gaussian blur for PIL.
af
The hunt for the perfect markup language Post on May 13, 2011
I'm just adding quick note, there's so many things I should blog about, and tonight I find myself researching markup languages... who thought there would be so many, and that they were so important.
Some (not so light) reading: http://en.wikipedia.org/wiki/List_of_markup_languages
Cheers, af
Twisted.web, WSGI and Django Post on Apr 26, 2011
W00t!
Now this is fun, I think I just said 'adios' to Apache (for the time being, anyway). Thanks to this post I just married my django site with twisted.
# web.application means 'web.py' twistd -no web --wsgi=web.application
Couple that with node.js reverse proxy and I'm one happy dude.
Fun fun!
[edit]
# bind to local interface twistd -no web --wsgi=web.application --port tcp:interface=127.0.0.1:port=8080 --logfile=foo.log
Markdown and Django Post on Apr 25, 2011
Note to self (aren't they all...)
One line after {% filter markdown %} or it renders as code...
One handy command Post on Apr 25, 2011
Read: DNS resolving woes and hairpulling resolved:
ipconfig /flushdns
Context: windows
Rubygems on Ubuntu 10.4 Post on Apr 22, 2011
... aka "note to self"
Trying to install sproutcore on an ubuntu machine, but sproutcore complains of rubygems being < 1.3.6
http://stackoverflow.com/questions/2777831/how-can-i-get-rubygems-1-3-6-on-ubuntu-10-4
Django Unit test (note to self) Post on Apr 05, 2011
TestCase methods must start with 'def test...' :)
AWS, BindDNS, and custom name servers Post on Apr 05, 2011
I just wanted to plug a little "note to self" on here, I was setting up a custom name server on a Webmin install on AWS. My EC2 instance was running fine, http requests were responding fine as long as I used the IP or a custom hosts file on my machine. The domain was hosted with Godaddy, and I had changed the nameserver entries to my custom nameserver. I also had entries in the Godaddy 'custom hosts' setup pointing my custom nameservers to my IP. BINDDNS is running, but still no cake, so what was the problem?
I needed to add an ICMP security rule for my AWS Security Group, the DNS requests to my machine weren't making it through. Add security rule, boom, site's up, everybody's happy.
AWS is kinda fun actually, once you've lost all your hair...
af
PyAMF and _version issue Post on Mar 23, 2011
I ran into this dumb issue trying to run an old project today:
... Could not import myapp.views. Error was: cannot import name _version ...
I had to actually break into the Django shell and try to import views from there to get a meaningful traceback, turns out the PyAMF __init__.py file was trying to do this:
from pyamf import util, _version
... and it wasn't lying, there was no _verion.py or _version folder or anything. A little googling found this page which revealed on the first line that the _version.py file is generated when "python setup.py install" is run to install pyamf. Well, that's all fine and good unless you're like me and almost never install modules into the main Python library unless absolutely necessary, I like to just put them on the python path, it makes upgrading modules much easier. So I cracked into the FBI mainframe and forced an assertion on the library (read: being super-stealthy, I created the file and pasted the expected code into it):
# THIS FILE IS GENERATED BY PYAMF SETUP.PY from pyamf.versions import Version version = Version(*(0, 6, 1))
Cheers! af
Serve Wordpress from subfolder Post on Nov 17, 2010
I come across this a fair bit: I develop a new site on a client machine in a subfolder called /2010/ (for example) using Wordpress, and then when it comes time to deploy, I want to put the files on the main domain, but I don't want to move the files to the root web folder (or can't). This can easily be done with changing the DocumentRoot directive in Apache, but sometimes I don't have access to the Apache config, or whatever the server config may be.
The solution surfaced here:
# .htaccess primary domain to subfolder redirect
# Copy and paste the following code into the .htaccess file
# in the public_html folder of your hosting account
# make the changes to the file according to the instructions.
# Do not change this line.
RewriteEngine on
# Change yourdomain.com to be your primary domain.
RewriteCond %{HTTP_HOST} ^(www.)?yourprimarydomain.com$
# Change 'subfolder' to be the folder you will use for your primary domain.
RewriteCond %{REQUEST_URI} !^/subfolder/
# Don't change this line.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subfolder' to be the folder you will use for your primary domain.
RewriteRule ^(.*)$ /subfolder/$1
# Change yourdomain.com to be your primary domain again.
# Change 'subfolder' to be the folder you will use for your primary domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?yourmaindomain.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
This will transparently serve a Wordpress install in /subfolder/ at the yourprimarydomain.com domain.
Cheers,
Aaron
Bazaar DVCS upload plugin Post on Oct 26, 2010
I've known that I needed to move to a DVCS for a while, but, being busy as usual, I haven't had the time to try out one of the few popular systems. Recently I have been faced with a recurring challenge: managing Wordpress template and plugin customizations on client sites where I don't have shell access.
The first couple I didn't weren't a really big deal, just jump in and edit some files, upload via FTP, no problem. But, as usual, it started to bite me in the ass: more changes were being requested, and it was often easier to edit the files online through the Wordpress admin interface than locally and then upload, rinse and repeat.
So, I received a request from a client to work on a site from a couple months ago. It became clear to me that I was losing my mind: were the local files most recent, or were the remote files most recent? I couldn't take it any more. I was bound to find a bloody VCS that would work over FTP.
Turns out it's Bazaar
Not to be confused with 'bizarre'.
Bazaar is a version control system written in Python (yay!), and while it doesn't have the functionality built right in, there's a little plugin called Bazaar Upload which installs in seconds (python setup.py install) and works like a dream.
Workflow
I learned what I needed to know about Bazaar in about 5 minutes. Just a quick tutorial from their documentation and I was up and running. Here's the rundown (by the way, I'm using Unix Utils in Windows):
// change to an existing wordpress directory locally $ cd wordpress // set up bazaar in the current folder $ bzr init Created a standalone tree (format: 2a) // add some files to the repo (let's say the theme) $ bzr add wp-content/themes/some-theme adding wp-content adding wp-content/themes ... // now commit the files to the repo $ bzr commit -m "Added only the files I want to keep track of" Committing to: C:/wamp/www/wordpress/ added wp-content/ added wp-content/themes added ... Committed revision 1. // now the fun part: send the files we've changed to //our production environment, make sure you have //the bzr_upload plugin installed $ bzr upload sftp://aaron@someproject.com/~/public_html/new-site // Asks for authentication... Uploading wp-content Uploading... // alternatively, we can use ftp also, but notice // the path is different $ bzr upload ftp://aaron@someproject.com/new-site // Asks for authentication Uploading wp-content Uploading ... // A note on sftp vs ftp: sftp uses the SSH protocol so it logs // you into the ~ (home) folder of your web server, so you specify // the path like you would in a unix environment. Ftp logs you // in as if you were the ftp user, so the path may be different
Now, the next time you make a change to a file, you just
$ bzr upload
Done and done.
Awesome! The end.
Satchmo store and YAML fixtures Post on Oct 20, 2010
I have been working on a Satchmo installation, which is pretty intense because of the size of the project, but, because it's Django, it's still relatively simple to find what I need. Recently I got the error:
ContactRole matching query does not exist
It was pretty simple, although not obvious at first. The YAML fixtures for the satchmo_store.contact app weren't installing because I didn't have PyYAML installed on my machine. A quick installation, another syncdb and boom, good to go.
Cheers, Aaron
Flash debug player and Google Chrome Post on Oct 13, 2010
What a pain this was, even though it was simple. To get debug player in Chrome, install the debug player from the Adobe site, go to chrome://plugins/ and you will see Shockwave Flash listed in there somewhere, it probably says "2 files". Simply hitting 'Disable' will shut off all flash players for Chrome, so press the little "Details" + button in the upper right, and only disable the player that's in the Chrome directory. Next time you open a Flash movie, Chrome will use the other player.
Cheers,
Aaron
jQuery, jCarousel, circular wrap and auto scroll Post on Oct 06, 2010
I recently needed a carousel for a site and decided to go with jCarousel, as it seemed to have the most flexibility in terms of what I was looking for. Only one problem though: I wanted to have both 'circular' wrap mode and auto scrolling enabled for my carousel, and as several people have reported, it doesn't seem to work.
The solution
Turns out the fix really wasn't that hard. Even with 'wrap' mode set to 'circular' on auto scroll, the carousel would still tell itself to shut down when it reached the end of the line of images. Probably a bug, but no biggie.
Just listen for the onAfterAnimation event and fire it back up:
// our event listener receives the carousel
// object, so we just check to see if it's
// turned itself off or not...
function afterAnimation(carousel){
if(carousel.autoStopped){
carousel.startAuto()
}
}
jQuery(document).ready(function(){
var options = {
auto: 2.5,
scroll:1,
wrap: 'last', // with this solution, wrap doesn't matter any more
// itemLastInCallBack fires when a new 'last' image
// shows up
itemLastInCallback:{
onAfterAnimation: afterAnimation
}
}
jQuery('.carousel').jcarousel(options);
})
That's it!
Happy trails
Aaron
| Older entries > |