Skip to content

Instantly share code, notes, and snippets.

View kljensen's full-sized avatar
😵‍💫
0101010101

Kyle L. Jensen kljensen

😵‍💫
0101010101
View GitHub Profile
{'query': {'bool': {'must':
[{'field':
{'abstract':
{'query': 'Kyle AND "body odor"'}}},
{'field':
{'title':
{'query': 'heat OR wave'}}}]}}}
def report_memory_leaked(f):
""" Counts objects allocated in memory before and after the
decorated function and reports the results. If you decorate
a function like
@report_memory_leaked
def myfunc():
pass # do stuff
It will report objects by type that were leaked or created.
"""
#!python
from google.appengine.api import mail
from google.appengine.api import urlfetch
try:
import json
except ImportError:
try:
import simplejson as json
except ImportError:
class HighBaseEncoder(object):
"""docstring for HighBaseEncoder
http://stackoverflow.com/questions/1119722/base-62-conversion-in-python
"""
def __init__(self):
super(HighBaseEncoder, self).__init__()
ALPHABET = "23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
# Make a new virtual env
# named ninjakitten
mkvirtualenv ninjakitten
cdvirtualenv
# Install readline binary
easy_install -a readline
# Install ipython
pip install -E . ipython
@kljensen
kljensen / fingerprint_cluster.py
Created December 15, 2010 16:09
Basic fingerprint algorithm from Google Refine
#!/usr/bin/env python
# encoding: utf-8
"""
fingerprint_cluster.py
Based on http://code.google.com/p/google-refine/wiki/ClusteringInDepth
Created by Kyle Jensen on 2010-12-15.
"""
import re
@kljensen
kljensen / prompt.zsh
Created May 31, 2012 20:13
Kyle's zsh prompt (pilfered from others)
autoload -Uz vcs_info
zstyle ':vcs_info:*' check-for-changes true
zstyle ':vcs_info:*' enable git svn hg
### git: Show marker (T) if there are untracked files in repository
# Make sure you have added staged to your 'formats': %c
function +vi-git-untracked(){
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' ]] && \
git status --porcelain | grep '??' &> /dev/null ; then
@kljensen
kljensen / gitx.zsh
Created June 28, 2012 19:55
Open GitX from the command line
GITX="/Applications/GitX.app/Contents/Resources/gitx"
if [[ -x $GITX ]]; then
gitx() {
if [[ ($# -eq 1) && ($1 != "-"*) ]]; then
# If a single arg is given, assume that
# arg is the directory to open.
$GITX --git-dir=$1
else
# Otherwise pass args to gitx.
$GITX "$@"
@kljensen
kljensen / vj.sh
Last active November 14, 2018 17:37
A simple, encrypted journal using vim.
#!/usr/bin/env bash
##########################################################
#
# This is a shell script for keeping a journal that is
# * plaintext,
# * time-stamped,
# * encrypted, and
# * edited with vim.
#
@kljensen
kljensen / set_postgresql_shared_mem.sh
Created February 6, 2013 14:12
Set shared memory for postgres on a linux box to a constant fraction of ram
# If you want maximum shared memory of 1/5 of your RAM,
# leave FRACTION as 5
FRACTION=5
RAM=`cat /proc/meminfo|grep ^MemTotal|awk '{printf("%.f", $2*1024)}'`
SHMMAX=`echo "$RAM / $FRACTION" |bc`
PAGESIZE=`getconf PAGESIZE`
SHMALL=`echo "$SHMMAX / $PAGESIZE" |bc`
sudo sysctl -w kernel.shmmax=$SHMMAX
sudo sysctl -w kernel.shmall=$SHMALL