Skip to content

Instantly share code, notes, and snippets.

# 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 / 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 / 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
@lrvick
lrvick / jQuery.EmbedPicasaGallery.js
Created January 3, 2012 05:51 — forked from mwolfetech/jQuery.EmbedPicasaGallery.js
Adjustment to EmbedPicasaGallery to pass album description, photo count, and title back to user provided callback functions.
/**************************************************************************
* Name: EmbedPicasaGallery
* Author: Tobias Oetiker <tobi@oetiker.ch>
* Demo: http://tobi.oetiker.ch/photo/
* $Id: jquery.EmbedPicasaGallery.js 474 2011-06-16 09:02:45Z oetiker $
**************************************************************************
Description:
[elided]
@lrvick
lrvick / whitepagecarriers.sh
Created January 7, 2012 09:19
Bash script to harvest all public cell-phone number -> carrier mappings from whitepages.com
#!/bin/bash
for NPA in {201..989}; do
NXXX=2000
while [ ${NXXX} -lt 9999 ]; do
NXXX1=$[$NXXX+1]
NXXX2=$[$NXXX+2]
NXXX3=$[$NXXX+3]
echo "Checking ${NPA}${NXXX}XXX, ${NPA}${NXXX1}XXX,
${NPA}${NXXX2}XXX, ${NPA}${NXXX3}XXX..."
URL="http://www.whitepages.com/carrier_lookup?carrier=alltel&name;_0=&number;_0=${NPA}${NXXX}000&name;_1=&number;_1=${NPA}${NXXX1}000&name;_2=&number;_2=${NPA}${NXXX2}000&name;_3=&number;_3=${NPA}${NXXX3}000&localtime;=survey"
@lrvick
lrvick / hnscrape.py
Created March 1, 2012 03:54
Scrapy spider to output hackernews titles
from scrapy.http import Request
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
class HackernewsSpider(BaseSpider):
name = 'hackernews'
allowed_domains = []
start_urls = ['http://news.ycombinator.com']
def parse(self, response):
if 'news.ycombinator.com' in response.url:
@lrvick
lrvick / loadtest.py
Created March 27, 2012 07:31
Simple 1000 thread web server load test using eventlet
import eventlet
from eventlet.green import urllib2
def request():
urllib2.urlopen("http://yourtarget.com").read()
print "%s request sent"
pool = eventlet.GreenPool(size=1000)
while True:
@lrvick
lrvick / github_flask.py
Created April 26, 2012 06:47
Github API access with Flask and rauth
from flask import Flask, request, redirect, url_for
from rauth.service import OAuth1Service, OAuth2Service
github = OAuth2Service(
name='github',
consumer_key='GITHUB_CONSUMER_KEY',
consumer_secret='GITHUB_CONSUMER_SECRET',
access_token_url='https://github.com/login/oauth/access_token',
authorize_url='https://github.com/login/oauth/authorize',
)
@lrvick
lrvick / q3lcd.py
Created July 7, 2012 11:35
Quake3 logger for the raspberry pi that outputs to an attached HD44780 LCD using my library for it
from hd44780 import HD44780
from os import stat
from time import sleep
lcd = HD44780()
lcd.message(" Quake3 Logger\nCommence killing...")
logfile_name = 'game.log'