Skip to content

Instantly share code, notes, and snippets.

View aseemk's full-sized avatar

Aseem Kishore aseemk

View GitHub Profile
@aseemk
aseemk / README.md
Last active February 14, 2018 16:41
A bookmarklet for "selecting all" (technically, "toggling all") checkboxes on the Amazon AWS S3 console.
@aseemk
aseemk / app.coffee
Created February 18, 2013 18:00
A simple message-tracking web server.
express = require 'express'
app = express()
# the list of all messages we've received:
messages = []
# a map from all the clients we've seen (by their IDs),
# to their next unseen messages (by the messages' indices):
clients = {}
@aseemk
aseemk / 500.html
Created January 9, 2013 23:47
Thingdom's error and maintenance pages for Heroku. (Built with Jekyll and served by GitHub Pages.)
---
title: 500 Internal Server Error
---
<article>
<h1>500 Internal Server Error</h1>
<p>
Sorry, something’s gone wrong on our end.
We apologize for the inconvenience.
</p>
@aseemk
aseemk / app.js
Created January 9, 2013 21:58
Node.js cluster support on Heroku — freaking sweet!
var cluster = require('cluster');
var http = require('http');
var numCPUs = require('os').cpus().length;
var pid = process.pid;
var port = process.env['PORT'] || 8000;
if (cluster.isMaster) {
console.log('Master:', pid);
// Fork workers -- one less than the number of CPUs.
@aseemk
aseemk / app.coffee
Last active December 10, 2015 16:38
A simple Restify API server example.
bunyan = require 'bunyan'
restify = require 'restify'
requireDir = require 'require-dir'
middleware = requireDir './middleware'
routes = requireDir './routes'
settings = require './settings'
app = restify.createServer
name: 'Foo Bar API'
@aseemk
aseemk / gist:3966253
Created October 27, 2012 21:04
GitHub post-receive hook error
$ git push
Counting objects: 104, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (83/83), done.
Writing objects: 100% (83/83), 12.38 KiB, done.
Total 83 (delta 64), reused 0 (delta 0)
error: hooks/post-receive died of signal 2
remote: /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/connection/hiredis.rb:23:in `connect': Timeout::Error (Timeout::Error)
remote: from /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:204:in `establish_connection'
remote: from /data/github/current/vendor/gems/ruby/1.8/gems/redis-2.2.0/lib/redis/client.rb:23:in `connect'
@aseemk
aseemk / gist:3966223
Created October 27, 2012 20:57
Neo4j mutable Cypher, e.g. creating comments (node + relationships + update stats)
results = @query _, """
START author=node({authorId}), target=node({targetId})
CREATE comment={commentData}
CREATE comment -[:#{@REL_AUTHOR} {relAuthorData}]-> author
CREATE comment <-[:#{@REL_COMMENT} {relTargetData}]- target
SET author.numCommentsBy = COALESCE(author.numCommentsBy?, 0) + 1
SET target.numComments = COALESCE(target.numComments?, 0) + 1
RETURN comment
""",
authorId: author.id
@aseemk
aseemk / gist:3905781
Created October 17, 2012 14:23
Wrapper script around gmvault that allows setting default options.
#!/usr/bin/env bash
#
# Wrapper around gmvault binary that sets default options.
GMVAULT_DIR="$HOME/Dropbox/Applications/Utilities/gmvault-v1.7-beta/bin/"
DB_DIR="$HOME/Dropbox/.gmvault-db"
# Run in a sub-shell since we need to change directories:
(
cd $GMVAULT_DIR
@aseemk
aseemk / bases.md
Created July 16, 2012 18:26
JavaScript utility to convert numbers to different bases/alphabets.
@aseemk
aseemk / randomStr.js
Created July 12, 2012 05:00
Random alphanumeric (base-62) strings in Node.js, cryptographically strong
var bases = require('bases');
var crypto = require('crypto');
// Returns a base-62 (alphanumeric only) string of the given length:
function randomStr(length) {
// We generate a random number in a space at least as big as 62^length,
// and if it's too big, we just retry. This is still statistically O(1)
// since repeated probabilities less than one converge to zero. Hat-tip to
// a Google interview for teaching me this technique! ;)