Skip to content

Instantly share code, notes, and snippets.

@bgola
bgola / midkov.py
Created November 5, 2014 05:16
midkov.py
#!/usr/bin/python2
# coding: utf-8
import re, datetime, random, mido, sys, time
data = {}
def split(seq):
for i in range(len(seq) - 2):
yield tuple(seq[i:i+3])
@xmlking
xmlking / Enum.es6.js
Last active June 25, 2019 18:09
JavaScript Enums with ES6, Type Checking and Immutability
export class EnumSymbol {
sym = Symbol.for(name);
value: number;
description: string;
constructor(name: string, {value, description}) {
if(!Object.is(value, undefined)) this.value = value;
if(description) this.description = description;
@yyolk
yyolk / cache_mine.sh
Last active December 25, 2015 00:49
grab all JPEGs, PNGs, and GIFs from Chrome's cache (useful for when someone deletes a post)
#!/bin/sh
CHROME_CACHE=$HOME/Library/Caches/Google/Chrome/Default/Cache
TMP_DIR=$HOME/Downloads/tmp
mkdir -p $TMP_DIR
for i in $(file $CHROME_CACHE/* | egrep -i 'jp|gif|png' |awk '{print $1}' | sed 's/://g'); do cp -v $i $TMP_DIR/`basename $i`.$(file $i | awk '{print tolower($2)}') ; done
anonymous
anonymous / clickmap.js
Created August 14, 2012 13:30
$(document).ready(function() {
// create canvas
var canvas = document.createElement("canvas");
canvas.height = 300; // important! because default canvas size is 300x150
var ctx = canvas.getContext('2d');
// create img
var img = document.createElement("img");
// IMPORTANT adding shadow map - each area has different background color
@olooney
olooney / cropped_thumbnail.my
Created January 12, 2012 16:31
A "better" thumbnail algorithm for Python Image Library PIL Image
'''
PIL's Image.thumbnail() returns an image that fits inside of a given size (preserving aspect ratios)
but the size of the actual image will vary and is certainly not guaranteed to be the requested size.
This is often inconvenient since the size of the returned thumbnail cannot be predicted. The django-thumbs
library solves this for square thumbnails by cropping the image to a square and then resizing it. However,
this only works for exact squares.
This function generalizes that approach to work for thumbnails of any aspect ratio. The returned thumbnail
is always exactly the requested size, and edges (left/right or top/bottom) are cropped off to adjust to
make sure the thumbnail will be the right size without distorting the image.
@adeleinr
adeleinr / fabric.py
Created April 20, 2011 21:21
fabric config for deploying a Django project
"""
Distributor ID: Ubuntu
Description: Ubuntu 10.04 LTS
Release: 10.04
Codename: lucid
Author: Adelein Rodriguez, adeleinr@gmail.com
Note: This is an adaptation from a fabric script presented here:
http://morethanseven.net/2009/07/27/fabric-django-git-apache-mod_wsgi-virtualenv-and-p.html
Summary: This script: