Skip to content

Instantly share code, notes, and snippets.

View github.css
body {
font-family: Helvetica, arial, sans-serif;
font-size: 14px;
line-height: 1.6;
padding-top: 10px;
padding-bottom: 10px;
background-color: white;
padding: 30px; }
body > *:first-child {
View exportjson.js
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@mlconnor
mlconnor / async_series.js
Created Mar 18, 2014
Using async in node.js
View async_series.js
var async = require('async'),
async.series([
function(callback) {
setTimeout(function() {
console.log('f1');
callback(null, 'one');
}, 800);
},
function(callback) {
@mlconnor
mlconnor / regex.js
Created Apr 8, 2014
My regex notes
View regex.js
// match ip address but not internal 10.
"dkdl sld dj d 110.2.33.7 asjd ".match(/[^\d](?!10\.)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/);
@mlconnor
mlconnor / pick_mixins.js
Last active Aug 29, 2015
String based pick mixins for underscore
View pick_mixins.js
_.mixin({
pickStartsWith : function(obj,beginStr) {
if ( _.isArray(obj) || ! _.isObject(obj) ) throw new TypeError("pickStartsWith must be called on an object");
return _.pick(obj, _.filter(_.keys(obj), function(el, index) { return el.indexOf(beginStr) == 0; }));
},
pickMatch : function(obj,regex) {
if ( _.isArray(obj) || ! _.isObject(obj) ) throw new TypeError("pickBeginsWith must be called on an object");
return _.pick(obj, _.filter(_.keys(obj), function(el, index) { return el.match(regex) != null; }));
},
keyReplace : function(obj,regex, replace) {
@mlconnor
mlconnor / example.json
Last active Aug 29, 2015
A template for request.js call to Google search
View example.json
{
"uri" : "https://www.google.com/search",
"qs" : { "q" : "Example Search" },
"method" : "GET",
"headers" : {
"User-Agent" : "Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25"
},
"strictSSL" : false,
"timeout" : 20000,
"followRedirect" : false
@mlconnor
mlconnor / underover.js
Last active Aug 29, 2015
Concept for allowing JSON to inherit from other defs
View underover.js
var fs = require('fs');
var _ = require('lodash');
var defs = fs.readFileSync('servicedefs.json', {encoding:'utf8'});
var defsJson = JSON.parse(defs);
var indexedDefs = _.indexBy(defsJson, 'id');
_.each(indexedDefs, function(def, index) {
var current = def;
while ( _.has(def, 'under') ) {
@mlconnor
mlconnor / dumper.js
Last active Aug 29, 2015
This fill will dump raw post data to the console. An enhancement would be to use middleware to grab all posts.
View dumper.js
var express = require('express')
, http = require('http')
, bodyParser = require('body-parser')
, _ = require('underscore')
, cookieParser = require('cookie-parser');
var app = express();
/* configure express */
app.set('port', process.env.PORT || 3000);
@mlconnor
mlconnor / underscore_merge.js
Created Aug 6, 2014
underscore merge function
View underscore_merge.js
var _ = require('lodash');
var obj1 = {foo:'bar',baz:'bang', arr:[1,3,5,7], objecter : { 'connor' : 2, 'sky':'toot', 'new':'dude' } };
var obj2 = {foo:'bar',baz:'bang', arr:[2,4,6,8], newz:1, objecter : { 'sky' : 'mills'} };
merge(obj1,obj2);
merge(null,2);
merge(4,6);
console.log(obj1);
@mlconnor
mlconnor / requestjs2curl.js
Last active Aug 29, 2015
A quick first pass at turning request.js options object into a curl command. Much work needed here for escaping and edge cases.
View requestjs2curl.js
function request2Curl(options) {
var tokens = ['curl', '-v', '-k', '-ssl3'];
if ( _.has(options, 'auth') ) {
if ( _.has(options.auth, 'user') ) {
tokens.push('--user', "'" + options.auth.user + ":" + options.auth.pass + "'");
}
}
var isPost = _.has(options, 'method') && options.method.toLowerCase() == 'post';