Skip to content

Instantly share code, notes, and snippets.

@spence
spence / gist:4176224
Created November 30, 2012 14:54
Bookmarklet: Enable Autocomplete
<!DOCTYPE html>
<html>
<head><title>Bookmarklet: Auto Complete</title></head>
<body>
<a href="javascript:(function()%7Bfor(var%20b=Array.prototype,a=b.concat.apply(b.slice.call(document.getElementsByTagName(%22form%22),0),document.getElementsByTagName(%22input%22)),i=0;a.length%3Ei;i++)a%5Bi%5D.setAttribute(%22autocomplete%22,%22on%22);%7D)()">Enable Autocomplete</a>
</body>
</html>
@spence
spence / fetchip-gasmask-hosts.sh
Last active December 24, 2015 07:39
CRON to resolve and update the IP addresses used throughout the Gasmask *.hst config files. Tested only on OSX 10.8.3 with Gasmask 0.7.
#!/bin/bash
# Job for automatically resolving and updating GasMask host file entries.
#
# Spencer Creasey (github.com/spence)
#
# Gasmask: http://www.clockwise.ee/gasmask/
#
# To use, on the line before your host entry, add:
#
@spence
spence / enableautocomplete.js
Created April 8, 2014 15:32
Enable Autocomplete for sites that disable it (bookmarklet)
var forms = document.getElementsByTagName("form");
var inputs = document.getElementsByTagName("input");
var fields = Array.prototype.concat.apply(Array.prototype.slice.call(forms, 0), inputs);
for (var i = 0; i < fields.length; i++) {
fields[i].setAttribute("autocomplete", "on");
fields[i].onpaste = null;
if (window.jQuery) {
window.jQuery(fields[i]).unbind("paste");
}
}
@spence
spence / phantomjs-repl.sh
Last active August 29, 2015 14:19
Bash PhantomJS REPL modeled after https://github.com/sotownsend/BooJS
#!/usr/bin/env bash
### Repl Usage:
#
# $ ./phantomjs-repl.sh
# > missing
# ReferenceError: Can't find variable: missing
# > window
# [object Window]
# > console.log('Hello')
def get_products_of_all_ints_except_at_index(int_array):
"""
Single pass.
"""
# Condition where element has neither left nor right elements
if len(int_array) == 1:
# Maybe [None] ?
return [0]
@spence
spence / find_anagrams.py
Created May 17, 2015 14:17
Given a string of words, find all those that are anagrams.
def find_anagrams(words):
"""
Find anagrams in O(n*m) time and O(n) space.
Notes: returns all words in input that are anagrams of another word.
"""
anagrams = []
sorted_words = {}
for word in words: # O(n)
@spence
spence / skype-link.html
Created May 29, 2015 17:55
Create a emailable link to a Skype profile (since skype has no web profiles and gmail blocks direct application links). e.g., http://static.spencercreasey.com/skype-profile.html
@spence
spence / run.py
Last active August 29, 2015 14:22
Failing issue with geventwebsocket + newrelic instrumentation. run via `chmod +x run.py && ./run.py` and navigate to http://localhost:9191. After the first websocket connection, no more connections are allowed. Commenting out NR instrumentation restores expected behavior.
#!/usr/bin/env python2.7
# pip install newrelic gevent gevent-websocket flask
# my versions: (2.50.0.39) (1.0.2) (0.9.3) (0.10.1)
import newrelic.agent
from geventwebsocket.handler import WebSocketHandler
from gevent.pywsgi import WSGIServer
from flask import Flask, request
# Flask app

Keybase proof

I hereby claim:

  • I am spence on github.
  • I am spence (https://keybase.io/spence) on keybase.
  • I have a public key whose fingerprint is 9C16 5E92 0DF1 FA53 B80E AFCB CF19 C3ED D6C4 63B6

To claim this, I am signing this object:

DO
$do$
DECLARE
i INT;
BEGIN
FOR i IN 1..1000000 LOOP
SELECT LEFT(('x' || RIGHT(gen_random_bytes(3)::TEXT, 6))::BIT(24)::INT::TEXT, 4)::INT INTO i;
RAISE NOTICE '%', i;
END LOOP;
END