Skip to content

Instantly share code, notes, and snippets.

View aseemk's full-sized avatar

Aseem Kishore aseemk

View GitHub Profile
@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 / 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.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 / 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 / gist:5191967
Created March 18, 2013 23:30
Sexy method argument overloading in CoffeeScript.
#
# Overloads:
# - fetch(url, callback)
# - fetch(url, opts, callback)
#
fetch = (args...) ->
[arg0, arg1, arg2] = args
[url, opts, callback] = switch args.length
when 0, 1 then throw new Error "Usage: fetch(url[, opts], callback)"
when 2 then [arg0, null, arg1]
@aseemk
aseemk / bookmarklet.js
Last active May 11, 2016 19:08
GitHub bookmarklet for toggling outdated diffs, and dotjs script for fixing links to pull request comments on outdated diffs.
javascript:(function(){[].forEach.call(document.querySelectorAll('.discussion-item-toggle-closed'), (elmt) => elmt.click())})();
@aseemk
aseemk / gist:5574052
Created May 14, 2013 06:21
A homegrown convention for shorthand static access syntax in CoffeeScript.

One of CoffeeScript's best features is the @ shorthand for this -- perfect for accessing instance methods and properties:

class Rectangle
  constructor: (@width, @height) ->
  getArea: ->
    @width * @height

But there's no similar shorthand for accessing static members, e.g. @@. So instead, you're forced to either hardcode class names, or type out the long constructor reference to be generic:

@aseemk
aseemk / app-api.coffee
Created May 20, 2013 15:43
Express 2 (Connect 1) vhosting.
express = require 'express'
app = express.createServer()
# ...
module.exports = app
@aseemk
aseemk / HelloNode.java
Created July 19, 2013 22:07
Node.java — a faithful port of the asynchronous Node.js platform to the strongly-typed Java language.
import java.util.Map;
import java.util.HashMap;
import com.joyent.node.http;
import com.joyent.node.http.RequestListener;
import com.joyent.node.http.ServerRequest;
import com.joyent.node.http.ServerResponse;
public class HelloNode {
public static void main(string[] args) {
@aseemk
aseemk / httpie-output
Created July 30, 2013 20:59
Testing `Expect: 100-continue` support in Node.js and HTTPie.
$ http -v PUT localhost:5100 Expect:100-continue foo=bar
PUT / HTTP/1.1
Accept-Encoding: identity, deflate, compress, gzip
Accept: application/json
User-Agent: HTTPie/0.2.5
Host: localhost:5100
Expect: 100-continue
Content-Type: application/json; charset=utf-8