davehansen's posterous http://davehansen.posterous.com Most recent posts at davehansen's posterous posterous.com Wed, 16 Sep 2009 14:24:42 -0700 MySQLdb User's Guide http://davehansen.posterous.com/mysqldb-users-guide http://davehansen.posterous.com/mysqldb-users-guide http://mysql-python.sourceforge.net/MySQLdb.html

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Tue, 15 Sep 2009 19:51:33 -0700 Lec 1 | MIT 6.00 Introduction to Computer Science and Programming, Fall 2008 http://davehansen.posterous.com/lec-1-mit-600-introduction-to-computer-scienc http://davehansen.posterous.com/lec-1-mit-600-introduction-to-computer-scienc

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Sat, 05 Sep 2009 10:57:55 -0700 Convert files to JPEG w/ Python/PIL http://davehansen.posterous.com/convert-files-to-jpeg-w-pythonpil http://davehansen.posterous.com/convert-files-to-jpeg-w-pythonpil Convert files to JPEG

 import os, sys
import Image

 for infile in sys.argv[1:]:
  f, e = os.path.splitext(infile)
  outfile = f + ".jpg"
  if infile != outfile:
  try:
  Image.open(infile).save(outfile)
  except IOError:
  print "cannot convert", infile

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Thu, 03 Sep 2009 13:19:45 -0700 Zenburn for putty http://davehansen.posterous.com/zenburn-for-putty http://davehansen.posterous.com/zenburn-for-putty Default Foreground: 255/255/255
Default Background: 51/51/51
ANSI Black: 77/77/77
ANSI Green: 152/251/152
ANSI Yellow: 240/230/140
ANSI Blue: 205/133/63
ANSI Blue Bold 135/206/235
ANSI Magenta: 205/92/92
ANSI Cyan: 255/160/160
ANSI Cyan Bold: 255/215/0
ANSI White: 245/222/179

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Mon, 31 Aug 2009 15:52:33 -0700 ImageMagick hax http://davehansen.posterous.com/imagemagick-hax http://davehansen.posterous.com/imagemagick-hax

convert -background white -transparent white -pointsize 32 -size 200x
caption:'Journal of Human Consumption and Cannibalism Studies' +repage
text.gif
composite -gravity center text.gif blank.gif blank-text.gif

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Thu, 27 Aug 2009 11:13:19 -0700 Learning to handle cookies with python scraper http://davehansen.posterous.com/learning-to-handle-cookies-with-python-scrape http://davehansen.posterous.com/learning-to-handle-cookies-with-python-scrape cookielib_example.py: uses cookielib and various other methods for foolproof cookie handling and storage
scaper.py: uses pycurl/libcurl to access resources with 'automatic cookie handling'

Click here to download:
cookielib_example.py (4 KB)

Click here to download:
scraper.py (1 KB)

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Thu, 20 Aug 2009 08:01:00 -0700 Cory Doctorow interview on librarianship and media http://davehansen.posterous.com/cory-doctorow-interview-on-librarianship-and http://davehansen.posterous.com/cory-doctorow-interview-on-librarianship-and

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Wed, 19 Aug 2009 10:48:26 -0700 App to AutoFilter Google Docs spreadsheets http://davehansen.posterous.com/app-to-autofilter-google-docs-spreadsheets http://davehansen.posterous.com/app-to-autofilter-google-docs-spreadsheets http://spreadsheetautofilter.googlepages.com/index.html

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Wed, 19 Aug 2009 09:34:02 -0700 Git troubleshooting http://davehansen.posterous.com/git-troubleshooting http://davehansen.posterous.com/git-troubleshooting

When Git tells you it failed to push some refs (link)

I received an unhelpful error while trying to push to a repository on Github today:

 git push
To git@github.com:user/repo.git
! [rejected] branchname -> branchname (non-fast forward)
error: failed to push some refs to 'git@github.com:user/repo.git'

In case you ever have the same problem, all you have to do is a quick git pull first, then you can carry on as normal. Easy when you know how...

github and public key (link)

 $ git push origin master Permission denied (publickey). fatal: The remote end hung up unexpectedly error: failed to push to 'git@github.com:stonean/stage.git' 

I knew it was a configuration issue, just wasn’t sure if it was a git thing or not. After a minute or two of thinking it through, all I needed to do was:

 $ cd ~/.ssh $ ssh-add id_rsa

I then re-tried the push command, and it worked. Cool.

UPDATE: Can just do ssh-add without being in the .ssh directory

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Sat, 15 Aug 2009 21:35:35 -0700 Getting Wii Sports Resort working http://davehansen.posterous.com/getting-wii-sports-resort-working http://davehansen.posterous.com/getting-wii-sports-resort-working from description of this video:

 Config Options -> Alt .Dol -> CD

 When booting, press right arrow to choose player.dol

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Sat, 15 Aug 2009 21:15:00 -0700 Wii Softmod update http://davehansen.posterous.com/wii-softmod-update http://davehansen.posterous.com/wii-softmod-update

