Skip to content

Instantly share code, notes, and snippets.

@lrvick
lrvick / bathroom-lock.ino
Created March 26, 2015 20:00
Arduino Bathroom Lock State Server
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xCA, 0xFE };
EthernetServer server(80);
const int lockPin = 2;
const int ledPin = 13;
@lrvick
lrvick / load-avg.sh
Created April 1, 2015 22:40
Simple siege runner to test multiple steps of workers and log results for quick comparison.
#!/bin/bash
URL=$1
LOG_FILE=$2
WORKER_STEPS=( 10 100 200 500 1000 1500 )
DELAY=10
TEST_LENGTH=60s
for WORKERS in "${WORKER_STEPS[@]}"; do
@lrvick
lrvick / kralr.py
Created November 24, 2010 18:27
Tasks to support Twitter 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 February 23, 2011 01:09
Extract html <title> from url and universally return as unicode
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
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']
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 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
@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 / 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',