Skip to content

Instantly share code, notes, and snippets.

View aseemk's full-sized avatar

Aseem Kishore aseemk

View GitHub Profile
@aseemk
aseemk / npm-shrinkwrap-devdeps2.md
Last active December 26, 2015 10:59
npm shrinkwrap issues w/ de-duped production + dev dependencies

Install a production dependency, then install a dev dependency that the production dependency (internally) depends on as well. (Should you have to know that? Is that not an implementation detail?)

Then shrinkwrap for production, and note that the dev dependency is (correctly) excluded at the top, but present nested under the production dependency.

npm init
npm install strong-agent --save
npm install request@2.x --save-dev
npm shrinkwrap
@aseemk
aseemk / npm-shrinkwrap-devdeps1.md
Last active December 26, 2015 10:59
npm shrinkwrap issues w/ de-duped production + dev dependencies

Install a dev dependency, then install a production dependency that (internally) depends on that same dev dependency. (Should you have to know that? Is that not an implementation detail?)

Then shrinkwrap for production, and note the missing nested dependency.

npm init
npm install request@2.x --save-dev
npm install strong-agent --save
npm shrinkwrap
@aseemk
aseemk / app.js
Created September 26, 2013 00:18
Testing the non-blocking behavior of Node.js logging on Heroku.
// http://nodejs.org/api/process.html#process_process_stdout
console.log('Is stdout blocking?', process.stdout.isTTY);
console.log('Is stderr blocking?', process.stderr.isTTY);
console.log('Full stdout:\n', process.stdout);
console.log('Full stderr:\n', process.stderr);
@aseemk
aseemk / i18n._coffee
Last active January 28, 2019 14:52
Node.js script to extract i18n strings from source code.
#!/usr/bin/env _coffee
#
# Helper script to search all of our files for i18n strings and update our
# strings file. Helpful in case we missed a code path during testing.
#
# Specifically, searches for gettext `__()` calls in our checked-in files.
#
$ = require 'underscore'
echo = console.log
@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
@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 / 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 / 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 / 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: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]