Sections
Daniel
Moriah
Photos
Recipes
Movies
Software
Other
About
Contact
Show/Hide Search
Wolf
Entries By:
Daniel
Moriah

Entry Type:
Audio
Blog
Chat
Code
Link
Lyrics
Picture
Quote
Thought
Video

Archives By:
2010
M
F
J
2009
D
N
O
S
A
J
J
M
A
M
F
J
2008
D
N
O
S
A
J
J
M
A
M
F
J
2007
D
N
O
S
A
J
J
M
A
M
F
J
2006
D
N
O
S
A
J
J
M
A
M
F
J
2005
D
N
O
S
A
J
J
M
A
M
F
J
2004
D
N
O
S
A
J
J
M
A
M
F
J
2003
D
N
O
S
A

Links:
Toast Driven
Gemstone Creations
Wagging Work
Luke
Peter
Matt
Christian
Andy
Nummy!
Arthur
Nico
Mike T.
Bojangler
Eric's A Dirty Hippie
Phil
All Entries Filtered By Entry Type: code
May 18, 2009

[Daniel] Livable iPython config

# Add to ipy_user_conf.py
o.separate_in = ''
o.confirm_exit = 0
o.banner = 0
            
September 9, 2008

[Daniel] Best Moment Of The Day

matt_c: Ellington: 298 tests; no errors.
            
August 6, 2008

[Daniel] Command-Line Status Updates

"""
A simple but useful command-line trick.

To output a status update that stays on a single line, end your line with
\r instead of \n. This will cause the next line to print over the top of the 
current one. Be sure to output an extra blank newline (\n) once your loop is 
complete to retain the information (like the last record processed).

Works on Linux & Mac as it should, generates a ton of (correct) output on 
Windows. Works in all programming languages I've tried (PHP, Perl, Ruby, etc.), 
not just Python.
"""
for i in xrange(0, 100):
    # Processing happens here.
    print "Percent complete - %s%%\r" % i,

print
print "Complete!"
            
March 18, 2008

[Daniel] Oh Snap!

#!/usr/bin/env python
"""Since SnapTalent (http://snaptalent.com/) seems to have some solid jobs and a decent site, but no list of ads, let's make one."""
import urllib2

base_url = 'http://snaptalent.com/ads/'

for i in xrange(255):
    current_url = "%s%s" % (base_url, i)
    
    try:
        oh_snap = urllib2.urlopen(current_url)
        
        if oh_snap.code == 200:
            print "Valid URL: %s" % current_url
        
        oh_snap.close()
    except:
        pass
            
November 18, 2007

[Daniel] Color 'ls' on Mac OS X

In '/etc/bashrc':

export CLICOLOR='cons35'
export LSCOLORS='ExGxcxdxCxegedabagacad'

Fire up a new terminal and enjoy.
            
December 7, 2006

[Daniel] Django Newforms

from django.newforms import *

class Test(Form):
    name = CharField()
    email = EmailField()

def view_test(request):
    if request.POST:
        form = Test({
            "name": request.POST["name"],
            "email": request.POST["email"],
        })
        if form.errors != {}:
            # Process that data!
    else:
        form = Test()
    return render_to_response("view_test.html", {"form": form})