Skip to content

Instantly share code, notes, and snippets.

View ithinkihaveacat's full-sized avatar

Michael Stillwell ithinkihaveacat

View GitHub Profile
/*
// Generate in Firefox with:
function externs(obj) {
var e = { };
for (p in obj) {
if (!p.match(/^_/) && (p != "listenersByObjId")) {
if (typeof obj[p] == 'object') {
e[p] = externs(obj[p]);
[root@pal iplayer-utils]# cat glow2.js
Glow.versions = [4,5,6];
Glow.showVersions();
[root@pal iplayer-utils]# java -jar lib/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --formatting PRETTY_PRINT --js glow2.js
Glow.b = [4, 5, 6];
Glow.a();
[root@pal iplayer-utils]# cat e.js
var Glow = { versions: null, showVersions: null };
[root@pal iplayer-utils]# java -jar lib/compiler.jar --compilation_level ADVANCED_OPTIMIZATIONS --externs e.js --formatting PRETTY_PRINT --js glow2.js
Glow.versions = [4, 5, 6];
<?php
/**
* Work-around fix for 'Include in Navigation Menu'
*
* Currently the promotion script can be run in 2 ways:
* 1) Via command-line: this only happens at initial installation (e.g. install.sh)
* 2) Via cURL: this happens in all other cases (e.g. newer Setup module version)
*
* @param array $resaveCategories
<html>
<head>
</head>
<body>
<script>
function jjjjj(arg) {
var post = arg.posts[0];
console.log(post);
document.write(post["regular-body"]);
}
var http = require('http');
var url = require('url');
http.createServer(function (req1, res1) {
var tmp = url.parse(req1.url);
var options = {
"host": tmp.hostname,
"port": tmp.port || 80,
"path": tmp.pathname + (tmp.search ? tmp.search : ''),
"method": req1.method,
import SocketServer
import SimpleHTTPServer
import urllib
PORT = 8080
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
# Do not name this twisted.py or Python's loader will get
# confused!
from twisted.web import proxy, http
from twisted.internet import reactor
from twisted.python import log
import sys
# log.startLogging(sys.stdout)
@ithinkihaveacat
ithinkihaveacat / sync-and-async-map.js
Last active September 25, 2015 02:17
Map an array, where the map function, and the result of the map, are asynchronous.
// SYNCHRONOUS MAP
function smap(src, fn) {
if (src.length == 0) {
return [];
} else {
return [fn(src[0])].concat(smap(src.slice(1), fn));
}
}
@ithinkihaveacat
ithinkihaveacat / uncaught-exception.js
Created March 10, 2011 23:28
Throws exception--agent has sockets, but nothing in the queue
var http = require('http');
var options = {
host: 'pix04.revsci.net',
port: 80,
path: '/H07707/b3/0/3/0806180/551104974.js?D=DM_LOC%3Dhttp%253A%252F%252Fwww.nytimes.com%252F2011%252F03%252F11%252Fworld%252Fafrica%252F11policy.html%253F_r%253D2%2526hp%26DM_CAT%3DNYTimesglobal%2520%253E%2520World%2520%253E%2520Africa%26DM_REF%3Dhttp%253A%252F%252Fwww.nytimes.com%252F2011%252F03%252F11%252Fworld%252Fafrica%252F11policy.html%253F_r%253D2%2526hp%26DM_EOM%3D1&C=H07707',
headers: { host: 'pix04.revsci.net',
'user-agent': 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
accept: '*/*',
'accept-language': 'en-us,en;q=0.5',
From 4d80c2dc876e7bffde2b23825587518c4bd7b678 Mon Sep 17 00:00:00 2001
From: Michael Stillwell <mjs@beebo.org>
Date: Thu, 10 Mar 2011 23:23:12 +0000
Subject: [PATCH] Only emit error on request if request can be found.
If the socket receives a "ECONNRESET, Connection reset by peer" error, the http error handler tries to find the associated request from the request queue. However at this point in time, all requests may have been satisfied (e.g. by other sockets) and the queue empty.
---
lib/http.js | 15 +++------------
1 files changed, 3 insertions(+), 12 deletions(-)