Skip to content

Instantly share code, notes, and snippets.

View tcr's full-sized avatar
🚮
bad command or file name

Tim Ryan tcr

🚮
bad command or file name
View GitHub Profile
@tcr
tcr / gist:4416956
Last active November 29, 2017 03:38
Make a callable() object in all browsers and Node.js
if (!Object.__proto__) {
var sandbox = function () {
// create an <iframe>
var iframe = document.createElement("iframe");
iframe.style.display = "none";
document.documentElement.appendChild(iframe);
return frames[frames.length - 1];
}
var iframe = sandbox();
@tcr
tcr / gist:4409353
Created December 29, 2012 21:02
Script to convert HTML page with d3 to HTML page with PNGs
var fs = require('fs');
var jsdom = require('jsdom');
function svgToPng (xml, out) {
var convert = require('child_process').spawn("convert", ["svg:", "png:-"]);
convert.stdout.pipe(out);
convert.stdin.write(xml);
convert.stdin.end();
}
@tcr
tcr / rem.txt
Created December 23, 2012 22:59
A Gist created with Rem. http://github.com/tcr/rem-js
A successful OAuth 2 test!
@tcr
tcr / code.sh
Created December 13, 2012 23:29
How do you use Python 2.7 and Passenger on Dreamhost?
read -p "Domain name: " site
mkdir ~/$site/tmp
touch ~/$site/tmp/restart.txt
cat <<_DOC_
import sys, os
INTERP = "/home/`whoami`/Python27/bin/python"
if sys.executable != INTERP:
os.execl(INTERP, INTERP, *sys.argv)
sys.path.append('/home/`whoami`/$site/app')
from app import app as application
@tcr
tcr / code.py
Created December 4, 2012 21:01
How do you connect to a mongodb: URL using PyMongo?
# Mongo URL.
MONGO_URL = os.getenv('MONGOLAB_URI', 'mongodb://localhost:27017/mytable')
# MongoDB setup.
from urlparse import urlsplit
parsed_mongo = urlsplit(MONGO_URL)
db_name = parsed_mongo.path[1:]
# Get db connection.
print('Connecting to %s [db %s]' % (MONGO_URL, db_name))
db = Connection(MONGO_URL)[db_name]
@tcr
tcr / auth.js
Created December 4, 2012 20:08
Authenticating Rem with existing oauth access token/secret
var rem = require('rem');
var twitter = rem.load('twitter', '1.1', {
key: '...',
secret: '...'
});
rem.oauth(twitter, 'http://localhost/').loadState({
oauthAccessToken: '...',
oauthAccessSecret: '...'
@tcr
tcr / code.sh
Created December 4, 2012 05:01
How do you install Python 2.7 on Dreamhost?
read -p "Domain name: " site
cd ~
mkdir ~/tmp
cd ~/tmp
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz
tar zxvf Python-2.7.3.tgz
cd Python-2.7.3
./configure --prefix=$HOME/Python27
make
make install
@tcr
tcr / code.sh
Created December 3, 2012 04:01
How do you connect to a Wifi network from the command line in Ubuntu?
sudo /usr/share/checkbox/scripts/create_connection -S wpa -K THE_PASSWORD NETWORK_NAME
@tcr
tcr / summary.md
Created October 25, 2012 16:03
Why am I getting a 404 error when POSTing to https://api.github.com/gists?

One possibility: you must set the "gist" scope parameter when authenticating the user.

@tcr
tcr / summary.md
Created October 25, 2012 15:56
How do you use a different DNS entry per domain name in OS X?

Use /etc/resolver. For instance, to change the DNS servers for irc.freenode.net, create the file

/etc/resolver/irc.freenode.net

And set its contents to

nameserver 8.8.8.8

nameserver 8.8.4.4