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 / 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 / permissions.py
Created April 17, 2015 08:24
IsOwner - Custom django-rest-framework permission to only allow owners of an object to edit it.
from rest_framework import permissions
class IsOwner(permissions.BasePermission):
"""
Custom permission to only allow owners of an object to edit it.
"""
def has_permission(self, request, view):
return request.user and request.user.is_authenticated()
@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::
@Kobold
Kobold / round.js
Created September 16, 2015 04:05
Cool intelligent rounding function
function roundToSignificantFigures(num, sigFigs, truncationFunc) {
if (num == 0) {
return 0;
}
// We use base 5 because it makes for pretty numbers without intervals
// quite as large as base 10.
var d = Math.ceil(Math.log(num < 0 ? -num: num) / Math.log(5));
var power = sigFigs - d;
@Kobold
Kobold / help-hover.js
Created October 16, 2015 12:35
Help popovers.
$('.help-hover').popover({
trigger: 'hover'
});
@Kobold
Kobold / 1 screencast_1.py
Last active December 25, 2015 04:39
Nate ♥s L-systems
class LSystem(object):
def __init__(self, axiom, rules):
self.axiom = axiom
self.rules = rules
self.string = self.axiom
self.generation = 0
@Kobold
Kobold / nice-toolkit.css
Created April 21, 2016 09:59
Classy little helper CSS.
/* A very classy shadow. */
.classy-shadow {
box-shadow: -1px 0 0 0 #d1d1d1,
-1px 0 0 0 #e5e5e5,
1px 0 0 0 #d1d1d1,
2px 0 0 0 #e5e5e5,
0 -1px 0 0 #e7e7e7,
0 2px 0 0 rgba(240, 240, 240, 0.3),
0 1px 0 0 #b0b0b0;
}