Skip to content

Instantly share code, notes, and snippets.

View terryjbates's full-sized avatar

Terry Bates terryjbates

View GitHub Profile
@terryjbates
terryjbates / random-proust
Created August 21, 2014 20:43
Random text based on Markov analysis of Proust text
de Charlus would be the answer, for Françoise, since at Combray (because on those first evenings when I recalled, later, what I was dismayed not to know what I had not stirred from its window. When a man of the keenest sorrow. So much so that they were necessarily much simplified; doubtless the very depths of my impression, that something more immediate, something, possibly, which had not seen him in the front of me, really, don't you know, as she did not know, the little town in Italy, since I did not know my name, and as though he knew
@terryjbates
terryjbates / introrx.md
Last active August 29, 2015 14:28 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@terryjbates
terryjbates / selenium-yahoo-test.py
Created August 16, 2012 02:23
Rudimentary Python script that demos how selenium can do stuff
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.keys import Keys
import time
#browser = webdriver.Firefox() # Get local session of firefox
browser = webdriver.Chrome() # Get local session of firefox
browser.get("http://www.yahoo.com") # Load page
assert "Yahoo!" in browser.title
@terryjbates
terryjbates / txt2dbm.pl
Created September 27, 2012 02:58
Perl program to generate a .dbm file given a .txt file to be used by RewriteMap directive. Faster!
#!/usr/bin/perl -w
##
## txt2dbm -- convert txt map to dbm format
##
use SDBM_File;
use Fcntl;
($txtmap, $dbmmap) = @ARGV;
@terryjbates
terryjbates / dbm_generate.py
Created September 28, 2012 19:45
Python program to generate .dbm file for use with Apache RewriteMap
#!/usr/bin/env python
#
# dbm_generate.py
'''Script to generate a .dbm file able to be used by Apache RewriteMap directive. Point it to the text file that contains the key/value pairs. This file must contain no empty lines, nor comments (though the code below should avoid that).
It may also be possible to use this file as a template to read any current .dbm files and make mods, versus generating anew each time.
'''
import dbm
@terryjbates
terryjbates / yahoo-api-caching.py
Created October 6, 2012 04:44
Yahoo Python API caching example
import time, urllib
class CacheFetcher:
def __init__(self):
self.cache = {}
def fetch(self, url, max_age=0):
if self.cache.has_key(url):
if int(time.time()) - self.cache[url][0] < max_age:
return self.cache[url][1]
# Retrieve and cache
@terryjbates
terryjbates / gist:3846434
Created October 6, 2012 22:57
Processing Tutorial at VIA-PGH
int xPos = 10;
int yPos = 10;
void setup() {
size(400,400);
// background(100,50,100);
}
@terryjbates
terryjbates / popen-example.py
Created November 29, 2012 01:21
Python code snippet with processing of stdout output gotten from Popen
#!/usr/bin/env python
import subprocess
p = subprocess.Popen(["/bin/ls", "-l"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
for line in p.stdout:
print line.strip()
for output in file.stdout.readlines():
if "FontCache" in output:
@terryjbates
terryjbates / tmux.conf
Last active October 31, 2015 19:49
tmux.conf config to be shared from the PragPub book
# Change the Prefix key to Ctrl-a and not Ctrl-b
set -g prefix C-a
unbind C-b
# Change default delay
set -s escape-time 1
# Set pane and reference window indexing to 1
set -g base-index 1
setw -g pane-base-index 1
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])