Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / craigmailer.php
Created January 7, 2012 09:15
Script to email all Craigslist posts from given categories to you from the authors emails, so you can simply reply to the ones that interest you.
<?php // CraigMailer
$to_email = '[email protected]'; // the email all postings should be sent to
$sqlite_file = 'craigmailer.sqlite'; // sqlite file location
$city = 'orlando'; // city to watch (as per cl subdomain)
$topics = array('cpg','sad','web','sof','eng'); // topics (three char topics as used in cl urls)
$handle = sqlite_open($sqlite_file, 0666, $sqlite_error) or die("Could not open database");
$query = sqlite_query($handle,"SELECT name FROM sqlite_master WHERE type='table'");
if (!sqlite_fetch_array($query)){
sqlite_query($handle,"CREATE TABLE posts (id INTEGER(15) PRIMARY KEY NOT NULL,timestamp DATETIME NOT NULL,topic CHAR(4) NOT NULL, subject CHAR(255) NOT NULL, email CHAR(255) NOT NULL, body TEXT, mail_sent INTEGER(1) DEFAULT 0 NOT NULL);")
@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 <[email protected]>
* Demo: http://tobi.oetiker.ch/photo/
* $Id: jquery.EmbedPicasaGallery.js 474 2011-06-16 09:02:45Z oetiker $
**************************************************************************
Description:
[elided]
@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 / 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 / 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 / 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 / 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',
# 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