Skip to content

Instantly share code, notes, and snippets.

@bkeating
Last active December 23, 2015 07:59
Show Gist options
  • Save bkeating/6604579 to your computer and use it in GitHub Desktop.
Save bkeating/6604579 to your computer and use it in GitHub Desktop.
I use to keep a diary file as a single text file. Each note was separated by a datestamp. I wanted to break them out into their own individual text files so I wrote this with some help: http://stackoverflow.com/questions/18860441/split-diary-file-into-multiple-files-using-python/

Friday 02011-06-24 at 04:17:21 PM

Started new and improved diary file. Now in markdown format!

A good UNIX date string (used for my TextMate diary now macro):

date +"# %A 0%Y-%m-%d at %r"

Wednesday 02011-08-24 at 04-10-31 PM

Generating a md5 hash in Python

>>> import hashlib
>>> import random
>>> hashlib.sha1(str(random.random())).hexdigest()

Tuesday 02012-11-27 at 11-25-41 AM

RegEx: "search for lines that do NOT start with a dollar sign":

^(?!\$).+

Tuesday 02012-05-15 at 11-51-04 PM

Just do pip install python-memcached and you should be good.

As for installing memcached itself, it depends on the platform you are on.

Tuesday 02012-04-10 at 12-41-12 PM

Get the Memory of a machine....

Solaris

  • dmesg | grep mem
  • prtdiag | grep Memory
  • prtconf -v | grep Memory

AIX

  • bootinfo -r
  • lsattr -E1 sys0 -a realmem
  • getconf REAL_MEMORY

HPUX

  • dmesg | grep Physical
  • /opt/ignite/bin/print_manifest | grep Memory
  • machinfo | grep Memory

Linux

  • dmesg | grep Memory
  • grep -i memtotal /proc/meminfo
  • free

OpenVMS

  • show mem /page

FreeBSD

  • dmesg | grep memory
  • grep memory /var/run/dmesg.boot
  • sysctl -a | grep mem
"""
diarya.py - shits your diary file out into individual text files :D
"""
from __future__ import print_function
import re
date_re = re.compile(r'^#(\s)(Mon|Tue|Wed|Thu|Fri|Sat|Sun)(.*)(\s)(.*)$')
def create_note(body):
filename = "%s.txt" % body[0][2:].rstrip().replace(":", "-")
del body[0]
with open(filename, "w") as f:
f.writelines(body)
f = open("diary-example.md", "r")
body = []
for line in f:
if date_re.match(line):
if body:
create_note(body)
body = []
body.append(line)
if body:
create_note(body)
f.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment