Skip to content

Instantly share code, notes, and snippets.

@Trindaz
Trindaz / hash.js
Created November 18, 2014 16:12
A deterministic, circular reference safe hash function for javascript objects
function hash(obj) {
var cache = [];
function sanitize(obj) {
if (obj === null) { return obj; }
if (['undefined', 'boolean', 'number', 'string', 'function'].indexOf(typeof(obj)) >= 0) { return obj; }
if (typeof(obj)==='object') {
var keys = Object.keys(obj).sort(),
values = [];
for k in $(git branch | sed /\*/d); do
if [ -n "$(git log -1 --before='1 month ago' -s $k)" ]; then
git branch -D $k
git push origin --delete $k
fi
done
@Trindaz
Trindaz / Circular reference JSON.stringify wrapper
Created January 28, 2013 04:44
Circular reference JSON.stringify wrapper
var repeatingArray = [4, 5, 6];
var circularObj = {
a: 1,
b: 1,
c: "an allowed repeating string",
d: "an allowed repeating string",
e: repeatingArray,
f: repeatingArray,
g: [
@Trindaz
Trindaz / gist:2234277
Created March 29, 2012 06:46
Javascript object deep copy
function processObjWithRef(obj, result){
if(obj==null || typeof obj != 'object'){
//nothing really to do here - you're going to lose the reference to result if you try an assignment
}
if(obj instanceof Array) {
for(var i=0; i<obj.length; i++){
result.push();
processObjWithRef(obj[i], result[i]);
}
}
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
@Trindaz
Trindaz / gist:5351634
Created April 10, 2013 03:45
How do I make these two divs line up in the center?
<html>
<head>
<title>Side By Side Div Example</title>
<style>
div.left-column {
background-color: yellow;
display: inline;
}
<html>
<head>
<title>Side By Side Div Example</title>
<style>
div.left-column {
width: 20%;
min-width: 200px;
float: left;
background-color: yellow;
@Trindaz
Trindaz / gist:5275435
Created March 30, 2013 04:54
package.json for jcrugzz
{
"name": "schema-website",
"version": "0.0.0-30",
"description": "ERROR: No README.md file found!",
"main": "server.js",
"dependencies": {
"async": "~0.2.5",
"consolidate": "~0.8.0",
"express": "~3.1.0",
"passport": "~0.1.15",
info: Creating snapshot 0.0.0-14
debug: { method: 'POST',
debug: uri: 'https://api.nodejitsu.com/apps/trindaz/schema-website/snapshots/0.0.0-14',
debug: headers:
debug: { Authorization: '*****************************************************************',
debug: 'Content-Type': 'application/octet-stream',
debug: 'Content-Length': 838180 },
debug: timeout: 240000 }
info Uploading: [=============================] 100%
debug: { statusCode: 201,
info: Creating snapshot 0.0.0-13
info Uploading: [=============================] 100%
info: Updating app schema-website
info: Activating snapshot 0.0.0-13 for schema-website
info: Starting app schema-website
error: Error running command deploy
error: Nodejitsu Error (500): Internal Server Error
error:
error: There was an error while attempting to start the app
error: Error spawning drone