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 / 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 / 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 / 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 / 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 / 0005_blah.py
Created December 11, 2014 23:37
How to make an order_with_respect_to migration work.
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class AlterOrderWithRespectTo(migrations.AlterOrderWithRespectTo):
"""
Represents a change with the order_with_respect_to option.
"""
@Kobold
Kobold / dump2csv.py
Created August 13, 2015 18:33
Dump querysets to csv
# Via: http://palewi.re/posts/2009/03/03/django-recipe-dump-your-queryset-out-as-a-csv-file/
import csv
from django.db.models.loading import get_model
def dump2csv(qs, outfile_path):
"""
Takes in a Django queryset and spits out a CSV file.
Usage::
import urllib
from xml.dom import minidom
from xml.dom.minidom import parse, parseString
display_tags = ["d:PartitionKey", "d:RowKey", "d:TimeStamp", "d:entityid",
"d:name", "d:address", "d:weburl", "d:gis_id", "d:gender",
"d:offensedescription"]
def GetData():
url = "http://ogdi.cloudapp.net/v1/dc/JuvenileArrestsCharges/?$filter=gender%20eq%20'F'"
class SubdivisionTree(object):
"""docstring for SubdivisionTree"""
def __init__(self, top, right, bottom, left, element=None):
self.top = top
self.right = right
self.bottom = bottom
self.left = left
self.element = element
-- Playing around with ContraFunctors
-- http://blog.ezyang.com/2010/07/flipping-arrows-in-coburger-king/
class ContraFunctor t where
contramap :: (a -> b) -> t b -> t a
newtype ContraF a b = ContraF (b -> a)
instance ContraFunctor (ContraF a) where
contramap g (ContraF f) = ContraF (f . g)
#include <iostream>
#include <map>
#include <string>
using namespace std;
map<char, char> alternatives;
void traverse(string prefix, string rest)
{
if (rest.empty()) {