Skip to content

Instantly share code, notes, and snippets.

View jameshartig's full-sized avatar

James Hartig jameshartig

View GitHub Profile
$mobileID = 0;
if ((string)$mobileID == 'beta') {
error_log("shit bricks: " . $mobileID);
}
...
php test.php
@jameshartig
jameshartig / getAnywhereStatus.js
Created December 29, 2010 21:26
get the current user's status from @anywhere
window.gotStatus = function (s) {
console.log(s);
//feel free to do whatever you want here
};
//replace twttr.anywhere._getVersion(twttr.anywhere._config.defaultVersion) with your version (ex. 1.1.3) if you want
function getStatus() {
twttr.anywhere({version: twttr.anywhere._getVersion(twttr.anywhere._config.defaultVersion), currentUser: twttr.anywhere.currentUser}, function (T) {
if (!T.isConnected()) {
if (!T.boundAuth) {
T.boundAuth = true;
@jameshartig
jameshartig / gist:761520
Created January 1, 2011 02:58
How to get php-cgi to detect if you have reset the connection
/*
The following example shows how to correct detect connection status under php-cgi
Works under apache and nginx. Cannot get it to work under lighttpd.
*/
ignore_user_abort(true);
ob_implicit_flush(true); //put these at the beginning
//loop and keep doing something until the user aborts
while (true) {
@jameshartig
jameshartig / gist:762267
Created January 2, 2011 03:57
How to listen for client disconnects in node.js
request.connection.addListener('end', function () {
response.end();
});
request.connection.addListener('close', function () {
response.end();
});
@jameshartig
jameshartig / gist:762874
Created January 2, 2011 22:20
Get IP of user in node.js and CloudFlare-compatible
function getIP(req) {
var ip_address = (req.connection.remoteAddress ? req.connection.remoteAddress : req.remoteAddress);
//check for cloudflare
try {
if (req.headers['cf-connecting-ip']) {
var ipParts = ip_address.split(".");
var cloudFlare = false;
switch (parseInt(ipParts[0])) {
case 204:
//(204.93.177.0 - 204.93.177.255)
@jameshartig
jameshartig / gist:772316
Created January 10, 2011 03:41
Count how many Google Voice text messages you've sent
/*
This is assuming you don't delete text messages. This only counts the amount of text messages you have not deleted.
This may take 5 minutes or so, depending on your computer speed and how many text messages you have.
Instructions:
Visit: https://www.google.com/voice/b/0#sms/ and wait for the page to fully load.
Paste this into your Javavscript console, wait it stops and look at the last count.
@jameshartig
jameshartig / func.js
Created October 27, 2011 11:32
Support for events on remove and add of children
function(element, addCallback, removeCallback) {
if (element) {
//adding support for DOM events on remove and adding children
if (addCallback && element.appendChild) {
(function() {
var orig = element.appendChild;
element.appendChild = function() {
try {
orig.apply(this, arguments);
} catch(e) { //ie7,6
@jameshartig
jameshartig / testTimeout.js
Created December 2, 2011 07:03
Test case for failing setTimeout(0)
var net = require("net"),
sys = require('util'),
socket = new net.connect(80, '74.125.115.99'); //google.com
socket.timedOut = false;
socket.setTimeout(1000, function() {
console.log("setTimeout(0) failed. Timed out!");
socket.timedOut = true;
});
socket.setTimeout(0);
var common = require('../common');
var assert = require('assert');
var net = require('net');
var util = require('util');
var c2 = net.createConnection(9999, 'google.com');
c2.on('connect', function() {
console.log("connected");
assert.ok(true);
});
function is_assoc($arr) {
return !(is_array($arr) && count(array_filter(array_keys($arr),'is_numeric')) == count($arr));
}