Skip to content

Instantly share code, notes, and snippets.

View ithinkihaveacat's full-sized avatar

Michael Stillwell ithinkihaveacat

View GitHub Profile
<?php
// From presentation-layer/application/modules/user/models/Givingpage.php
protected function _setIf($givingPage, $data, $key, $field = null)
{
if ($field === null) {
$field = $key;
}
if (isset($data[$key])) {
@ithinkihaveacat
ithinkihaveacat / bench.php
Created November 7, 2011 23:07
Microbenchmarks of different forms of array access
<?php
// Micro-benchmarks, again, see http://daveyshafik.com/archives/30320-faster-arrays.html
// Results:
//
// regular 1.64
// preallocated 1.42
// fixed 0.81
<?php
function isStringPresent($needle, $haystack)
{
$result = strstr($haystack, $needle);
if ($result == FALSE) {
return FALSE;
} else {
return TRUE;
}
From 4d80c2dc876e7bffde2b23825587518c4bd7b678 Mon Sep 17 00:00:00 2001
From: Michael Stillwell <[email protected]>
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(-)
@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',
@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));
}
}
# 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)
import SocketServer
import SimpleHTTPServer
import urllib
PORT = 8080
class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_GET(self):
self.send_response(200)
self.end_headers()
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,
<html>
<head>
</head>
<body>
<script>
function jjjjj(arg) {
var post = arg.posts[0];
console.log(post);
document.write(post["regular-body"]);
}