Skip to content

Instantly share code, notes, and snippets.

View ranman's full-sized avatar
🏠
Working from home

Randall Hunt ranman

🏠
Working from home
View GitHub Profile
@ranman
ranman / gist:1087135
Created July 17, 2011 03:43
Idea for constantly updating dict
from multiprocessing import Process, Lock
class ConstantlyUpdatingDict(dict):
updater #= Process(target=update_dict, args=(self, self.data_lock))
data_lock #=
def __init__(self, *args):
dict.__init__(self,*args,**kwargs)
self.updater.start()
def __setitem__(self, key, val):
data_lock.acquire()
@ranman
ranman / gist:1094395
Created July 20, 2011 05:29
calc sims
venues = []
others = []
sims = []
dictVenues = VenueToVenue.transformDict(user_ratings)
for venueID in dictVenues.keys():
for otherID in dictVenues.keys():
if otherID == venueID:
sim = 0
else:
sim = dist_metric(dictVenues[venueID], dictVenues[otherID])
@ranman
ranman / gist:1094400
Created July 20, 2011 05:30
constantly updating dict
from multiprocessing import Process, Lock, Manager
from time import sleep
def update_dict(cls, db, lock):
temp_db = {}
while True:
lock.acquire()
try:
temp_db['userRatings'] = db['userRatings'] + 1
temp_db['venueToVenue'] = db['venueToVenue'] +1
irb(main):001:0> a
NameError: undefined local variable or method `a' for main:Object
from (irb):1
irb(main):002:0> b
NameError: undefined local variable or method `b' for main:Object
from (irb):2
irb(main):003:0> a=b
NameError: undefined local variable or method `b' for main:Object
from (irb):3
irb(main):004:0> a=a
@ranman
ranman / apod.py
Created May 19, 2012 05:58
quick script to set twitter bg to astronomy pic of the day
# Copyright 2012 Joseph R. Hunt
# All rights reserved.
# This is just a quick hack and is not reliable
# width 850,315
import re
import urllib
import Image
import cStringIO
@ranman
ranman / Facewall.py
Created May 20, 2012 05:28 — forked from madzen/Facewall.py
Create an image grid from Facebook friend profile pictures
#!/usr/bin/python
###############################################################################
# Produce a collage (grid) of friend profile images from Facebook.
# Inspired by Vipin "swvist" Nair @ https://gist.github.com/2692786
###############################################################################
# Copyright (c) 2012 Madzen
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@ranman
ranman / poormanschef.scpt
Created August 10, 2012 20:52
A poorman's chef
set hostList to {"jsl1", "jsl2", "jsl3", "jsl4", "jsl5", "jsl6", "jsl7", "jsl8"} as list
tell application "iTerm"
activate
set myTerm to (make new terminal)
tell myTerm
repeat with hostItem in hostList
set Lsession to (launch session "Default Session")
tell Lsession
write text "ssh " & hostItem
@ranman
ranman / gist:3760095
Created September 21, 2012 06:58
xgen jira wrapper
import requests
import json
from jira.client import JIRA
from jira.client import raise_on_error
# This class is neccesary because of broken jira-python scripts from Atlassian
class XgenJIRA(JIRA):
@ranman
ranman / awesome.py
Created October 2, 2012 03:21
awesome fizzbuzz
messages = [None, "Fizz", "Buzz", "FizzBuzz"]
acc = 810092048
for i in xrange(1, 101):
c = acc & 3
print messages[c] if c else i
acc = acc >> 2 | c << 28
> db.createCollection("newlogs", {capped: true, size: NumberLong("100000000000")});
{ "ok" : 1 }
> db.newlogs.stats()
{
"ns" : "buildlogs.newlogs",
"count" : 0,
"size" : 0,
"storageSize" : 100000001312,
"numExtents" : 47,
"nindexes" : 1,