Skip to content

Instantly share code, notes, and snippets.

Avatar

Lance R. Vick lrvick

View GitHub Profile
@lrvick
lrvick / kralr.py
Created Nov 24, 2010
Tasks to support Twitter kralr.py
View kralr.py
import httplib,pycurl,json
from django.conf import settings
from tasks import ProcessTweet
QUERY="android"
class Twitter():
default_retry_delay = 5
def run(self,query):
self.buffer = ""
@lrvick
lrvick / utf8-webtitles.py
Created Feb 23, 2011
Extract html <title> from url and universally return as unicode
View utf8-webtitles.py
import urllib2,httplib,re
def url_title(url,**kwargs):
title = None
request = urllib2.Request(url)
try:
response = urllib2.urlopen(request)
data = response.read()
except urllib2.HTTPError:
data = None
View twitter_sentiment.py
import urllib2, json, base64, sys, termios, tty, os
USER = "your_twitter_user"
PASS = "your_twitter_pass"
neg_filename = "negative.txt"
pos_filename = "postive.txt"
queries = ['awesome','beautiful','shit','fuck','android','iphone','blackberry','windows','linux','apple','google']
View twitter_sentiment.py
USER = "your_twitter_user"
PASS = "your_twitter_pass"
if "your_twitter" in USER+PASS:
print "You didn't set your twitter username and password in the script!"
USER = raw_input("Username>")
PASS = raw_input("Password>")
import urllib2, json, base64, sys, os
@lrvick
lrvick / progress_indicator.py
Created Mar 16, 2011
Python console progress indicator snippet
View progress_indicator.py
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
@lrvick
lrvick / rgbint.py
Created Mar 20, 2011
Go from rgb to 32bit int or vice-versa
View rgbint.py
#!/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 / notification.confirm.md
Created May 4, 2011 — forked from mwbrooks/notification.confirm.md
Markdown code block within list item
View notification.confirm.md

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 / collect.py
Created May 10, 2011
Twitter / Facebook Data dumper
View collect.py
import urllib2
import json
import sys
import os
import re
import time
import rfc822
import sqlite3
import datetime
@lrvick
lrvick / get_results.py
Created Jun 22, 2011
Get async celery results from subtasks
View get_results.py
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 / results.py
Created Jun 22, 2011 — forked from ask/get_results.py
Get async celery results from nested subtasks as they complete
View results.py
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
You can’t perform that action at this time.