Skip to content

Instantly share code, notes, and snippets.

"""
Note: There are several variations to do the same thing (see # or). The idea
is to choose the best (one or so) of the variations and implement that. I.E.
these are different designs possibilities for the API.
"""
"""
Filtering
"""
@tiffon
tiffon / agents.py
Last active January 15, 2017 16:57
A somewhat ghetto, but still handy, utility for getting a random user-agent weighted by their general popularity (circa mid-2014). Useful for web-scraping.
import random
rng = random.SystemRandom()
TOTAL = 77.28
USER_AGENTS = None
def get_agent():
"""
@tiffon
tiffon / stackoverflow.py
Created April 4, 2015 08:39
Beautiful Soup 4 code that scrapes a few questions off stackoverflow.com
#! /usr/bin/env python
import sys
import time
import urllib2
from bs4 import BeautifulSoup
HOMEPAGE_URL = 'http://stackoverflow.com/'
TAG_PAGE_URL = 'http://stackoverflow.com/questions/tagged/web-scraping?sort=newest&pageSize=10'
@tiffon
tiffon / gist:8747582
Created February 1, 2014 03:31
Simulated Annealing algorithm from "Programming Collective Intelligence" by Toby Segaran.
public class SimulatedAnnealing
{
public static final double DEFAULT_TEMPERATURE = 10000;
public static final double DEFAULT_COOL_RATE = 0.95;
static public double[] optimize(double[][] domain, SolutionCost costF, double stepSize)
{
return optimize(domain, costF, DEFAULT_TEMPERATURE, DEFAULT_COOL_RATE, stepSize);
}
@tiffon
tiffon / gist:5881101
Last active December 19, 2015 02:09
vamp
`` 'it' keyword replaces 'this'
`` variable declaration ':='
`` lamda function '-->'
`` within an object literal ':prop = value'
`` loops
`` -----------------------------------------------------------------------------
@tiffon
tiffon / jsToWorker.js
Last active December 10, 2015 02:38
Create a WebWorker from a javascript function. Optionally, supply environment variables. Derived from this jsFiddle: http://jsfiddle.net/YUKSu/7/
var jsToWorker = (function(win) {
var enabled = !!win.Worker,
blobBuilder = win.BlobBuilder || win.WebKitBlobBuilder || win.MozBlobBuilder,
urlFactory = win.URL || win.webkitURL,
stringToBlobUrl;
if (!enabled || !urlFactory || (!win.Blob && !blobBuilder)) {
var noop = function(){};
noop.enabled = false;
@tiffon
tiffon / retina.js
Created December 20, 2012 05:06
Retinajs change to employ localStorage caching of image path results. Original (1st version) downloaded from: https://raw.github.com/imulus/retinajs/5671145d8a8adf3d72b6b62d8927799f8dd97863/src/retina.js
(function() {
var root = (typeof exports == 'undefined' ? window : exports);
var config = {
// Ensure Content-Type is an image before trying to load @2x image
// https://github.com/imulus/retinajs/pull/45)
check_mime_type: true
};
@tiffon
tiffon / Find Results.hidden-tmLanguage
Created December 19, 2012 01:17
Tricked-out Find in Files... results
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Find Results</string>
<key>patterns</key>
<array>
<dict>