Skip to content

Instantly share code, notes, and snippets.

@henryoswald
henryoswald / gist:1106175
Created July 26, 2011 07:17
npm install now - lion fail
[henry@dyn207249:~/Desktop/a]$ npm install now -g
> [email protected] install /usr/local/lib/node_modules/now/node_modules/node-proxy
> make
sh: make: command not found
npm ERR! error installing [email protected] Error: [email protected] install: `make`
npm ERR! error installing [email protected] `sh "-c" "make"` failed with 127
npm ERR! error installing [email protected] at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:67:17)
@henryoswald
henryoswald / onlySingleClick.coffee
Last active December 11, 2015 04:08
simple way to prevent double clicks in a client side app but still register single clicks
cachedEvents: {}
onlySingleClick: (e, waitBetweenClicks = 500)->
foundTime = cachedEvents[e.target]
now = new Date().getTime()
difference = now - foundTime
cachedEvents[e.target] = now
return difference > waitBetweenClicks
request = require("request")
module.exports = {
getUserDetails: function(user_id, callback){
var url = "http://www.api.com/user/" + user_id
request.get(url, function(err, response, body){
callback(err, body)
})
}
}
sinon = require('sinon');
chai = require('chai');
should = chai.should();
SandboxedModule = require('sandboxed-module');
modulePath = "./UserHandler";
describe('User Handler', function() {
var user_id = "12345"
@henryoswald
henryoswald / totalRecurlyTransactionsByCountry
Created October 9, 2014 10:15
this can be used to total together transactions expored by recutly by groups such as the EU and USA
euCountries = ["AT", "BE", "BG", "HR", "CY", "CZ", "DK", "EE", "FI", "FR", "DE", "EL", "HU", "IE", "IT", "LV", "LT", "LU", "MT", "NL", "PL", "PT", "RO", "SK", "SI", "ES", "SE", "GB"]
_ = require("underscore")
fs = require("fs")
file = fs.readFileSync("./transactions.csv", "utf-8")
lines = file.split("\n")
groupedTransactions = _.groupBy lines, (line)->
vals = line.split(",")
@henryoswald
henryoswald / gist:aca1545987f2360c4bd4
Created October 16, 2014 09:27
gzip project data
(function() {
var zlib = require('zlib');
var ObjectId, UserGetter, db, mongojs;
mongojs = require("../../infrastructure/mongojs");
console.log("hello")
db = mongojs.db;
ObjectId = mongojs.ObjectId;
@henryoswald
henryoswald / gist:7bec14e3a3cd548d05af
Created October 16, 2014 10:58
group premium users by role
var db, mongoConnectionString, mongojs, query;
mongojs = require("mongojs");
var ObjectId = mongojs.ObjectId
var async = require("async")
var _ = require("underscore")
mongoConnectionString = "mongodb://127.0.0.1/sharelatex-production";
@henryoswald
henryoswald / gist:552d1a2a747f01537577
Created November 17, 2014 13:19
process redis db
sort -t"," -n -k4 memory.csv > sorted.csv
grep "DocOps" sorted.csv> docops.csv
grep "sess" sorted.csv> sess.csv
grep "doclines" sorted.csv> doclines.csv
grep "tpds" sorted.csv> tpds.csv
grep UncompressedHistoryOps sorted.csv> historyops.csv
grep "project_last_updated" sorted.csv> lastupdated.csv
@henryoswald
henryoswald / gist:0ca8d12b594be9d1b745
Created May 26, 2015 12:54
create random users with projects and linking
UserCreator = require("./app/js/Features/User/UserCreator")
ProjectCreationHandler = require("./app/js/Features/Project/ProjectCreationHandler")
CollaboratorsHandler = require("./app/js/Features/Collaborators/CollaboratorsHandler")
uuid = require('node-uuid')
async = require("async")
_ = require("underscore")
require("./app/js/Features/Email/EmailSender").sendEmail= (opts, cb)->
cb()
@henryoswald
henryoswald / gist:8ff9cf917e63c2e983dd
Created July 19, 2015 15:57
db.serverStatus() on primary server
{
"host" : "primary-mongodb",
"version" : "3.0.3",
"process" : "mongod",
"pid" : NumberLong(24890),
"uptime" : 1671011,
"uptimeMillis" : NumberLong(1671011524),
"uptimeEstimate" : 1655592,
"localTime" : ISODate("2015-07-19T15:55:42.960Z"),
"asserts" : {