Skip to content

Instantly share code, notes, and snippets.

//synchronous behaviour testing
var async = require('async');
var request = require('request');
function async_function(){
}
function sync_function(){
var result = "5";
@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]);
}
}
@Trindaz
Trindaz / gist:2234466
Created March 29, 2012 07:13
Deep Copy walk with forced async completion before return
var http = require('http');
var request = require('request');
var samplePayload = {
"key1":{
"key1.1": {
"key1.1.1": ["val1.1.1.1", "val1.1.1.2", "val1.1.1.3", "val1.1.1.4"]
},
"key1.2": ["val1.2.1" ,"val1.2.2"]
},
@Trindaz
Trindaz / gist:2355968
Created April 11, 2012 00:41
Unwanted qualified href values
var currentDoc = jsdom.jsdom('<html><head><title>href test</title></head><body><p><a href="test.html">Test</a></p></body></html>';, null, {});
var window = currentDoc.createWindow();
jsdom.jQueryify(window, 'jquery-1.4.2.min.js' , function() {
console.log(window.$('a')[0]['href']);
});
/*
returns /Users/[path to the script]/test.html
*/
@Trindaz
Trindaz / ClothObjectValues.js
Created May 4, 2012 00:31
Clothe 'naked' values of an object by wrapping in " chars for postponed evaluation
//clothe a hub file that has 'naked' expressions
//e.g. turn {key:$('body p')} into {key:"$('body p')"}
function clothe(contents){
closers = /[\}\]\)\/"']/
openers = /[\{\[\(\/"']/
closing = {
"{": "}",
"[": "]",
"(": ")",
function codeAddress(){
var geocoder,latLng;
geocoder = new google.maps.Geocoder();
var address = document.getElementById('address').value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latLng=results[0].geometry.location;
document.getElementById("address").value = latLng;
} else {
alert('Geocode was not successful for the following reason: ' + status);
var jsdom = require('jsdom');
var body1="<html><head>"+
"<script type='text/javascript' src='https://maps.googleapis.com/maps/api/js?key=***key***&sensor=false'></script>"+
"<script type='text/javascript' src='https://raw.github.com/gist/2878326/f2d5d46b07a9f425870fa025c2cfbeb379c41a67/gistfile1.js'></script></head>"+
"<script>functions testMe(){ var a = 1;}</script>"
"<body>"
"<div><form id='addressform'>"+
"<input id='address' class='address' type='textbox' value='1 Market St, San Francisco'>"+
"<input id='test' class='test' type='textbox' value='not tested'></form></div></body>"+
@Trindaz
Trindaz / Test1
Created July 8, 2012 12:32
Test1
/usr/local/bin/node src/testScripts/PeopleSearchTests/scratchpad/umbrella_test.js
Starting batch 0
It's been 123 since you start this script
360 so far, got response from 1, and still waiting: 359 max ever: 360
360 so far, got response from 2, and still waiting: 358 max ever: 360
360 so far, got response from 3, and still waiting: 357 max ever: 360
360 so far, got response from 4, and still waiting: 356 max ever: 360
360 so far, got response from 5, and still waiting: 355 max ever: 360
360 so far, got response from 6, and still waiting: 354 max ever: 360
360 so far, got response from 7, and still waiting: 353 max ever: 360
@Trindaz
Trindaz / gist:3074685
Created July 9, 2012 06:54
2012-07-08 1000-1
/usr/local/bin/node src/testScripts/PeopleSearchTests/scratchpad/umbrella_test.js
Starting batch 0
1000 so far, got response from 1, and still waiting: 999 max ever: 1000
1000 so far, got response from 2, and still waiting: 998 max ever: 1000
1000 so far, got response from 3, and still waiting: 997 max ever: 1000
1000 so far, got response from 4, and still waiting: 996 max ever: 1000
1000 so far, got response from 5, and still waiting: 995 max ever: 1000
1000 so far, got response from 6, and still waiting: 994 max ever: 1000
1000 so far, got response from 7, and still waiting: 993 max ever: 1000
1000 so far, got response from 8, and still waiting: 992 max ever: 1000
@Trindaz
Trindaz / gist:3074694
Created July 9, 2012 06:56
2012-07-08 1000-2
/usr/local/bin/node src/testScripts/PeopleSearchTests/scratchpad/umbrella_test.js
Starting batch 0
1000 so far, got response from 1, and still waiting: 999 max ever: 1000
1000 so far, got response from 2, and still waiting: 998 max ever: 1000
1000 so far, got response from 3, and still waiting: 997 max ever: 1000
1000 so far, got response from 4, and still waiting: 996 max ever: 1000
1000 so far, got response from 5, and still waiting: 995 max ever: 1000
1000 so far, got response from 6, and still waiting: 994 max ever: 1000
1000 so far, got response from 7, and still waiting: 993 max ever: 1000
1000 so far, got response from 8, and still waiting: 992 max ever: 1000