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 / xkcd-worth-the-time.ipynb
Last active September 12, 2023 12:40
A Jupyter notebook to explore variations of xkcd's "Is it worth the time?" comic.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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 / 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 / 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 / inset_input.css
Created May 4, 2016 10:07 — forked from nrrrdcore/inset_input.css
The Perfect Inset Input CSS
input {
height: 34px;
width: 100%;
border-radius: 3px;
border: 1px solid transparent;
border-top: none;
border-bottom: 1px solid #DDD;
box-shadow: inset 0 1px 2px rgba(0,0,0,.39), 0 -1px 1px #FFF, 0 1px 0 #FFF;
}
@Kobold
Kobold / sortGoodreadsByPopularity.js
Created April 27, 2016 04:16
Bookmarklets to sort arbitrary Goodreads views by popularity and rating!
javascript:(() => {
if (window.tinysort === undefined) {
var script = document.createElement('script');
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/tinysort/2.3.0/tinysort.min.js';
script.onload = function() {
sortGoodreads();
};
document.getElementsByTagName('head')[0].appendChild(script);
} else {
sortGoodreads();
@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;
}
@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 / help-hover.js
Created October 16, 2015 12:35
Help popovers.
$('.help-hover').popover({
trigger: 'hover'
});
@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"""