Django On Mac OSx
Posted by: Logan Bailey in Web Development on March 8th, 2010
Originally battling with installing Django on OSx I decided to go with my host(dream host) then after battling with them and realizing that I did alot of my development on a train with out internet access that it would really benefit me to install it on my Mac OSx Laptop and to forgot the Apache Integration, I thought this would be a synch armed with my new book I leaped into the unknown. The instructions were pretty easy to follow:
I installed a new version of MySQL, pretty easy find out what version of OSx you’re running and if you don’t know how many bytes your processor is go with 32.
Then using basic commands from the Django website. (I’m a big fan of svn, as i use it at work, I also see it’s down sides though) I was able to install Django and begin with the “interesting chapters” of my book.
./django-admin.py startapp mysite
./manage.py startserver(You can verify this works here, but we’ll check later)
So I trucked onwards in my book with the next command that actually set the framework and got the ball rolling.
./manage startapp blog
Then I continued defined a Model and set my database information in the settings tab. And that’s when I hit my first road bump, I’m a trained programming not really a systems guy. Everything I learn about sysadmins is by total accident in an attempt to do something with a programming language.
The first of two problems was python could not find the mysql driver. This isn’t a hard problem at all.
1. Download East Install(download the egg that is the same version as python you’re running)
2. run the command “sudo sh setuptools-0.6c9-py2.4.egg ” renaming 2.4.egg to the file you’ve downloaded
3. Run this command “easy_install MySQL-python” (This will install the mysql patch)
3.5 (At this point feel free to try the “./manage syncdb” command again it should fail
4. Open ./bash_profile or ./profile in using vim ~/.bash_profile or vim ~/.profile
5. add the following line PATH=”${PATH}:/usr/local/mysql/bin” (and “EXPORT PATH” if needed, this will allow all binary files to be added to the global link, to test this run mysql_config from wherever you are)
6. At this point you should be able to run “./manage syncdb” with no problem
If you’re following the same book as me, Python Web Development with Django, it will have you setup the admin controller for the blog site. Once you do this and visit your blogsite you will have some error saying that “NameError: name ‘admin’ is not defined”. In the urls.py add the following line of code “from django.contrib import admin” and you should be golden
Valid Credit Card Numbers for Paypal Sandbox
Posted by: Logan Bailey in Web Development on March 5th, 2010
When testing your paypal account in the sandbox you’ll sometime need a fake credit card, and the ones supplied by Paypal do not work.
The easiest way is to login/create an account in the sandbox. When you do that goto My Account > Profile > Credit/Debit Cards.
From here create a credit card, remember the information for this credit card, and yes you can leave the Card Verification Number as 000.
And there you go, a valid credit card number. Note if you save this credit card you will not be able to save it as it will be tied to a paypal account.
Changing Search Engine in Chrome
Posted by: Logan Bailey in Web Development on February 24th, 2010
To use google search in Chrome all you need to do is type the search term in the address bar, simple.
But is there a way to change the search engine to yahoo? Can I have multiple search engines like Firefox supports with a drop down, the answer is two these is yes.
Right click the address bar and click “Edit Search Engines”. As you can see there is a pre-populated list of popular search engines, as well as search engines that you have transfered over from existing browsers. You can easily any of these to your default search engine by click “Making Default” on the bottom when the specific search engine is selected. But how do you change the search engine?
When you looking at the “Edit Search Engines” window there are two columns: Name, Keywords. You can edit these by simply double clicking on the row. But back to the browser window, highlight the address bar(ctrl L) type the keyword for the search engine you want to use yahoo.com and then tab. This should create “Search Yahoo!” box in the url so you are aware of what engine you are using. escape will set the url back to what it was originally
My First Ruby Script
Posted by: Logan Bailey in Web Development on December 12th, 2009
I decided as PHP developer I should learn another scripting language. After running into RoR several times I decided I’d be better off just learning Ruby. Asking my boss for any advise he told me to just rewrite what I do at work with Ruby.
Well I didn’t take is advice on a per word basis, but This is my first ruby script. It’s designed to be run from the command line. Any suggestions on making it better are welcomed.
if ARGV.length != 1 puts "Expecting 1 arguement found #{ARGV.length}" Process.exit end def fibonacci_seq(max) current = prev = comparison = 1 while comparison < max temp = current + prev prev = current current = temp comparison+=1 end return current end max = ARGV.shift.to_i puts fibonacci_seq(max)This is a pretty straight forward function, slightly harder than your normal "Hello World" but doesn't do anything to revolutionary. Little surprised about the lack of increment/decrement operator, but I recall reading that it isn't not there because it is unclear.
if ARGV.length != 1puts "Expecting 1 arguement found #{ARGV.length}"Process.exitenddef fibonacci_seq(max)current = prev = comparison = 1while comparison < maxtemp = current + prevprev = currentcurrent = tempcomparison+=1endreturn currentendmax = ARGV.shift.to_iputs fibonacci_seq(max)
Validating Integers
Posted by: Logan Bailey in Web Development on December 9th, 2009
A while at work I came across some random reference where I need to validate that a $_POST or $_GET value was an integer. Now this is a fairy common problem, but like many PHP programmers I had never found Filter Var Functions. I came across what ended up being an extremely tedious work around.
The issue arises when a variable needs to be an integer where 0 is a possible value. Most databases don’t use 0 as indexs so this is a semi rare situation, but often happens on drop downs and sliders. The issue is as follows
$not_int = 'asdf'; $int = '5'; $int_2 = 0; is_int($not_int); //false is_int($int); //false(it's a string duh is_int($int_2); //true intval($not_int); // 0 intval($int) // 5 intval($int_2); // 0 /* Then I had to figure out how to determine if the original value was 0; Meaning if I passed in a 0, but it was a string My original theory was*/ if(intval($not_int) != $not_int) {} /* This should've worked, btu upon further inspection i release with type converting for comparison i was essentially doing */ if(intval($not_int) != (int)$not_int){} // Identical so they're always equal $int = '5'; $int_2 = 0;</div> is_int($not_int); //false is_int($int); //false(it's a string duh is_int($int_2); //true intval($not_int); // 0 intval($int) // 5 intval($int_2); // 0 /* Then I had to figure out how to determine if the original value was 0; Meaning if I passed in a 0, but it was a string My original theory was*/ if(intval($not_int) != $not_int) {} /* This should've worked, btu upon further inspection i release with type converting for comparison i was essentially doing */ if(intval($not_int) != (int)$not_int){} // Identical so they're always equal</div>The solution is filter_var.
Filter var and it’s sister function sanitize var gives you a nice solution to this problem as well as many other problems in the web.
if(filter_var($not_int, FILTER_VALIDATE_INT) !== false ) {}
The tricky thing about this function is it returns the integer value, so be careful to use !== when comparing to false.
There are a large number of “filters” that can replace common used regexp, IP address, email, url. I’d suggest giving this a really good going over.
Setting Colors In Bash Prompt
Posted by: Logan Bailey in Web Development on June 14th, 2009
Here is how to turn on Colors in your Bash Prompt
Open up
./bash_profile and insert the following code:
export CLICOLOR=1 export LSCOLORS=ExFxCxDxBxegedabagacad