Skip to content

Instantly share code, notes, and snippets.

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

k⃝͡yl͜e j⃝͡en͜s͜en kljensen

😵‍💫
0101010101
  • ᒪ̊Λ̸̊ṅ̊̇ï̊̈ä̊̇̈k̊̇̈̊ë̊̈̇̊ä゚̈̇̊𖦹゚ Ꮥ̊͜͡ᑌ̊͜͡ᑭ̊͜͡Ɛ̊͜͡ᖇ̊͜͡ᑕ̊͜͡ᒪ̊͜͡ᑌ̊͜͡Ꮥ̊͜͡Ƭ̊͜͡Ɛ̊͜͡ᖇ̊ ⟳ ✧゚꩜
  • /dev/null
View GitHub Profile
# -*- coding: utf-8 -*-
""" Small script that shows hot to do one hot encoding
of categorical columns in a pandas DataFrame.
See:
http://scikit-learn.org/dev/modules/generated/sklearn.preprocessing.OneHotEncoder.html#sklearn.preprocessing.OneHotEncoder
http://scikit-learn.org/dev/modules/generated/sklearn.feature_extraction.DictVectorizer.html
"""
import pandas
import random
@kljensen
kljensen / celery_gevent_flask_fix.py
Created March 14, 2013 11:00
Fixing celery w/ the gevent worker -- Flask, celery, gevent, app_context
"""
If you're using Celery with the gevent worker and a Flask app,
you may have noticed that you're unsuccessful in having the
tasks execute within your Flask app's app_context. Normally,
you can do this
with app.app_context():
celery.start()
...but...doesn't appear to work with the gevent worker pool.
@kljensen
kljensen / discover_ips.sh
Created March 5, 2013 14:32
Discover IP & mac addresses of most devices on your network
# First, find your broadcast address
#
ifconfig
# - Should return something like the below, where 192.168.1.255 is
# - the broadcast address
# -
# - eth0 Link encap:Ethernet HWaddr b8:27:eb:19:c6:01
# - inet addr:192.168.1.109 Bcast:192.168.1.255 Mask:255.255.255.0
# - UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
@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
@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 / 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 / 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 / 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
# Make a new virtual env
# named ninjakitten
mkvirtualenv ninjakitten
cdvirtualenv
# Install readline binary
easy_install -a readline
# Install ipython
pip install -E . ipython
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"