Skip to content

Instantly share code, notes, and snippets.

@colinpollock
colinpollock / Sal.scala
Created March 7, 2012 07:15
Causing a ClassCastException by trying to deserialize a Map[String, Seq[String]]
package com.salattest
import com.mongodb.casbah.Imports._
import com.novus.salat._
import com.novus.salat.global._
import com.novus.salat.dao._
case class Data (
_id: String,
@colinpollock
colinpollock / Friday_Shots.md
Created March 23, 2012 18:35
Rules and regulations for Friday Shots

Friday Shots

Rules

  1. The competition begins every Friday promptly at beer o'clock (once at least one person has opened a beer and it is 4:00pm or later).
  2. Anyone in the office at the time of the competition can participate.
  3. No practice shots can be taken once the competition begins.
  4. Each participant gets to take one shot after paying the $1 entry fee. All fees must be paid
    prior to the first shot.
class Person(val name: String) {
def greeting = "I am Person %s".format(name)
override def equals(that: Any): Boolean = that match {
case p: Person if p.name == this.name => true
case _ => false
}
override def hashCode = 11
}
{
"rankerType": "naiveranker",
"retrieverType": "mongokeywordindexretriever",
"useTfIdf": true,
"concurrent": true,
"persistResults": false,
"targetCorpusTags": [
"wordpress.com",
"wordpress.org"
class Node(object):
def __init__(self, data):
self.data = data
self.next_node = None
def __repr__(self):
return self.data
class List(object):
"""
@colinpollock
colinpollock / gist:3262624
Created August 5, 2012 07:28
Tastypie: model and resource for Player
class Player(models.Model):
name = models.CharField(primary_key=True, max_length=50)
date_added = models.DateTimeField('date added', default=datetime.now())
rating = models.IntegerField(default=1600)
@property
def wins(self):
return self.winner_games.all()
@colinpollock
colinpollock / fut.py
Created August 31, 2012 17:52
python3.2 futures
#!/usr/bin/env python3.2
from concurrent.futures import ThreadPoolExecutor
from itertools import chain
import time
import requests
def ngrams(tokens, n):
@colinpollock
colinpollock / graph.json
Created September 8, 2012 21:59
Sample graph data for ladder visualization
{
"nodes": [
{"player": "Andy", "rating": 1640},
{"player": "Bob", "rating": 1570},
{"player": "Carmen", "rating": 1590}
],
"edges": [
{"p1": "Bob", "p2": "Andy", "difference": 50},
{"p1": "Carmen", "p2": "Bob", "difference": 20},
@colinpollock
colinpollock / gist:3711345
Created September 13, 2012 01:50
stupid hashmap
import collection.mutable
case class Pair[A, B](key: A, value: B)
class HMap[K, V](numBuckets: Int) {
val buckets = Seq.fill(numBuckets)(mutable.ListBuffer.empty[Pair[K, V]])
def get(k: K): Option[V] =
@colinpollock
colinpollock / fridayshots.py
Created September 21, 2012 23:30
Code for running Friday Shots and persisting winner/loser results
from datetime import datetime
import json
import random
import sys
names = list(set(sys.argv[1:]))
print 'There are %d players: %s' % (len(names), ', '.join(sorted(names)))
raw_input('Continue?')