Followed guide tonight on:
http://www.yafaze.com/forums/viewtopic.php?f=46&t=1178&p=9923#p9923
 
Last step performed was installing CIOSrev14

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Thu, 30 Jul 2009 16:48:24 -0700 http://web.media.mit.edu/~jorkin/aibooks.html http://davehansen.posterous.com/httpwebmediamitedujorkinaibookshtml http://davehansen.posterous.com/httpwebmediamitedujorkinaibookshtml from http://web.media.mit.edu/~jorkin/aibooks.html:

GAME AI
AI Game Programming Wisdom - Edited by Steve Rabin
AI Game Programming Wisdom 2 - Edited by Steve Rabin
AI Game Programming Wisdom 3 - Edited by Steve Rabin
AI Game Programming Wisdom 4 - Edited by Steve Rabin
Programming Game AI by Example - Mat Buckland
AI Techniques for Game Programming - Mat Buckland
Artificial Intelligence For Computer Games: An Introduction - John Funge
AI for Computer Games and Animation: A Cognitive Modeling Approach - John Funge
AI Game Development: Synthetic Creatures with Learning and Reactive Behaviors - Alex J. Champandard
AI Game Engine Programming - Brian Schwab
Artificial Intelligence for Games - Ian Millington
Behavioral Mathematics for Game AI - Dave Mark
AI for Game Developers - David M. Bourg
Game Programming Gems - Edited by Mark DeLoura
Game Programming Gems 2 - Edited by Mark DeLoura
Game Programming Gems 3 - Edited by Dante Treglia
Game Programming Gems 4 - Edited by Andrew Kirmse
Game Programming Gems 5 - Edited by Kim Pallister
Game Programming Gems 6 - Edited by Mike Dickheiser
Game Programming Gems 7 - Edited by Scott Jacobs
 
 ACADEMIC AI TEXTBOOKS
Artificial Intelligence: A Modern Approach - Stuart Russell and Peter Norvig
Artificial Intelligence: A New Synthesis - Nils J. Nilsson
Artificial Intelligence - Patrick H. Winston
 
 MACHINE LEARNING & DATA MINING
Machine Learning - Thomas Mitchell
Data Mining: Practical Machine Learning Tools and Techniques - Ian H. Witten and Eibe Frank
Pattern Classification - Richard O. Duda, Peter E. Hart, and David G. Stork
 
 COMPILER DESIGN
Compilers: Principles, Techniques, and Tools - Alfred V. Aho, Monica S. Lam, Ravi Sethi, and Jeffrey D. Ullman
lex & yacc - Doug Brown and Tony Mason
 
 NATURAL LANGUAGE PROCESSING AND GENERATION
Foundations of Statistical Natural Language Processing - Christopher D. Manning and Hinrich Schutze
Speech and Language Processing - Daniel Jurafsky and James H. Martin
Generating Natural Language Under Pragmatic Constraints - Eduard H. Hovy
Algorithms on Strings, Trees and Sequences: Computer Science and Computational Biology - Dan Gusfield
 
 MODELS OF THE MIND AND EMOTION
Society of Mind - Marvin Minsky
The Emotion Machine: Commonsense Thinking, Artificial Intelligence, and the Future of the Human Mind - Marvin Minsky
Designing Sociable Robots - Cynthia Breazeal
Commonsense Reasoning - Erik T. Mueller
 
 PLANNING
Automated Planning: Theory & Practice - Malik Ghallab, Dana Nau, and Paolo Traverso
 
 RELATED TEXTBOOKS
Data Structures Using C and C++ - Yedidyah Langsam, Moshe J. Augenstein, and Aaron M. Tenenbaum
Introduction to Probability - Dimitri P. Bertsekas and John N. Tsitsiklis
Introduction to Algorithms - Thomas H. Cormen, Charles E. Leiserson, Ronald L. Rivest, and Clifford Stein
The Algorithm Design Manual - Steven S. Skiena
Introductory Linear Algebra: An Applied First Course - Bernard Kolman
All the Mathematics You Missed: But Need to Know for Graduate School - Thomas A. Garrity
Computer Vision - Linda G. Shapiro and George C. Stockman
 
 RELATED READING
