Content for the category "General Posts"
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
Django and multiple joins on the same table Post on Jan 22, 2010
I picked up this trick back using Wordpress, which I always kinda liked, you scenario: you have a Content model and a Date model, but the Date model is generically-related:
#django models
class Date(models.Model):
# GR stuff
content_type = models.ForeignKey(ContentType, null=True, blank=True)
object_id = models.PositiveIntegerField(null=True, blank=True)
content_object = generic.GenericForeignKey()
# actual data
key = models.CharField(max_length=75)
date = models.DateTimeField()
class Content(models.Model):
title = models.CharField(max_length=75)
body = models.TextField()
dates = generic.GenericRelation(Date)
The reason you would do this is so you could have as many dates related to the content as you wanted (you don't have to use a generic relation for this, but I like to use dates on lots of things).
What fun
I'm a little eccentric, I like to do wierd things, like with Django's .extra() method on querysets, you can do some funky stuff, like pull several of the generically-related dates based on their 'key' value, and add that 'key' value directly to the Content object as though it were a native attribute. Something like this:
>>> from myapp.models import Content, Date >>> from datetime import datetime >>> content = Content(title="Hello", body="My content :)") >>> content.save() >>> post_date = Date(key='post_date', date=datetime.now()) >>> post_date.save() >>> content.dates.add(post_date) >>> modified_date = Date(key='modified_date', date=datetime.now)) >>> modified_date.save() >>> content.dates.add(modified_date)
Now the trick here is to join the myapp_date table on to our content twice, which is easy enough:
>>> content = Content.objects.all() >>> content.filter(dates__key='post_date') >>> content.filter(dates__key='modified_date')
But now we have a problem
Because django is so wonderful, it does all the work of joining tables and keeping track of those pesky aliases for you, but how do we select the dates from the joined tables (using .extra(select={xxx})) if we don't know the aliases? Well we can spit out the query, as mentioned in the django docs, and that works fine (for now):
>>> print content.query # live on the edge...
# the result is something like:
SELECT "myapp_content"."title", "myapp_content"."body" FROM "myapp_content" INNER JOIN "myapp_date" ON ("myapp_content"."id" = "myapp_date"."object_id") INNER JOIN "myapp_date" T2 ON ("myapp_content"."id" = T2."object_id") WHERE ("myapp_date"."key" = "post_date" AND T2."key" = "modified_date")
# Disclaimer: I wrote this query by hand, it's an approximation, yours may differ, also note: it's pretty damn close.
Now if you were just feeling adventurous, you could simply nab the alias names from that query and grab the extra data as needed:
>>> content.extra(select={'post_date': 'myapp_date.date', 'modified_date': 'T2.date'})
>>> print content.query
# the result is something like:
SELECT (myapp_date.date) AS post_date, (T2.date) AS modified_date, "myapp_content"."title", "myapp_content"."body" FROM "myapp_content" INNER JOIN "myapp_date" ON ("myapp_content"."id" = "myapp_date"."object_id") INNER JOIN "myapp_date" T2 ON ("myapp_content"."id" = T2."object_id") WHERE ("myapp_date"."key" = "post_date" AND T2."key" = "modified_date")
# extra(select={}) just pops a couple extra selects in there, like it should, but yuck, static references ie: T2
>>> content[0].post_date
datetime.datetime(2010, ...)
>>> content[0].modified_date
datetime.datetime(2010, ...)
Fun huh?
But, there is a gotcha...
I had been employing this method in an application, and arbitrarily decided to upgrade my django. Lo' and behold, the alias names changed! Whooda thought? So after much turmoil and source-code-diggery, I found the way to get those pesky aliases (and therefore perform the query) without all the guilt. The trick was I had to find the place in django.db.models.sql.query.Query where the table alias (T2) was related to the part in the where clause that was related to the field (post_until). The answer was in the content object's where clause, something like:
>>> content.query.where.children [(<django.db.models.sql.where.constraint object="object" at="at">, 'exact', True, 'post_date'),(</django.db.models.sql.where.constraint><django.db.models.sql.where.constraint object="object" at="at">, 'exact', True, 'modified_date'),...] >>> content.query.where.children[0].alias # < the constraint holds the key, literally 'myapp_date' >>> content.query.where.children[1].alias 'T2' </django.db.models.sql.where.constraint>
And there you have it
So my quick solution to keep the aliases produced by they code referenced dynamically, I just build a quick little dict out of the 'where.children' so I could reference the aliases properly later...
# summed up
>>> content = Content.objects.all()
>>> content.filter(dates__key='post_date')
>>> content.filter(dates__key='modified_date')
>>> alias_map = {}
>>> for condition in content.query.where.children:
... # alias_map['modified_date'] = 'T2'
... alias_map[condition[3]] = condition[0].alias
>>> content.extra(select={ \
... 'post_date': '%s.date' % alias_map['post_date'], \
... 'modified_date': '%s.date' % alias_map['modified_date']})
And with that, the keys end up as they should. Nothing spectacular, it just took some digging to find where the join "black magic" was happening in django. Thanks to jtiai on #django for the pointers.
Hope that really helps someone down the line,
Aaron
Flex Django and AMF Post on Dec 15, 2009
Been working back in Flex again a bit, using Vim in Linux for a while, but I been really impressed with the short compile times in FlashDevelop for Windows.
Besides the point
Having become increasingly frustrated with the shortcomings of Django-amf, I've decided to give pyamf another try. I tried it the first time around, and got hung up on an error that made me bail out on it:
Cannot find a view for the path ['/gateway/cardservice/echo'], 'DjangoGateway' object has no attribute '__name__'
Some poking around in the source didn't help any, but the fix turned out to be easy. I stumbled on this post on StackOverflow, the author answered his own question in his comment. Turns out, leaving the django-amf middleware turned on in the settings.py file messed up the operation.
I don't have enough clout on StackOverflow to tell the author thanks there, so I'll do it here...
Aaron
Adbusters + Pioneer General Store = Whoa! Post on Dec 09, 2009
I nearly shat myself today. And there is nothing glorious about that!
I was standing at the checkout of "the Pioneer" (the little general store smack in the middle of Caroline, AB, population 500 [including the cats]) and I glanced across a magazine that stuck out in the middle of the tabloids (the usual mental staple of Carolinites) like a sore hip > lo and behold a copy of Adbusters!
Shock set in
I says to the lady at the till (as I set the magazine down for purchase), I says, "this magazine is a little progressive for poor, little, innocent (read:hick) Caroline, isn't it?" :O
Well, it was a wasted effort, she didn't get it. Still made my day, though.
Af
Google Chrome for Linux Post on Dec 09, 2009
I just installed Google Chrome for Linux yesterday, and decided to try it out. It's been bugging me lately that my application set in Linux (vim, svn, irssi, etc) are all snappy, and yet Firefox is still a little slow (even with most of my plugins shut off). I've been craving a faster browser, and some of the others just don't make the cut.
Thank you Google
I signed up for the Chrome release mailing list and got the email yesterday:
Hello everybody out there using Linux - Google Chrome is go for beta on Linux! Thanks to the many Chromium and WebKit developers who helped make Google Chrome a lean, mean browsing machine. Here are a few fun facts from us on the Google Chrome for Linux team: 60,000 lines of Linux-specific code written 23 developer builds 2,713 Linux-specific bugs fixed 12 external committers and bug editors to the Google Chrome for Linux code base, 48 external code contributors Thanks for waiting and we hope that you enjoy using Google Chrome! Google Chrome Team
Installed like a snap, and it sure is snappy. The developer tools are looking quite promising also...
Sorry Firefox, looks like Chrome may be here to stay...
Af
Vim and ^M Dos characters Post on Dec 04, 2009
I've been working on a Flex project recently, one that I used to compile in Windows, but have since moved over to Linux with the Flex SDK. One of the problems I run into is that Dos appears to leave these characters in my files at the end of each line
// a comment in my flex file^M
The solution
It's painful to have to delete them all manually, so a simple command in vim will do it:
:1,$ s/^M//
To get the ^M you can hit 'Ctrl+v' and then 'Enter'
Aaron
Dreamhost, Django, Premature end of script headers: dispatch.fcgi Post on Oct 28, 2009
This problem comes up from time to time on my Dreamhost account, I get a long page load, finally ending with a 500 error in the browser. Tail'ing the apache error_log shows:
... [Wed Oct 28 13:48:37 2009] [error] [client 198.53.10.99] Premature end of script headers: dispatch.fcgi [Wed Oct 28 13:48:37 2009] [error] [client 198.53.10.99] Premature end of script headers: dispatch.fcgi [Wed Oct 28 13:48:40 2009] [error] [client 198.53.10.99] Premature end of script headers: dispatch.fcgi [Wed Oct 28 13:49:18 2009] [error] [client 198.53.10.99] Premature end of script headers: dispatch.fcgi [Wed Oct 28 13:49:21 2009] [error] [client 198.53.10.99] Premature end of script headers: dispatch.fcgi [Wed Oct 28 13:49:58 2009] [error] [client 198.53.10.99] Premature end of script headers: dispatch.fcgi [Wed Oct 28 13:50:39 2009] [error] [client 198.53.10.99] Premature end of script headers: dispatch.fcgi ...
But where's the real error?
A little trick for you: go to the folder where your dispatch.fcgi file is and type:
./dispatch.fcgi
Basically you are executing the script, similar to an incoming request. You should then see the original traceback.
Hth,
Aaron
Dreamhost and Django (fcgi) caching Post on Oct 28, 2009
Every once in a while (while dabbling with Django on Dreamhost) I run into the problem that Dreamhost appears to cache my site. I've even canned the db or deleted the settings file to try and provoke an error. But the site ticks on (for a bit anyway), and I want to see results now! damnit...I am after all hacking on the live site instead of my staging server! Talk about living on the edge!
The cure
Thwart the so-called caching with a mighty blow to the process itself, it will be restarted at the next request:
killall -USR1 dispatch.fcgi
Thanks to the dreamhosters forum for the tip.
Af
Files where Ubuntu menus are stored Post on Oct 21, 2009
Note to self - Ubuntu menus are stored here:
/usr/share/applications
I keep forgetting this one...
af
svn command line commit wierdness and Windows XP Post on Sep 29, 2009
I thought I was entering into Windows twilight zone, svn wouldn't let me commit on my XP console. Turns out it doesn't like single quotes, so this wouldn't work:
svn ci -m 'This is my message'
I had to do this:
svn ci -m "Windows XP sucks bobo bigtime"
Hope that helps someone keep from pulling their hair out...
Aaron
XP and dv9500 Post on Jul 24, 2009
I ran into a problem with my new(ish) laptop, I've been running Ubuntu 9 on it since I got it, and previous owner put the Windows 7 RC (no link intended) against my wishes. So the RC finally expired, and I'm left without Windows on my laptop. Normally this wouldn't be a big deal, but I have a Mackie Onxy 400f and Canon XL2 which can both connect and record on the laptop via the IEEE1394 (firewire) interface.
The problem
So I own a copy of XP Professional (from when it first came out), and I try to install it. Problem is, the drives are SATA and the XP installed doesn't recognize there's hard drives in the machine. I looked at a couple guides and opted not to build my own XP, and instead downloaded Vista Premium, for which there is a key on the bottom of the laptop. I've been resisting this to the bitter end, even trying to get a copy of OSx86 running instead (to no avail).
So I finally install Vista (actually my brother Dan did), update all the garbage, install the software, do all the typical 'fresh OS' stuff, and run my software to interface with the XL2, and find out there's a bloody bug in Vista that the firewire doesn't work properly or something stupid. The computer (rather, Vista) won't recognize my damn camera. Not much of a remote monitor for shooting then, is it. We've really made technological advancements when we sell people a feature like 'Firewire' on a laptop, and the operating system can't even utilize it. Great work, Microsoft.
The fix
So I downloaded XP Dark which promised to have SATA drivers for my laptop. I'm not into pirating Microsoft stuff, but if the bastards can't give me a working Vista, and won't let me install my XP Pro (it was $1000 US new), then they can kiss my arse.
XP Dark installed like a dream (it gave me an install option for SATA), it was way faster than a standard XP install, and relatively shiny. The last problem I ran into was a whole whack of missing drivers. Like, missing drivers for just about everything. No ethernet, wireless or otherwise. The only thing that did work was the silly webcam!
Anyway, I rummaged around a bit, and tried finding drivers for some stuff, but was having limited success. I found this page with link to a Super Awesome XP Driver Pack specifically for me laptoppy! All the drivers installed perfectly (thanks again, Dan) and we're now on our way to on-location shooting heaven!
Cheers,
Aaron
XBMC video problem Post on Jul 13, 2009
I just discovered XBMC media center while setting up a computer for a friend of mine, and it's pretty awesome. I couldn't figure out how to get it to load some episodes into the video Library, XBMC has missing or hiding the videos, and it turns out, the episodes need to have the episode number formatted like so: 1x01 in order for it to be recognized. I don't know if it matters where that is in the name, but 01-01 didn't work.
af
Fluxbox keys stopped working Post on Jun 23, 2009
I was mucking around trying to hide some files in vim's netrw, and all of a sudden fluxbox did some wierd blinky thing, and I had to reset my machine. None of the menus would work, I couldn't switch workspaces, nothing.
Resetting brought me back into fluxbox, but my theme had been reset to the default, which was wierd. So I set it back to the one I downloaded and started to go back to work...but...now none of my hotkeys were working. I jumped on #fluxbox and didn't get anything useful so I did a little digging around and found this post on linuxquestions.org. Turns out the session.keyFile setting in ~/.fluxbox/init was set back to the default which is /etc/X11/fluxbox/keys on my machine. So I put it back to my user file:
" ~/.fluxbox/init session.keyFile: ~/.fluxbox/keys
After a quick restart, everything is back to normal again...oh, except I have to set up more workspaces, I lost 3 of them. Hmmm, wish I could figure out what the hiccup was.
Maybe next time.
Af out.
'Find in files' in vim Post on Jun 14, 2009
I have been enjoying vim quite a bit recently, it is really starting to speed up my workflow. The learning curve is constant, however. The latest thing I have needed to know (and use quite a bit) is a 'find in files' feature. Vim has this built in with a plugin called 'vimgrep'. The documentation was pretty straight forward (:h vimgrep) but it wasn't immediately obvious how to do recursive searching. The solution was what vim calls 'starstar-wildcard' (essentially **)
This simple example produces a recursive search:
:vimgrep /myPattern/ **
The above example will search through everything though, including binary files (like pngs and such), so a little more instruction is needed.
:vimgrep /myPattern/ **/*.html # this is also equivalent :vim /myPattern/ **/*.html
Vim then gives you the first of the matches, you can cycle between them with :cnext/:cn and :cp/:cprevious.
If you have a lot of files to search through, :grep is faster.
:grep -Ir /myPattern/ *
Not so hard after all, af
Dreamhost and SMTP server Post on Jun 10, 2009
I was monkeying around a little bit for a friend earlier, trying to set them up on one of our outgoing mail servers, since our ISP server has been a little funky lately. I just wanted to note that Dreamhost SMTP server works on port 587 and not 25. When you try and send mail, it will not authenticate on port 25.
top, you liar! Post on Feb 27, 2009
aka: "Your server memory usage probably isn't what you think it is"
I learned a really valuable lesson in understanding the server today: "free memory" to the system means "wasted memory" (I think I got it from here). I'll elaborate...
The long of it
The problem was, we just upgraded our server from 2GB RAM to 4GB, and moved a whole host of sites off mod_python to mod_wsgi. One of the (supposed) benefits of wsgi is reduction in memory usage, in that a complete python interpreter is not supposed to be loaded with wsgi, as is the case with mod_python. What we had running before was a system with ~20 django sites, usually 6 child apache processes at roughly 200Mb each. I was getting a little nervous about memory usage, we weren't anywhere near capacity on our machine, but were using a tonne (Canadian that is) of memory.
So we upped to 4GB
...And recently switched our sites to WSGI. I should be happy, but a quick 'top' shows me memory usage is at like 96% (or so)!!! How can that be? I run 'ps aux', do some quick math, and yes, we should be using less memory, what's the deal?
Well, as it turns out, Linux (and therefore derivatives of) like to use free (aka wasted) memory to cache disk transactions. So to gain a (more) accurate representation of what is actually being used, try a command like 'free' instead.
free -m
aaron@videostation:~$ free -m
total used free shared buffers cached
Mem: 2023 1963 60 0 22 1094
-/+ buffers/cache: 846 1176
Swap: 5930 207 5722
The important bit is the line '-/+ buffers/cache', where the real figures are, used is not 1963, its 846 (less the cached stuff), and free is really 1176, not 60.
Still enough to give me a good palpatation early in the day. Oh well, off to the next hard learned lesson.
Aaron
Worth writing home about Post on Feb 05, 2009
Today, for me, will be a monumental day in history. Today is the day I checked the browser stats on W3C and saw that all the combined IE users are less than the FireFox users as of January, 2009.
IEs (combined): 44.8%
FireFox: 45.5%
Now I know the numbers are not exact, but they are close enough for W3C to post on their site, and certainly close enough to bring a tear to my eye. -sniff-
Now if we can just bring those Linux numbers up...
Delete svn directories Post on Jan 09, 2009
Every once in a while we find the need to hack out a bunch of .svn directories, a good example is borrowing a javascript plugin (with 500 nested folders) from a project already committed to a subversion repository. It can be (and really, is) quite painful to go through and remove all those little .svn folders so you can potentially commit the newly-coveted javascript morsel into your new project (if this sounds hackish, it probably is, there must be a better way).
My new favorite hack
rm -rf `find . -type d -name .svn`
Found it here.
Cheers
Global svn ignore Post on Jan 07, 2009
I have had the recent annoyance of having svn status reveal every .pyc file in my projects. I usually use eclipse for developing in python/django, but on my old (fluxbox-revived) laptop, eclipse is too much of a hog to run so I settle on gedit (awesome) and the command-line svn, which works just about as great.
The only thing I couldn't figure out is how to get svn to ignore my *.pyc files, and I tried propset and a bunch of other stuff.
Finally
I changed a line in my ~/.subversion/config file, I think it was global-ignore and added *.pyc to the end.
My next svn status? Pretty as can be, and free of pyc files.
Dessert Post on Jan 04, 2009
And tonight for dessert I had chocolate-covered bacon.
That's all I have to say about that...
MXMLC FileReference.load() compiler error Post on Dec 23, 2008
On my linux box I am running the Flex SDK 3.2, and tried to use the funky new load() method for FileReference (which pulls the byteArray data of the loaded file = sweet). But my Flex wouldn't compile it, complaining of an error:
Error: Call to a possibly undefined method load through a reference with static type flash.net:FileReference.
The fix?
Edit my /flex/frameworks/flex-config.xml and change the target-player version from 9.0.124 to 10.0.12.36 (even though linux is currently 10.0.15.3)
A hack a day keeps the blues away...
Aaron
Ubuntu and Actionscript Post on Dec 20, 2008
I just downloaded the Flex 3 SDK for Linux and wanted to pick up an old project I've been putting off for a while. I found some syntax-highlighting (language) files for gedit that cover mxml and actionscript but I immediately ran into a problem with opening actionscript files in my system. In the gedit file view, .as files don't even show up at all. In nautilus they do, but when I try to open one, I get an error:
The filename "Logger.as" indicates that this file is of type "Applix Spreadsheets spreadsheet". The contents of the file indicate that the file is of type "plain text document". If you open this file, the file might present a security risk to your system. Do not open the file unless you created the file yourself, or received the file from a trusted source. To open the file, rename the file to the correct extension for "plain text document", then open the file normally. Alternatively, use the Open With menu to choose a specific application for the file.
Applix Spreadsheet? Never heard of it. Turns out the solution wasn't too hard afterall, create a mime-type association in Ubuntu, but it did take some creating search terms on Google to finally get a result.
Another day, another Linux hack.
Cheers, Aaron
[edit] There are a couple more things you need to do to make this work. First make sure the mime-types for actionscript in both files are the same, currently one is 'application/x-actionscript' and the other is 'text/x-actionscript'. Then you need to run 'sudo update-mime-database /usr/share/mime' (assuming that is where you installed the mime xml files).
I'm not sure if you need to restart ubuntu for this to work, I did anyway. [/edit]
Ubuntu VNC glory Post on Dec 09, 2008
I needed to have a friend pull my vnc client the other day, and in UltraVNC in Windows, you can just set the client on 'listen mode'. I didn't know how to do this in Linux, but the answer was easy:
vncviewer -listen 5500
And the server
The server was just as easy to set up:
x11vnc -forever -usepw -httpdir /usr/share/vnc-java/ -httpport 5800 -listen 192.168.1.103
Make sure and -usepw or you'll open your machine up to a world of trouble :)
Aaron
Fluxbuntu and Intel Pro Wireless 2200bg Post on Dec 08, 2008
I had to blog this one. It's the hack of the day. I couldn't get a minipci wireless card (Intel Pro/Wireless 2200BG) card to work on my old Toshiba Satellite A30. The ipw2200 driver is installed in Fluxbuntu by default (which is nice) but 'iwconif' reported my 'radio off' on eth1.
I had to tape a couple pins to get it to work, and the sliver of tape was tiny, harder to pull off than I thought, but I'll be damned if it didn't work.
Internet: 1, Pro/Wireless 2200BG:0 :)
Aaron
FlexiCAM and Skype on Intrepid Post on Dec 01, 2008
I was having an issue with the new webcam I bought today on Intrepid and Skype. I first thought it was an issue with the video for linux driver, but the cam worked fine in cheese, but all I got was this funky green screen in Skype when testing my camera. After quite a bit of searching, I finally found an answer that worked, and it was really simple. You can grab it on Ubuntu Forms.
Cheers,
Aaron
[edit]I have to say, I'm not really impressed with the picture quality, I would go way beyond soft and say the picture is either blurry or completely out of focus. Here's a snap:
I read a couple reviews that said this camera has a sharp picture, I wonder if I got a bad one...[/edit]
Ubuntu Intrepid breaks Virtualbox Post on Nov 27, 2008
I have had a couple go-arounds with this one now, I try to boot my Virtualbox and it says something like
VirtualBox kernel driver not installed. The vboxdrv kernel module was either not loaded or /dev/vboxdrv was not created for some reason. Re-setup the kernel module by executing '/etc/init.d/vboxdrv setup' as root.
VBox status code: -1908 (VERR_VM_DRIVER_NOT_INSTALLED).
Result Code:
0x80004005
Component:
Console
Interface:
IConsole {d5a1cbda-f5d7-4824-9afe-d640c94c7dcf}
So I run
sudo /etc/init.d/vboxdrv setup
and I get
* Stopping VirtualBox kernel module
* done.
* Recompiling VirtualBox kernel module
/etc/init.d/vboxdrv: 311: cannot create /var/log/vbox-install.log: Permission denied
* Look at /var/log/vbox-install.log to find out what went wrong
And the log gives me some funky compile output and an 'Error 2' at the end.
... make -f scripts/Makefile.build obj=/tmp/vbox.1 gcc -Wp,-MD,/tmp/vbox.1/linux/.SUPDrv-linux.o.d -nostdinc -isystem /usr/lib/gcc/i486-linux-gnu/4.3.2/include -D__KERNEL__ -Iinclude -I/usr/src/linux-headers-2.6.27-7-generic/arch/x86/include -include include/linux/autoconf.h -Iubuntu/include -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -Werror-implicit-function-declaration -O2 -m32 -msoft-float -mregparm=3 -freg-struct-return -mpreferred-stack-boundary=2 -march=i586 -mtune=generic -ffreestanding -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Iinclude/asm-x86/mach-default -fno-stack-protector -fno-omit-frame-pointer -fno-optimize-sibling-calls -pg -Wdeclaration-after-statement -Wno-pointer-sign -I/lib/modules/2.6.27-7-generic/build/include -I/tmp/vbox.1/ -I/tmp/vbox.1/include -I/tmp/vbox.1/r0drv/linux -D__KERNEL__ -DMODULE -DRT_OS_LINUX -DIN_RING0 -DIN_RT_R0 -DIN_SUP_R0 -DVBOX -DRT_WITH_VBOX -DCONFIG_VBOXDRV_AS_MISC -DRT_ARCH_X86 -DUSE_NEW_OS_INTERFACE_FOR_MM -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(SUPDrv_linux)" -D"KBUILD_MODNAME=KBUILD_STR(vboxdrv)" -c -o /tmp/vbox.1/linux/.tmp_SUPDrv-linux.o /tmp/vbox.1/linux/SUPDrv-linux.c In file included from /tmp/vbox.1/linux/SUPDrv-linux.c:35: /tmp/vbox.1/SUPDRV.h:99:30: error: asm/semaphore.h: No such file or directory /tmp/vbox.1/linux/SUPDrv-linux.c: In function 'supdrvOSGipResume': /tmp/vbox.1/linux/SUPDrv-linux.c:1331: error: too many arguments to function 'smp_call_function' make[2]: *** [/tmp/vbox.1/linux/SUPDrv-linux.o] Error 1 make[1]: *** [_module_/tmp/vbox.1] Error 2 make[1]: Leaving directory '/usr/src/linux-headers-2.6.27-7-generic' make: *** [vboxdrv] Error 2
Cheers, Af
Lightroom -like histogram in Python Post on Nov 19, 2008
I just added a dynamically-generated histogram to the image items on my site. It's not really usefull information in the context of viewing a photograph, it's more functional when editing, but being the uber-geek that I am, I thought it would still be interesting information to have on my site, right along with the exif data (aperature, focal length, etc).
But not just any histo
I didn't just want a black and white representation of all the image histogram, I wanted something like the pretty histogram in Adobe Photoshop Lightroom:
All in all the final version took me about 1.5 hours to write in Python using PIL. The semi-tricky part was getting the overlapping colors. It turned out to be about 70 lines of code, and could probably be done much better. On my local Ubuntu install, a typical image histogram is generated in about 5-10 ms, not bad for a skinny white guy :)
Check out an image or two to see the pretty histogram in action :) Next step, drop shadows on the layers...
Cheers, Aaron
Short Film "Double Time" Post on Nov 19, 2008
We just posted our submission for the Digital Video Challenge #14 called "Double Time". I really want to thank everyone involved from Staged Right Productions for making the project fun, and seeing it through to completion. Just having put something together in such a short period of time that still makes me laugh feels like an accomplishment.
You can watch the film here:
YouTube version
Original (higher quality) version
Feel free to post some feedback below.
Cheers, Aaron
Mount an Ubuntu hard drive in XP Post on Nov 15, 2008
I have been running Ubuntu Linux for a number of months now, but every once in a while I need to jump into XP to do something (I'm running a dual-boot right now). And as soon as I'd get into Windows, I'd realize I needed a file off my Linux disk. Now XP and Ubuntu run totally different file systems, I run NTFS on Windows, and my Ubuntu install is using Ext2 (I believe). But, no problem, just run this handy little utility and your drive will show right up :)
Another crisis nearly diverted.
Aaron out.
PCI device list in Ubuntu Post on Nov 12, 2008
I just ran across this today, trying to get Ibex running on my wife's PC. I needed to know the hardware on this wireless card.
lspci
spit out something like this:
00:00.0 Host bridge: Intel Corporation 82945G/GZ/P/PL Memory Controller Hub (rev 81) 00:01.0 PCI bridge: Intel Corporation 82945G/GZ/P/PL PCI Express Root Port (rev 81) 00:1b.0 Audio device: Intel Corporation 82801G (ICH7 Family) High Definition Audio Controller (rev 01) 00:1c.0 PCI bridge: Intel Corporation 82801G (ICH7 Family) PCI Express Port 1 (rev 01) 00:1c.4 PCI bridge: Intel Corporation 82801GR/GH/GHM (ICH7 Family) PCI Express Port 5 (rev 01) 00:1c.5 PCI bridge: Intel Corporation 82801GR/GH/GHM (ICH7 Family) PCI Express Port 6 (rev 01) 00:1d.0 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #1 (rev 01) 00:1d.1 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #2 (rev 01) 00:1d.2 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #3 (rev 01) 00:1d.3 USB Controller: Intel Corporation 82801G (ICH7 Family) USB UHCI Controller #4 (rev 01) 00:1d.7 USB Controller: Intel Corporation 82801G (ICH7 Family) USB2 EHCI Controller (rev 01) 00:1e.0 PCI bridge: Intel Corporation 82801 PCI Bridge (rev e1) 00:1f.0 ISA bridge: Intel Corporation 82801GB/GR (ICH7 Family) LPC Interface Bridge (rev 01) 00:1f.1 IDE interface: Intel Corporation 82801G (ICH7 Family) IDE Controller (rev 01) 00:1f.2 IDE interface: Intel Corporation 82801GB/GR/GH (ICH7 Family) SATA IDE Controller (rev 01) 00:1f.3 SMBus: Intel Corporation 82801G (ICH7 Family) SMBus Controller (rev 01) 01:01.0 Ethernet controller: Marvell Technology Group Ltd. Marvell W8300 802.11 Adapter (rev 07) 01:03.0 FireWire (IEEE 1394): Texas Instruments TSB43AB22/A IEEE-1394a-2000 Controller (PHY/Link) 01:04.0 Mass storage controller: Integrated Technology Express, Inc. ITE 8211F Single Channel UDMA 133 (rev 11) 02:00.0 Mass storage controller: Silicon Image, Inc. SiI 3132 Serial ATA Raid II Controller (rev 01) 03:00.0 Ethernet controller: Marvell Technology Group Ltd. 88E8053 PCI-E Gigabit Ethernet Controller (rev 15) 05:00.0 VGA compatible controller: nVidia Corporation G70 [GeForce 7800 GTX] (rev a1)
Not so scary after all :)
Ubuntu and PyQt Post on Oct 14, 2008
I just went through the nightmare of trying to install PyQt and all its dependancies. I had originally searched for an ubuntu package (coz we loves packages, doesn't we precious?) I couldn't seem to find one.
Turns out (after failing 'configure's and 'make's and missing dependancies), there is a package (a couple, actually).
To install PyQt on Ubuntu:
sudo apt-get install libqt4-core libqt4-dev libqt4-gui qt4-dev-tools python-qt4 pyqt4-dev-tools
I'm not sure if all the packages before the last one are necessary, but I didn't think it would hurt to have them.
Thanks again, Ubuntu Forums.
af
Installing Pygments on Webfaction Post on Oct 10, 2008
I just wanted to share the command, it took a little tinkering to get it right:
easy_install --always-unzip --install-dir=$HOME/lib/python --script-dir=$HOME/bin Pygments
Cheers, Aaron
Comment email notification in Django 1.0 on Webfaction Post on Oct 10, 2008
It's always nice to know when someone posts a comment on your blog, and if you're using something like Wordpress then email notification is already built in. Well, you guessed it, I'm not using Wordpress :)
The code
I got the original code to hook into signals sent from the comment system from here, but it's not compatible with 1.0. Thankfully, the fix is easy:
from django.contrib.comments.models import Comment from django.core.mail import send_mail from django.db.models.signals import post_save def comment_notification(sender, instance, **kwargs): subject = 'New Comment on %s' % instance.content_object.title msg = 'Comment text:\n\n%s' % instance.comment send_mail(subject, msg, 'from@mysite.ca', ['mail-to-me@mysite.com']) # ideally these go in the settings post_save.connect(comment_notification, sender=Comment)
There were minimal modifications to make the code work from the original version, now the next trick is to get Webfaction to send my email.
Webfaction and send_mail
Wefaction won't just let you send mail right off the bat, you need to set up a mailbox and email address on your Webfaction account, and then change a couple settings in your project's settings.py file. I had found a forum post with the details but they implied I should be using 'mailx.webfaction.com' (x being my mail server number), but it wouldn't work. I recalled after that my outgoing mail server is 'smtp.webfaction.com'.
EMAIL_HOST='smtp.webfaction.com' EMAIL_HOST_USER='mymailbox' # < this should be the mailbox EMAIL_HOST_PASSWORD='mymailboxpass' # < a valid password (obviously) EMAIL_PORT='25' DEFAULT_FROM_EMAIL = "my-email@my-webfaction-account.com" # < the next 2 are the email address tied you your mailbox SERVER_EMAIL = "my-email@my-webfaction-account.com"
And bada-bing! The mail comes through snappy fast too. Thank goodness for Django, black licorice, and Webfaction :)
Cheers, Aaron
Hardy and my LJ1600 Post on Oct 09, 2008
I'm impressed once again with Ubuntu 8.04 (LTS). I remember having to tweak gutsy to get color working on my laserjet, but I just plugged it into this box, and it worked without a glitch. Well, one glitch, I had to change the 'color' setting from 'monochrome' to 'color', but I can't complain, it's not find/editing obscure configuration files...
Cheers to Ubuntu :) af
Testing, again Post on Oct 08, 2008
I removed the crappy Feed reader plugin from facebook applications and just used the 'import' option on my profile page. Just testing it out again...
I wonder what happens when I add a link...
Testing feed reader from Facebook Post on Oct 08, 2008
Okay, I give in, Facebook is a little handy sometimes. But I still loathe the thought of having to read through the cruft of 300 friends' updates daily.
Let's see if FaceBook updates my profile with this new item :)
George Green Videos Post on Oct 07, 2008
I found George Green when I was looking up over-unity devices (again) after watching the Zeitgeist movies and resolving to find a good solution for power off the grid. If you haven't seen these, then I recommend them right after Zeitgeist. George went into a couple topics that put me on edge, but talked about a few things I like to think I know a bit about, and I found just about everything he had to say easy to chew on.
Links
Videos
A quote by Jacque Fresco Post on Oct 06, 2008
We talk about civilization as though it's a static state. There are no civilized people yet, it's a process that's constantly going on... As long as you have war, police, prisons, crime, you are in the early stages of civilization.
Zeitgeist Post on Oct 06, 2008
I just finished watching 2 shows by the indie producer Peter Joseph, The Zeitgeist Movie, and Zeitgeist: Addendum. If you haven't seen these, I completely recommend them. Take the time and sit through it, there's about 4 hours involved...
The Zeitgeist Movie
Zeitgeist: Addendum
New aaronfay.ca site now live Post on Sep 24, 2008
I had originally published a bit of content to this site at the test domain, and set the configuration of my domain dns yesterday. I noticed (while in Sundre having a coffee) on some other ISPs that the dns resolution was complete, but at home I was still seeing my old site. Now I just have to get some of the final tickets fixed up, and find a way to migrate my old Wordpress content gracefully...
Cheers to aaronfay.ca 2.0
Facebook haters Post on Sep 24, 2008
I've never really been a fan of Facebook. At first I didn't really get it, what it was for, or how to use it. Then after a couple tries, things started to kick in, and the utility made sense to me. But right off the bat I was turned off (as I'm sure others are) by constant "pokes" and "vampire bites" and other forms of interaction that would entertain any 7-year-old.
But the real reason
But that wasn't what really turned me off. I was pretty sure, having used similar social sites in the past, that Facebook would have a privacy policy and terms of service that is consistent with such sites. Every photo you upload, every post you write, everything you 'twitter' and comment and wall-post on the site, you have now granted Facebook the right to distribute, copy, and otherwise manipulate your content:
"for any purpose, commercial, advertising, or otherwise, on or in connection with the Site or the promotion thereof, to prepare derivative works of, or incorporate into other works, such User Content, and to grant and authorize sublicenses of the foregoing." - Source
You agreed to it when you signed on to the site
The only reprieve is that the license mentioned above ends if you remove your content, but that doesn't seem to be happening any time soon. I think FB is probably more popular than ever, having just launched The New Facebook.
Am I a FB hater?
Probably not. I still have a pang in my gut when I think about uploading my life onto their servers. Is it different than uploading my life onto this blog? Probably. I doubt any corporation is going to peruse my blog in attempts to benefit from my content (although I'm sure someone is trying anyway).
Should everyone delete their FB accounts?
No, I don't think so. Just be a little more mindful about what you put on your profile. I'm not sure whether I should laugh or feel sorry for my little sister when she twitters about her love life on on her FB status and my father reads it on the computer.
(and nobody does this next one):
READ THE TERMS OF SERVICE. How do you know what contract you're agreeing to without reading it? When you buy a house or a business, do you just sign the papers? Probably.
Here's the Facebook Haters site if you're interested.
And a neat video:
Trac XMLRPC integration Post on Sep 23, 2008
I just implemented an XMLRPC call to the Trac system I'm using for the codebase for this site. I was simple enough, just a couple lines of code, and I had to install the XMLRPC plugin for Trac.
The first post (again) Post on Sep 23, 2008
Okay, I'm going to test the first post this time. My 'miraculous new system' that I'm using for my weblog failed to post my first blog post. So let's test it first.
Okay, so it worked
I feel better now. I won't ramble on about the new site, let's just say this site is the first manifestation of the 'top-secret' project I've been working on, and is just a little test to try out the versatility of it.
More to come later, af