Skip to content

Instantly share code, notes, and snippets.

View Kobold's full-sized avatar

Andy Kish Kobold

  • TenantBase
  • Santa Monica, CA
View GitHub Profile
@Kobold
Kobold / ohlife_to_dayone.py
Last active August 29, 2015 14:06
Import an ohlife.com export text file to the mac app Day One.
#!/usr/bin/env python
"""
Run me like: python ohlife_to_dayone.py /Users/Kobold/Downloads/ohlife_20140925.txt
"""
import envoy
import re
import sys
def entries(filename):
timestamp = None
@Kobold
Kobold / README.md
Last active August 29, 2015 14:06
Obfuscate primary keys

Obfuscating primary keys

Often you'll want urls that are not authenticated, yet are not easily guessed. Giving each of your models a UUID is one approach. Another elegant approach is to use a block cipher to "encrypt" a unique identifier like the primary key (PK).

Let's sketch out what properties a good solution for PK obfuscation has:

  • Generates a one to one mapping between all PKs and obfuscated PKs, with no possibility of collision.
  • Not easily possible for an attacker to determine the obfuscated PK given a PK and vice versa.
  • Reversible, i.e. the originator can determine the original PK given an obfuscated PK.
@Kobold
Kobold / webpack.config.js
Created September 10, 2014 04:14
An example webpack config that I'm not sure handles external dependencies correctly.
var path = require('path');
module.exports = {
entry: {
module1: './static/js/module1.js',
module2: './static/jsx/module2.jsx',
module3: [
'./static/vendor/drop/drop.min.js',
'./static/vendor/jquery-timepicker-jt/jquery.timepicker.js',
'./static/jsx/module3.jsx',
@Kobold
Kobold / knight_moves.py
Created September 8, 2014 02:19
A python sketch aiming to find optimal play for the Big Brother S16 Knight Moves competition.
""""
A quick sketch aiming to find optimal play for the Big Brother S16 Knight Moves
competition. As it stands, this python version is waaay to slow.
Videos of the competition:
* http://www.cbs.com/shows/big_brother/video/fOLeybDVKA8LopMlgTZj05M__wPnnYMI/big-brother-knight-moves/
* https://tv.yahoo.com/video/big-brother-knight-moves-015945588-cbs.html
wins found per second
{2: 343036, 3: 527582, 4: 383558} 11259.6712734
@Kobold
Kobold / write_restricted_model_serializer.py
Created February 26, 2014 20:34
A default read-only serializer for django-rest-framework as of DRF 2.4.
class RestrictedSerializerOptions(serializers.ModelSerializerOptions):
"""
Meta class options for ModelSerializer
"""
def __init__(self, meta):
super(RestrictedSerializerOptions, self).__init__(meta)
self.writable_fields = getattr(meta, 'writable_fields', ())
class WriteRestrictedModelSerializer(serializers.ModelSerializer):
@Kobold
Kobold / dupe_finder.py
Created April 12, 2011 00:10
Finds duplicate files probablistically and quickly.
#!/usr/local/bin/python
from paste.util.multidict import MultiDict
from pprint import pprint
import hashlib
import os
import sys
def md5(file_path, block_size=2**18):
"""Compute md5 hash of first ``block_size`` of the specified file"""
@Kobold
Kobold / el_test.pde
Created December 16, 2010 18:26
An arduino control thingy.
// the pins for each connector on the el escudo
#define A 2
#define B 3
#define C 4
#define D 5
#define E 6
#define F 7
#define G 8
#define H 9
@Kobold
Kobold / optical_flow.py
Created November 10, 2010 01:32
an implemention of automated rig removal
"""
The rest of the example code that I ganked.
// 3. Draw arrows on second image to show movement
for (int x=0; x<frame2->width; x=x+10) {
for (int y=0; y<frame2->height; y=y+10) {
int vel_x_here = (int)cvGetReal2D( vel_x, y, x);
int vel_y_here = (int)cvGetReal2D( vel_y, y, x);
cvLine( frame2, cvPoint(x, y), cvPoint(x+vel_x_here,
y+vel_y_here), cvScalarAll(255));
int potpin = 0;
int speakerPin = 9;
int redPin = 10;
int bluePin = 12;
int high = 0, low = 500;
void setup()
{
pinMode(speakerPin, OUTPUT);
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<char, char> alternatives;
void traverse(string prefix, string rest)
{
if (rest.empty()) {