Skip to content

Instantly share code, notes, and snippets.

@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',
@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 / 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 / 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 / results.py
Created June 22, 2011 18:03 — forked from ask/get_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().join()
results = []
for query_proc in query_procs:
# while the following iterate() is happening, the other query_procs are ignored.
# ideas on iterating over all of them at once?
for result in query_proc.iterate():
yield result
@lrvick
lrvick / get_results.py
Created June 22, 2011 17:02
Get async celery results from subtasks
from celery.result import AsyncResult
from celery.execute import send_task
def get_results(queries):
result = send_task('task1',queries)
results = result.get()
#this does not return ids until _after_ all the tasks are complete, for some reason.
while results:
#pop first off queue, this will shorten the list and eventually break out of while
first_id = results.pop(0)
@lrvick
lrvick / collect.py
Created May 10, 2011 20:07
Twitter / Facebook Data dumper
import urllib2
import json
import sys
import os
import re
import time
import rfc822
import sqlite3
import datetime
@lrvick
lrvick / notification.confirm.md
Created May 4, 2011 20:04 — forked from mwbrooks/notification.confirm.md
Markdown code block within list item

foo

  1. index is the 0 based index value of the button pressed

  2. label is the text label of the button pressed

         function showConfirm() {
             var confirmDelegate = navigator.notification.confirm(
                 'You are the winner!',  // message
    

'Game Over', // title

@lrvick
lrvick / rgbint.py
Created March 20, 2011 07:42
Go from rgb to 32bit int or vice-versa
#!/bin/python
import random
def rgb_to_int(r,g,b):
i = str()
for c in r,g,b:
for d in str("%03d" % (c,)):
i += '%s%s%s' % (d,d,d)
return i
@lrvick
lrvick / progress_indicator.py
Created March 16, 2011 16:40
Python console progress indicator snippet
import time,sys
total_loops = 500;
complete_loops = 0;
while (complete_loops < total_loops):
percent = int(complete_loops*100/total_loops)
time.sleep(1)
complete_loops +=1