Learning Python
Amazed to report that, having never created a Python program longer than “hello world” and within an hour of starting, I was able to research and implement a Python script that imports arbitrary CSV files into a sqlite database for more sane analysis. Go Python!
Writing
I’ve been starting to think I should be writing a bit more, and things like this (http://www.copyblogger.com/bad-writing-habits/) keep popping up for me and sparking this feeling even more. I think I’ll use it to help structure my workweek better as well.
I know you’ve been wondering for months. (I certainly have.)
PHP’s boolean literals (true and false) are completely case-insensitive. Cool!
easy peasy find big files on linux
du -xakm /|sort -rn|head -500 > bigfiles.txt
This saves (quickly!) a list of the 500 biggest files on your Linux / Unix / Mac OSX system, along with their size in megabytes, and organizes them with the largest at the top. Cool!
It’s saving me this evening - thanks go out to a commenter named georges at http://www.cyberciti.biz/faq/find-large-files-linux/
Drinking Tropicana Orange Juice
And the box says “Contains Orange Juice from the U.S. and Brazil.”
WHAT?
Why is it that food safety rules are so focused on points of failure rather than systemic problems?
What if we mashed the Brazillian oranges _separately_ from the U.S. oranges? Perhaps the inevitable lapses in food safety would be identified and quashed faster than the absurdly broad contaminations we have now that result in the wholesale destruction of tons and tons of food.
Just a thought. One glass of orange juice simultaneously from the U.S. and Brazil, harumph.
Apache RewriteRule weirdness
Phenomenally useful post by a guy named Max Dunn in his blog “Eschew Obfuscation”.
The gist of the usefulness for me:
- Let’s say people are accessing your site on the url http://site.com/coolpage and you need to rewrite that to http://site.com/index.php/coolpage
- When your RewriteRule directive is in a conf file, it will be matching against “/coolpage”
- When the directive is in a .htaccess file located in the document root for site.com, it will be matching against “coolpage”
I thought it was pretty weird behavior until I realized: the .htaccess rules will only be applied to requests for things within the site.com document root, (making the leading slash irrelevant information) whereas the the conf files are potentially server-wide.
Here’s what you’d probably use in each case:
Apache conf file:
RewriteRule ^/(.*)$ index.php?/$1 [L]
.htacess file:
RewriteRule ^(.*)$ index.php?/$1 [L]
Google Sites Screencasts
I recently gave a workshop on how to create a simple personal branding website using the Google Sites service and decided that I could provide a recap of some of the key steps here for anyone that needs them. I’ll be adding more as time goes by, but I’m getting started with a simple one that shows how to create a new site:
- Creating a new site in Google Sites - 5 minute narrated tutorial showing how to create a new site
I know this is really basic but don’t worry, more are coming! If you bookmark this page dedicated to the tutorials and check back regularly, the new posts will appear right at the top.
Really cool remote file copying trick
So I was trying to copy a really huge (about 4 gigs) file from my laptop up to my web server, using a simple and standard command:
scp local_file_name username@remoteserver.com:remote_file_name
When I got about 10% through, I began to worry what would happen if the transfer failed somewhere way down the line. (It claimed it would take 4 and a half hours.) So I googled “scp resume” to see if there was anything to be done. Sure enough, I found several blog posts suggesting this command:
rsync --partial --progress --rsh=ssh local_file_name username@remosthost.com:remote_file_name
So, worried to potentially waste a bunch of time if the scp failed at 95% or something, I just canceled it and expected to have to re-do the 10% that was already done.
The coolest part? The canceled scp left the portion of the file already transfered, and the new rsync command was happy to resume that transfer.
So it’s not only a resume-friendly alternative to scp, it’s actually a rescue method for failed scp transfers. Cool!
CodeIgniter View Hack
I ran into what seems like it might a bug in CodeIgniter’s view loading. (Specifically in the extraction of a data array into the local scope for that view.) I had pulled out a piece of HTML that was repeated a lot into a separate view file in order to call it more easily in the main view file. The data array I was passing in had certain keys that were sometimes present, sometimes not present. I discovered that if I called the view once when the keys were present, and then a second time when the keys were not present, rather than seeing no value for the keys (the expected result), the view saw the values from the previous call. My eventual soultion was to replace my view loading line $this->load->view('view_name', $data); with $this->load->view('view_name',Array('d'=>$data)); Loading the view in this second method meant CodeIgniter was only extracting one symbol ($d) into the global sope of the view I was loading. Since this symbol got replaced on every call, my problem went away. The kinda-lame part, however, is that the view now needs to reference pieces of data as $d['piece_of_data'] instead of simply $piece_of_data

