Django image upload failure problem and fix
Software
Thursday, 26 January 2012 23:42

On my Mac (Lion) I was getting an error when uploading images: "Upload a valid image. The file you uploaded was either not an image or a corrupted image."

I guess django uses PIL for verification of a valid image. The problem as it turns out was that PIL was installed without JPEG support and I was trying to upload a JPEG image.

The fix is very simple. You have to install libjpeg and then you have to reinstall PIL.

brew install jpeg
pip install pil --upgrade
Add a comment
 
Mockingbird
Startup
Monday, 23 January 2012 09:22
Making wireframes is a great way to capture and test an idea. For those of us that aren't gifted at photoshop, and even perhaps for those of us who are, it is nice to have a tool specifically designed for this. There are a few such online tools that have been developing nicely. One that I really like is mockingbird. The general idea is this. The tool gives you tons of common widgets (text, input boxes, placeholder image, etc) to quickly make a wireframe of your product. You create many of these and you can make them link to each other easily, so when you click on some button in one wireframe, it takes you to another. Add a comment
 
AJAX Forms Only
Websites
Wednesday, 18 January 2012 14:23
Forms. As web developers, we work with them a lot. And you have to deal with validating them client-side and server-side. You can write custom javascript to do the client-side validation and then separate code for server-side validation. But what if the server finds and error that was not found client side, such as trying to register a user, but that username is already taken? So now you have to be able to not only validate on both sides, but display errors from both sources. It's simple really, but I've finally decided that it's just easier to submit ALL forms via AJAX. The validation can all be done server-side because with an AJAX call it's pretty darn fast. In the end it's really much more simple. Plus, on most sites, you have some forms that submit "normally" and some that submit via ajax, so you have two general philosophies to support. Let's make life more simple. Just do it all via AJAX. Add a comment
 
Two Helpful Git Aliases
Software
Tuesday, 22 November 2011 14:10

Add this to your ~/.gitconfig to add these two super useful aliases. A guy at work shared these with me. The provide a nice way to view your history on the command line in a much more pretty format. Mainly they add some color and add visualization of branching and merging.

[alias]
        hist = log --pretty=format:'%Cred%h%Creset %C(bold blue)<%an>%Creset%C(yellow)%d%Creset %Cgreen(%cr)%Creset%n%w(80,8,8)%s' --graph
        histfull = log --pretty=format:'%Cred%h%Creset %C(bold blue)<%an>%Creset%C(yellow)%d%Creset %Cgreen(%cr)%Creset%n%w(80,8,8)%s%n' --graph --name-status
Add a comment
 
Oracle XE on Ubuntu 11.04 32 bit and other platforms
Software
Sunday, 13 November 2011 14:19

At my work we are now using Oracle 11g database. The production version of this thing is quite hefty so I wanted something lighter while developing on my laptop. Oracle provides a lightweight edition called Oracle XE. Unfortunately I had to install 10g (see compatibility notes below). Using 10g instead when the rest of the company is on 11g has only caused me one pain point so far and I was able to work around it. I'll explain more later. So, without further ado, here's what I learned when trying to get this sucker installed.

Compatability notes

I mentioned above that I had to use 10g since I'm running 32 bit. Here's some more specific notes about what version you have to use for various platforms.

  • If you have 64 bit Ubuntu/Debian, then you have to follow the alien instructions below.
  • If you have 64 bit RedHat, Fedora or CenOS, just skip the alien stuff and install the RPM directly.
  • If you have a 32 bit linux OS (like me), install Oracle 10g XE instead. There are packages for lots of distributions in that version so nothing special is required.

Prerequisites

You need a JDK. For Ubuntu, I just installed openjdk-6.

 
sudo apt-get install openjdk-6-jdk
You also need ant installed
sudo apt-get install ant
 

Converting 11g 64 bit RPM into a .deb using Alien

Download the RPM from Oracle's website. The instructions below assume you have a copy of it. Note: I got a few weird errors while installing this, but it seems that they were benign.

 
sudo apt-get install alien libaio1 chkconfig
sudo alien -d --scripts oracle-xe-11.2.0-0.5.x86_64.rpm
 

