This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* For Node.js - deal with some of the boilerplate involved in HTTP GET requests */ | |
| var http = require('http'), | |
| urlmod = require('url'); | |
| function getResponse(url, callback) { | |
| var parsed = urlmod.parse(url); | |
| var port = parseInt(parsed.port || '80', 10); | |
| var client = http.createClient(port, parsed.hostname); | |
| var path = parsed.pathname; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* For Node.js - resolve a chain of HTTP redirects | |
| Uses getResponse() from http://gist.github.com/399276 | |
| Example: resolveHttpRedirects('http://ow.ly/1Kn4j', function(url) { sys.puts(url) }); | |
| */ | |
| function resolveHttpRedirects(url, callback, maxnum) { | |
| maxnum = maxnum || 3; | |
| var count = 0; | |
| function next(url) { | |
| getResponse(url, function(response) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import django | |
| from django.template import Template, Context | |
| template_string = """ | |
| The answer to the Ultimate | |
| Question is {{ everything.universe.answer }}. | |
| Among our weapons are: | |
| {% for weapon in weapons %} | |
| {{ weapon }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Smokescreen v0.1.2 - Chris Smoak <chris.smoak@gmail.com> | |
| * A Flash player written in JavaScript. | |
| * | |
| * Copyright 2010, RevShock | |
| * | |
| * Date: 2010-05-27 | |
| */ | |
| var Smokescreen = function(url, element, width, height, name, params) { | |
| goog = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Multiget web service, written in Node | |
| http://127.0.0.1:9001/?urls=http://example.com/,http://example.net/ | |
| Will fetch all URLs in parallel, then return a JSON response containing | |
| the fetched content from them. | |
| */ | |
| var DEFAULT_TIMEOUT = 10000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Evil script for exporting LinkedIn contacts along with their locations. | |
| Navigate to http://www.linkedin.com/connections?trk=hb_tab_cnts and | |
| click on the "Locations" accordion button, then paste the following | |
| script in to the Google Chrome JavaScript console (untested in anything | |
| else). After quite a while a popup with some JSON will appear. */ | |
| function fakeClick(el) { | |
| var e = document.createEvent('MouseEvents'); | |
| e.initEvent('click', true, true); | |
| el.dispatchEvent(e); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import httplib, urlparse, socket | |
| def http_get_headers_and_truncated_body( | |
| url, max_redirects=5, body_length=2048, timeout=5, | |
| allowed_content_types = ('text/html',), num_redirects_followed=0, | |
| redirect_chain = None | |
| ): | |
| redirect_chain = redirect_chain or [] | |
| # Returns {'ok':True,'headers':{},'redirected':False,'url':'','body': '', | |
| # 'max_redirects_reached': False, 'num_redirects_followed': 0, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wget http://mirrors.kernel.org/ubuntu/pool/universe/r/redis/redis-server_2.0.0~rc2-1_i386.deb | |
| sudo dpkg -i redis-server_2.0.0~rc2-1_i386.deb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Here's how to run a command from Python piping a string in to stdin and reading the | |
| output back in to another string. It took me way too long to work this out. | |
| """ | |
| from subprocess import Popen, PIPE | |
| output = Popen( | |
| ['java', '-jar', 'yuicompressor-2.4.2.jar', '--type=css'], | |
| stdin=PIPE, stdout=PIPE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Inspired by Python's useful re.findall method */ | |
| function findall(regex, str) { | |
| var matches = [], m; | |
| regex.lastIndex = 0; | |
| while (m = regex.exec(str, regex.lastIndex)) { | |
| matches[matches.length] = m; | |
| } | |
| return matches; | |
| } |