Skip to content

Instantly share code, notes, and snippets.

@lrvick
lrvick / results.py
Created June 23, 2011 03:45 — forked from tsoporan/results.py
Get async celery results from nested subtasks as they complete
from tasks import task1
def get_results(queries):
query_procs = task1.delay(queries).get()
tasks = []
for query_proc in query_procs:
tasks.extend(query_proc.subtasks)
while tasks:
current_task = tasks.pop(0)
@lrvick
lrvick / flask_geventwebsocket_example.py
Created September 1, 2011 07:17
Simple Websocket echo client/server with Flask and gevent / gevent-websocket
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template('index.html')
@lrvick
lrvick / sqlite3_import.py
Created September 20, 2011 18:17
Import remote gzipped Sqlite3 SQL file as local sqlite3 database
#The goal is to emulate the following bash line properly in python:
#wget -O - "https://github.com/downloads/Tawlk/synt/sample_data.bz2" | bzcat | sqlite3 sample_data.db
import bz2
import sqlite3
import time
import urllib2
import os
from cStringIO import StringIO
@lrvick
lrvick / manual_nltk_bayes_classify.py
Created October 6, 2011 03:04
Manually train an NLTK NaiveBayes Classifier
from nltk.probability import DictionaryProbDist
from nltk import NaiveBayesClassifier
train_samples = {
'I hate you and you are a bad person': 'neg',
'I love you and you are a good person': 'pos',
'I fail at everything and I want to kill people' : 'neg',
'I win at everything and I want to love people' : 'pos',
'sad are things are heppening. fml' : 'neg',
'good are things are heppening. gbu' : 'pos',
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@lrvick
lrvick / manual_nltk_bayes_classify.py
Created October 6, 2011 04:06 — forked from tsoporan/manual_nltk_bayes_classify.py
Manually train an NLTK NaiveBayes Classifier
from nltk.probability import DictionaryProbDist
from nltk import NaiveBayesClassifier
from nltk import FreqDist
train_samples = {
'I hate you and you are a bad person': 'neg',
'I love you and you are a good person': 'pos',
'I fail at everything and I want to kill people' : 'neg',
'I win at everything and I want to love people' : 'pos',
'sad are things are heppening. fml' : 'neg',
@lrvick
lrvick / manual_nltk_bayes_classify.py
Created October 6, 2011 04:59 — forked from tsoporan/manual_nltk_bayes_classify.py
Manually train an NLTK NaiveBayes Classifier
from nltk.probability import ELEProbDist, FreqDist
from nltk import NaiveBayesClassifier
from collections import defaultdict
train_samples = {
'I hate you and you are a bad person': 'neg',
'I love you and you are a good person': 'pos',
'I fail at everything and I want to kill people' : 'neg',
'I win at everything and I want to love people' : 'pos',
'sad are things are heppening. fml' : 'neg',
@lrvick
lrvick / PonyWeb.pde
Created October 7, 2011 08:31
Simple Arduino Webserver With Hits/IP on LCD & DHCP
#include <Wire.h>
#include <LiquidCrystal.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE };
EthernetServer server(80);
LiquidCrystal lcd(0);
@lrvick
lrvick / subsetsum.js
Created November 20, 2011 22:43
Subset-Sum Solution in javascript
var subset_sum = function(items, target) {
var perms = [], layer = 0, depth = 4, attempts = 0, sum, perm,
ss = function(items) {
var item = items.shift();
for (i = 0; i < items.length; i++) {
attempts = attempts + 1;
if (attempts <= items.length * items.length) {
if (layer === 0) {
perm = [items[0], items[i]];
} else {
@lrvick
lrvick / pologen.php
Created December 31, 2011 07:35
Convincing Random Polaroids with iMagick
<?php
$mime_type = "image/png" ; // mime type of file to pretend to be
$compression = "95" ; // compression
$trimming = "yes" ; // trim canvas after rendering, yes or no
$canvas_height = "800" ; // height of entire canvas
$canvas_width = "800" ; // width of entire canvas
$shadow_color = "black" ; // color of drop shadow
$size[0] = "140" ; // size in pixils for top image
$size[1] = "120" ; // size in pixils for middle image
$size[2] = "100`" ; // size in pixils for bottom image