Install the package

If you are installing an RPM, I haven't actually done that. I assume it would be easy though. If you're installing a deb (either converted by alien or a deb directly from Oracle in the case of 10g), then here's some more details.

 
sudo dpkg -i oracle-xe-11.2.0-0.5.x86_64.rpm
sudo /etc/init.d/oracle-xe configure
#if you don’t want oracle to start automatically on boot, run this:
sudo /sbin/chkconfig oracle-xe off
 

Here are the answers I gave to questions during installation.

 
Port for Oracle Application Express: 8085 (so it doesn’t conflict with Tomcat, JBoss, etc.)
Port for DB Listener: 1521 (default)
Password for SYS and SYSTEM: Oracle11 (because this is standard)
 

You should now add yourself to the dba group. When I was doing this I noticed that oracle wasn’t in this group either. Added that user too, but probably unnecessary. This will allow you to start/stop your XE database among other things.

Now you need to setup some env variables for your user and for your oracle user:

 
export ORACLE_SID=XE
alias vi='vim'
export ORACLE_BASE=/u01/app/oracle #(or just $HOME for oracle user)
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/xe
export ORACLE_TERM=xterm
export _EDITOR=vim
export NLS_LANG=american_america.utf8
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NLS33=$ORACLE_HOME/ocommon/nls/admin/data
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
 

I found that the paths are a bit different if you’re installing 10g. Here’s what worked for me:

 
export ORACLE_SID=XE
alias vi='vim'
export ORACLE_BASE=/usr/lib/oracle/xe/app/oracle
export ORACLE_HOME=$ORACLE_BASE/product/10.2.0/server
export ORACLE_TERM=xterm
export _EDITOR=vim
export NLS_LANG=american_america.utf8
export TNS_ADMIN=$ORACLE_HOME/network/admin
export ORA_NLS33=$ORACLE_HOME/nls/data
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=$ORACLE_HOME/bin:$PATH
 

Troubleshooting

In $TNS_ADMIN/tnsnames.ora, your computer’s hostname is used in the default XE config. But for me, my hostname was not resolvable. Either add it to /etc/hosts or get a DNS entry for your host...or just change this to localhost, which is what I did.

Eventually you’re going to start getting an error like this due to the fact that XE limits the number of concurrent connections too much:

org.jboss.resource.JBossResourceException: Could not create connection; - nested throwable: (java.sql.SQLException: Listener refused the connection with the following error:
ORA-12519, TNS:no appropriate service handler found
The Connection descriptor used by the client was:
localhost:1521:XE
)

So let’s up this limit with the following commands:

 
sqlplus system/Oracle10
alter system set processes=150 scope=spfile;
quit;
sudo /etc/init.d/oracle-xe restart
 
Add a comment
 
Gnome Terminal Tab Titles
Tech & Gadgets
Friday, 04 November 2011 09:34

I love screen. One of the things I love about it is that I can name the windows. When I get too many tabs open in Gnome Terminal it gets really hard to keep track of things. There are definitely times when I'd prefer to just use Gnome Terminal without screen if it weren't for that issue. Well it turns out that you can easily name the tabs in Gnome Terminal by right clicking them and choosing "Set Title...". I'm not sure if this is new or if I'm just a dork and never noticed it, but this is great! Just one of those little details that will make a big difference for me.

Set Tab Titles in Gnome Terminal

Add a comment
 
Programming Puzzle Websites
Miscellaneous
Thursday, 14 July 2011 22:21

I thought a few of these looked pretty interesting...

10 Puzzle Websites to Sharpen Your Programming Skills

Add a comment
 
Word Press mysql & mysqldump helper scripts
Websites
Thursday, 16 June 2011 08:50

Here are two simple scripts that will allow you to use mysql and mysqldump without having to constantly open up wp-config.php to copy the DB connection information.

