Wednesday, June 19, 2013

dumping postgres database via backup script

I came across an issue when trying to backup a database via pg_dump. The issue was that I needed to type the password. mysql will let me dump the database with the password on the command line, but postgresql does not and requires a prompt or a variable. You can use PGPASSWORD or .pgpass and I used the environmental variable.

In my BASH script, backup.sh, I have:
TIMEATSTART=$(date +%Y-%m-%d-%s) 
DIRECTORY_ARC=$USER_HOME/archive
FILENAME_DBBACKUP=db-$TIMEATSTART.gz

export PGPASSWORD=dbpassword
pg_dump -U dbuser database_name | gzip -c > $DIRECTORY_ARC/$FILENAME_DBBACKUP
The script makes a convenient backup of my database_name database to an archive/db-00000000000.gz file in my home directory.

Friday, June 14, 2013

Isn't public debt the debt of the public?

The art in Detroit cannot be sold because it is owned by the public. Considering that the debt is that of the public, it seems that something is logically wrong. Detroit is a city of "people", and those "people" voted for, or leveraged the use of money that caused the debt. Regardless of what the lawyers *think* the answer is, the correct answer is that the people owe on the debt.

Tuesday, June 4, 2013

When someone steals your keys, they might steal your car.

Summary: Someone breaks into your house and steals everything, including your keys, and then later steals the car. http://www.cbsatlanta.com/story/22434247/several-cars-damaged-before-chase-ends

sui: hello.
r: yo
sui: I'm meeting B. Wednesday for Frisbee!
r: oh nice
sui: totally miss playing frisbee with you
r: we should have done that more
sui: how are things?
r: things are alright did a pretty crazy camping trip over last weekend
got my truck stolen monday night
good stuff
sui:stolen?
r: heh yah
sui: you need to get out of ATL. it's a sign.
r: well when we got robbed they stole spare keys to my truck and D's bmw
sui: from your apartment?
r: we'd been being careful
parking our cars elsewhere
until we got them rekeyed
but my truck ended up at the apartment for like 4 hours one night
and it got jacked
sui: :/
r: they caught the guy though
sui: oh? that's good.
r: tried to pull him over bc he didn't have his lights on at 230am, he fled ended up hitting a residential speedbump, tubling over and totalling 5 parked cars on the side of the street, landed on the roof of a house got out and started running
i've got insurance to cover it
sui: ha, well, I think at least the insurance company will believe you
r: talked to insurance lady, and she was like, oh yah, i saw you on the news
http://www.cbsatlanta.com/story/22434247/several-cars-damaged-before-chase-ends
that video isn't worth watchign really
but the text is accurate
oh, so get this, atlanta police are not allowed to pursue
so if they try to pull you over
and you floor it
they're supposed to disengage
so running from the police is a totally viable option in atlanta
sui: wow
r: so this officer tried to pull guy over, he fled, officer stopped pursuit (i actually talked to the guy) and the fleeing guy got into an accident like a mile down the road
sui: wow, that guy seems to be a professional loser
r: yah...
we looked up his jail record
was never in jail for more than a month
wonder if we have like a 15 strikes and you're out policy in atl
sui: still a month is enough to make sure you don't have a real job
r: well
true
but not enough penalty on this shit
probably robs 10 places before getting caught
make a few thousands dollars, spend a month in jail
worth it
sui: Is the car being removed in the video yours?
r: dunno, that video keeps changing
i was in it for a while
but i was boring, tired, and annoyed they were interviewing me
so they took me off
all vehicles were towed at night
mine is kinda triangle shaped
sui: You need to work on your inherent sense of showman ship I guess. Still, what a few weeks for you

Saturday, June 1, 2013

Install SLIM for PHP in a single stroke...

I use SLIM for my web service for a personal project that I have been working on. It works great, but I forget the steps to install it because I revisit this project every 3 months or so. The BASH script below downloads the slim framework, writes the initial index.php file and sets up the .htaccess file. I run this from the root of my website directory.
 #!/bin/sh  
 #  
 #This installs the SLIM framework in a single command.  
 WEBSERVICE_ROOT=api  
 WEBSERVICE_FILE=index.php  
 echo "installing SLIM framework and dependencies in ./$WEBSERVICE_ROOT"  
 if [ -d $WEBSERVICE_ROOT ]  
 then  
      echo "api exists... slipping creation"  
 else  
      mkdir $WEBSERVICE_ROOT  
 fi  
 echo "{\"require\": {\"slim/slim\": \"2.*\"}}" > $WEBSERVICE_ROOT/composer.json  
 cd $WEBSERVICE_ROOT > /dev/null ;  
 curl -s https://getcomposer.org/installer | php -d detect_unicode=Off  
 php composer.phar install  
 echo "RewriteEngine On\nRewriteCond %{REQUEST_FILENAME} !-f\nRewriteRule ^ $WEBSERVICE_FILE [QSA,L]" > .htaccess  
 if [ -f $WEBSERVICE_FILE ]  
 then  
   echo "$WEBSERVICE_FILE exists\n"  
 else  
      echo "<?php\nrequire 'vendor/autoload.php';\n" >> $WEBSERVICE_FILE  
      echo "\$app = new \Slim\Slim();\n" >> $WEBSERVICE_FILE  
      echo "\$app->get('/hello/:name', function (\$name) {\n" >> $WEBSERVICE_FILE  
   echo "echo \"Hello, \$name\";\n" >> $WEBSERVICE_FILE  
   echo "});\n" >> $WEBSERVICE_FILE  
      echo "\$app->run();?>\n" >> $WEBSERVICE_FILE  
 fi  
 echo "it should have worked, try http://127.0.0.1/api/hello/test and you should see \"Hello, test\""