Skip to content

Instantly share code, notes, and snippets.

View jameshartig's full-sized avatar

James Hartig jameshartig

View GitHub Profile
<?php
function gcd($a, $b) {
$a = abs($a);
$b = abs($b);
if ($a < $b) {
$c = $a;
$a = $b;
$b = $c;
}
if ($b == 0) {
<?php
function superDuperMerge($array1, $array2)
{
if (!$array1 || $array1 instanceof stdClass) {
return $array2;
} else if (!$array2 || $array2 instanceof stdClass) {
return $array1;
}
$new = array();
@jameshartig
jameshartig / keybase.md
Last active August 29, 2015 14:07
keybase.md

Keybase proof

I hereby claim:

  • I am fastest963 on github.
  • I am jameshartig (https://keybase.io/jameshartig) on keybase.
  • I have a public key whose fingerprint is 5425 C8A5 EE2F 158C 6AF4 E1A7 ACDE 6F5B 3F1F 0068

To claim this, I am signing this object:

@jameshartig
jameshartig / onename
Created October 21, 2014 20:34
onename
Verifying that +jameshartig is my Bitcoin username. You can send me #bitcoin here: https://onename.io/jameshartig
@jameshartig
jameshartig / suggestion.js
Created October 24, 2014 15:48
Grooveshark User Ignore
var oldParse = GS.Models.ChatActivity.prototype.parse;
GS.Models.ChatActivity.prototype.parse = function() {
var attrs = oldParse.apply(this, Array.prototype.slice.call(arguments));
if (attrs.type == 'message' && attrs.user && isIgnored(attrs.user.get('UserID'))) {
attrs.specialFlag == 'ignored';
}
return attrs;
}
@jameshartig
jameshartig / cluster.js
Last active August 29, 2015 14:16
Cluster vs manually forking
//Straight from http://nodejs.org/api/cluster.html
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
// Fork workers.
for (var i = 0; i < numCPUs; i++) {
cluster.fork();
}
test('Do not allow duplicate models (with nonstandard id) to be `add`ed or `set`', function() {
var Stooge = Backbone.Model.extend({
parse: function(a) {
var attrs = {};
attrs._id = a.__id;
return attrs;
}
});
Stooge.prototype.idAttribute = '_id';
// If a duplicate is found, prevent it from being added and
// optionally merge it into the existing model.
existing = this.get(attrs);
if (!existing) {
model = newModels[i] = this._prepareModel(attrs, options);
if (!model) continue;
existing = this.get(model);
}
if (existing) {
....
@jameshartig
jameshartig / destroyLoop.js
Last active August 29, 2015 14:16
failed test backbone
test("destroy models in each loop", 4, function() {
var collection = new Backbone.Collection([{id: 1}, {id: 2}, {id: 3}, {id: 4}]);
collection.each(function(model) {
notStrictEqual(model, undefined);
if (model !== undefined) {
model.destroy({url: function() {}});
}
});
});
var artistMap = new WeakMap(),
albumMap = new WeakMap();
var Song = Backbone.Model.extend({
parse: function(a) {
artistMap.set(this, a.artist);
delete a.artist;
albumMap.set(this, a.album);
delete a.album;
},