Commonly I create temporary files using dd like this:

dd if=/dev/random of=blah bs=1m count=16

That will generate a random 16MB file named blah.

Doing the same thing in python looks something like this:

with open("blah", 'w') as f:
    for i in range((16*2**20)/512):
        f.write(os.urandom(512))

Posting here because it took me about 15 minutes longer than it should have to find that function.

 

At my job we used to have to have to log every hour worked.  I really hated it at first, but I got used to it.  After a while, I took for granted the ability to look back to see what I did on any given day.  Recently, they changed the policy so that we no longer have to log all of our hours, and I immediately began to lose track of my work history.

My solution is very simple.  Since I always have many terminals and screens running, I figured it would be nice if I could just leave notes for myself.  Here’s what I did:

#!/usr/bin/env python
from datetime import datetime

def log(msg):
    if len(msg)<2:
        return

    f = open('work.log', 'a')
    now = datetime.now().strftime("%Y-%m-%d %H:%M")
    f.write("%s: %s\n" % (now, msg))
    print "%s: %s" % (now, msg)
    f.close()

while(True):
    log(raw_input('work? '))

I simply run it in a terminal screen and whenever I'm working on something or complete something I jot down a note to myself.

Likewise, I did the same thing but for general notes. I generally use a wiki for note taking. The trouble is, the model doesn't work very well for me for transient and petty things. This way, I can just paste/type whatever I'd like into my note file and not really worry about publishing or styling or anything.

The method has yet to prove itself, and it is extremely rudimentary. I prefer to start as simple as possible and grow organically instead of attempting to construct a large solution that may or may not be used as anticipated (even by myself).

© 2011 The Rub Suffusion theme by Sayontan Sinha