wp-mysql

 
#!/bin/bash
db_name=`grep DB_NAME wp-config.php | awk -F\' '{print $4}'`
db_user=`grep DB_USER wp-config.php | awk -F\' '{print $4}'`
db_pass=`grep DB_PASSWORD wp-config.php | awk -F\' '{print $4}'`
db_host=`grep DB_HOST wp-config.php | awk -F\' '{print $4}'`
 
mysql -u $db_user -h $db_host --password=$db_pass $db_name
 

wp-mysqldump

 
#!/bin/bash
db_name=`grep DB_NAME wp-config.php | awk -F\' '{print $4}'`
db_user=`grep DB_USER wp-config.php | awk -F\' '{print $4}'`
db_pass=`grep DB_PASSWORD wp-config.php | awk -F\' '{print $4}'`
db_host=`grep DB_HOST wp-config.php | awk -F\' '{print $4}'`
 
mysqldump -u $db_user -h $db_host --password=$db_pass $db_name
 
Add a comment
 
Wordpress Backup Script
Websites
Wednesday, 15 June 2011 09:45
Here's a quickie Wordpress backup script that I wrote. It gets the job done and may be useful to others. It assumes that it is being run as root and that backups are stored at /root/backups. Enjoy!
 
#!/bin/bash
 
#####################################################################################
# backup-blog
# Author: Dustin McQuay
#
# Simple script to backup a wordpress blog, including it's database.
#
# Usage: backup-blog [name] [source_directory]
# Example: backup-blog myblog /var/www/html/myblog
#
# You probably want to set it up to run daily using cron:
# 0 0 * * * backup-blog myblog /var/www/html/myblog
#####################################################################################
 
#set up file names and such
backup_name=$1
backup_source=$2
backup_root=/root/backups
backup_target_filename=$backup_name-`date +%F`.tar.gz
days_to_keep_backups=14
 
#ouptut this config
echo "backup_name=$backup_name"
echo "backup_source=$backup_source"
echo "backup_root=$backup_root"
echo "backup_target_filename=$backup_target_filename"
echo "days_to_keep_backups=$days_to_keep_backups"
echo
 
#acquire mysql creds
db_name=`grep DB_NAME $backup_source/wp-config.php | awk -F\' '{print $4}'`
db_user=`grep DB_USER $backup_source/wp-config.php | awk -F\' '{print $4}'`
db_pass=`grep DB_PASSWORD $backup_source/wp-config.php | awk -F\' '{print $4}'`
db_host=`grep DB_HOST $backup_source/wp-config.php | awk -F\' '{print $4}'`
 
#backup the database
echo -n "Creating database dump file: "
echo "mysqldump -u $db_user -h $db_host --password=$db_pass $db_name > $backup_source/dbdump.sql"
mysqldump -u $db_user -h $db_host --password=$db_pass $db_name > $backup_source/dbdump.sql
if [[ "$?" != "0" ]]; then exit; fi
 
#tar up the files, including db dump
echo -n "Archiving files to backup target: "
echo "tar -cz -f $backup_root/$backup_target_filename -C" `dirname $backup_source` `basename $backup_source`
tar -cz -f $backup_root/$backup_target_filename -C `dirname $backup_source` `basename $backup_source`
if [[ "$?" != "0" ]]; then exit; fi
 
#delete dbdump from backup_source because it is probably web accessible
echo -n "Removing dbdump: "
echo "rm $backup_source/dbdump.sql"
rm $backup_source/dbdump.sql
if [[ "$?" != "0" ]]; then exit; fi
 
#clean up? (delete backups older than x days???)
echo -n "Removing old backups: "
echo "rm -f \`ls $backup_root/$backup_name* -1 | head -n -$days_to_keep_backups\`"
rm -f `ls $backup_root/$backup_name* -1 | head -n \-$days_to_keep_backups`
if [[ "$?" != "0" ]]; then exit; fi
 
echo
echo "Backup completed successfully at "`date`
 
Add a comment
 
<< Start < Prev 1 2 3 4 5 6 Next > End >>

Page 1 of 6