Skip to content

Instantly share code, notes, and snippets.

var choose = function(a, b, teams) {
if (teams[a] && teams[b]) {
return teams[a] < teams[b] ? a : b;
} else if (teams[a]) {
return a;
} else if (teams[b]) {
return b;
} else {
return Math.random() < 0.5 ? a : b;
}
function choice(set, choice) {
return set.indexOf(choice) > -1 ? choice : '';
}
function blankArray(l) {
return (new Array(l)).map(function(){ return ''; });
}
Array.prototype.pairChoice = function(c) {
@tstone
tstone / fizzbuzz.dart
Created January 7, 2012 15:44
FizzBuzz in Dart
// -- FizzBuzz in Dart --
void fbPrint(c) {
if (c % 15 == 0) { print ('FizzBuzz'); }
else if (c % 5 == 0) { print ('Buzz'); }
else if (c % 3 == 0) { print('Fizz'); }
else { print(c); }
}
void fbFlow(c) {
@tstone
tstone / imgtohtml.py
Created November 18, 2010 14:19
Convert any PNG into a pure HTML representation (A grid of 1px by 1px tags)
#!/usr/bin/env python
#
# Converts any PNG into pure HTML
#
import png, array
reader = png.Reader(filename='wedding.png') # << -- enter the image path here
width, height, pixels, metadata = reader.read()
Version = 4
Booleans = {'caretLineVisible': False, 'preferFixed': 1, 'useSelFore': True}
CommonStyles = {'attribute name': {'fore': 7872391},
'attribute value': {'fore': 3100463},
'bracebad': {'back': 9117943, 'bold': 1, 'fore': 16777215},
'bracehighlight': {'bold': 1, 'fore': 16777215},
'classes': {'bold': True, 'fore': 9117943},
'comments': {'fore': 2696233, 'italic': 1},
import scala.io.Source
if (args.length > 0) {
def formatSourcePrefix(line: Int, suffix: String, max: Int = 5): String = {
var prefix: String = ""
for (i <- 1 to (max - line.toString.length))
prefix += " "
prefix + line.toString + suffix
}
import datetime
import json
import urllib2
import time
LAST_DAY = datetime.datetime(2010, 6, 30)
TODAY = datetime.datetime.now()
CALENDAR_API_URL = 'http://www.hanalani.org/api/calevents/range.json?cal=all-school-calendar'
from django.db import models
from django.shortcuts import _get_queryset
class ChildAwareModel(models.Model):
class Meta:
abstract = True
def get_child_model(self):
"""
Attempts to determine if an inherited model record exists.
import os
import sys
from dirsearch import DirSearch
# Global variables
PREFIX = ''
#
# Print the basic help to the screen
#
# A python module to implement recursive search/copy of files
#
import datetime
import shutil
import os
import re
class DirSearch(object):