Creation: Life and How to Make It - Steve Grand
Edison's Eve: A Magical History of the Quest for Mechanical Life - Gaby Wood
Scripts, Plans, Goals, and Understanding: An Inquiry Into Human Knowledge Structures - Roger Schank and Robert Abelson
Intention, Plans, and Practical Reason - Michael E. Bratman
The Intentional Stance - Daniel C. Dennett
Using Language - Herbert H. Clark
The Language Instinct: How the Mind Creates Language - Steven Pinker
Understanding Comics: The Invisible Art - Scott McCloud
The Illusion of Life: Disney Animation - Ollie Johnston and Frank Thomas

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Thu, 09 Jul 2009 14:26:00 -0700 bash for loop http://davehansen.posterous.com/bash-for-loop http://davehansen.posterous.com/bash-for-loop

Loop over a shell command like a for loop. Useful for testing.

#!/bin/bash
for i in {1..10}; do echo "Welcome $i times"; pwd; done

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Thu, 09 Jul 2009 12:21:06 -0700 journalInfo.php http://davehansen.posterous.com/journalinfophp http://davehansen.posterous.com/journalinfophp
Given an ISSN ('journalInfo.php?issn=xxxx-xxxx'), grab the journal title, issn, and all links from the Core Periodicals list.

<?php

function trimProxyLeader($url) {
if (preg_match('/\?url=/', $url)) {
$split_url = preg_split('/\?url=/', $url);
return $split_url[1];
}
else {
return $url;
}
}

#header('Content-type: application/xml');
$issn = $_REQUEST['issn'];
if ($issn) {
$html = @DOMDocument::loadHTMLFile($url); // fetch the remote HTML file and parse it (@ suppresses warnings).
$xml = simplexml_import_dom($html); // convert the DOM object to a SimpleXML object.
$journalInfo = array(
"title",
"issn",
"links" => array()
);
foreach ($xml->xpath('//div') as $node){ // run an XPath query and iterate through the array of results
if ($node['class'] == 'SS_Holding') {
//grab the title and issn
foreach($node->xpath('//span') as $x) {
if ($x['class'] == 'SS_JournalTitle') {
$journalInfo['title'] = $x->children();
}
if ($x['class'] == 'SS_JournalISSN') {
$journalInfo['issn'] = preg_replace("/[()]/", "", $x);
}
}
//grab the links
foreach($node->xpath('//a') as $x) {
if ($x['class'] == 'SS_JournalHyperLink') {
$link_split = split('=', $x['href']);
$link = trimProxyLeader(urldecode($link_split[4]));
array_push($journalInfo['links'], $link);
}
}
}
}
print($journalInfo['title'].';');
print($journalInfo['issn'].';');
foreach ($journalInfo['links'] as $link) {
print $link.'|';
}
}

?>

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Mon, 06 Jul 2009 13:43:43 -0700 scraping and parsing with BeautifulSoup http://davehansen.posterous.com/scraping-and-parsing-with-beautifulsoup http://davehansen.posterous.com/scraping-and-parsing-with-beautifulsoup
import urllib2
import sys
from BeautifulSoup import BeautifulSoup

try:
url = sys.argv[1]
except IndexError:
print 'No URL to scrape. Please supply a target URL.'
sys.exit()

page = urllib2.urlopen(url)
soup = BeautifulSoup(page)

image = soup.find({'img' : True}, attrs={'alt' : 'Cover'})

print image['src']

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Sun, 05 Jul 2009 14:44:56 -0700 restarting sshd http://davehansen.posterous.com/restarting-sshd http://davehansen.posterous.com/restarting-sshd sudo /etc/init.d/ssh restart

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Sat, 04 Jul 2009 11:32:00 -0700 The Django Book http://davehansen.posterous.com/the-django-book http://davehansen.posterous.com/the-django-book

http://www.djangobook.com/en/2.0/

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Thu, 02 Jul 2009 14:12:00 -0700 First python script http://davehansen.posterous.com/first-python-script http://davehansen.posterous.com/first-python-script
My first functional Python script. Grabs the 'src' attribute of a specific image on a specific page, using xpath.

#!/usr/bin/python -u

from lxml import etree

parser = etree.HTMLParser()
html   = etree.parse('http://orgsci.journal.informs.org/', parser)

img = html.xpath('//a[(((count(preceding-sibling::*) + 1) = 3) and parent::*)]//img/@src')

for x in img:
print(x)

 

 

 

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen
Wed, 01 Jul 2009 14:55:00 -0700 python packages http://davehansen.posterous.com/python-packages http://davehansen.posterous.com/python-packages

feedparser: for parsing RSS feeds INSTALLED

lxml: for parsing HTML and XML INSTALLED
  • needed libxml2-dev and libxslt-dev installed using apt-get

urllib & urllib2: replaces curl, for sending HTTP requests INSTALLED [default]

Permalink | Leave a comment  »

]]>
http://posterous.com/images/profile/unknown75.gif http://posterous.com/people/eEShRjjJaV davehansen davehansen