Skip to content

Instantly share code, notes, and snippets.

View dandean's full-sized avatar
🌧️
It's raining.

Dan Dean dandean

🌧️
It's raining.
View GitHub Profile
@tj
tj / config.js
Last active December 27, 2015 14:49
/**
* Module dependencies.
*/
var pkg = require('../package');
var env = process.env.NODE_ENV || 'development';
/**
* Return setting `name`.
*
@domenic
domenic / interop.md
Last active July 7, 2022 19:47
`module.exports =` and ES6 Module Interop in Node.js

module.exports = and ES6 Module Interop in Node.js

The question: how can we use ES6 modules in Node.js, where modules-as-functions is very common? That is, given a future in which V8 supports ES6 modules:

  • How can authors of function-modules convert to ES6 export syntax, without breaking consumers that do require("function-module")()?
  • How can consumers of function-modules use ES6 import syntax, while not demanding that the module author rewrites his code to ES6 export?

@wycats showed me a solution. It involves hooking into the loader API to do some rewriting, and using a distinguished name for the single export.

This is me eating crow for lots of false statements I've made all over Twitter today. Here it goes.

@mikeal
mikeal / gist:2504336
Created April 27, 2012 00:11
Date parsing JSON
JSON._dateReviver = function (k,v) {
if (v.length !== 24 || typeof v !== 'string') return v
try {return new Date(v)}
catch(e) {return v}
}
JSON.parseWithDates = function (obj) {
return JSON.parse(obj, JSON._dateReviver);
}
@jlong
jlong / uri.js
Created April 20, 2012 13:29
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"
@indexzero
indexzero / README.md
Created January 14, 2012 04:38
npmcount output for groups of node.js thought leaders
@madrobby
madrobby / i18n.coffee
Created November 14, 2011 15:45
Backbone i18n with CoffeeScript
# before this file is loaded, a locale should be set:
#
# In a browser environment, you can use:
# ```<script>__locale='en';</script>```
#
# In a server environment (specifically node.js):
# ```global.__locale = 'en';```
# normalize in-app locale string to "en" or "de-AT"
parts = @__locale.split('-')
@ded
ded / app.js
Created October 21, 2011 23:14
Rails-like routes for Express
var express = require('express')
, app = express.createServer()
require('./config/routes').initialize(app)
@fhemberger
fhemberger / nodecamp.eu-talks-2011.md
Created June 13, 2011 11:31
A collection of talks and presentations held at nodecamp.eu 2011
@gf3
gf3 / git-feature
Created May 3, 2011 22:45
Git Feature Command – Feature Branches
#!/usr/bin/env zsh
# git-feature
# Written by: Gianni Chiappetta <gianni@runlevel6.org>
# Requires: git 1.7.5+, zsh 4.3.11+
# Screenshot: http://cloud.gf3.ca/6TPb
function c_list { echo " \033[1;32m✔\033[0m $1"; }
function e_list { echo " \033[1;31m✖\033[0m $1"; }
@joemccann
joemccann / nginx + node setup.md
Created October 25, 2010 02:06
Set up nginx as a reverse proxy to node.js.

The idea is to have nginx installed and node installed. I will extend this gist to include how to install those as well, but at the moment, the following assumes you have nginx 0.7.62 and node 0.2.3 installed on a Linux distro (I used Ubuntu).

In a nutshell,

  1. nginx is used to serve static files (css, js, images, etc.)
  2. node serves all the "dynamic" stuff.

So for example, www.foo.com request comes and your css, js, and images get served thru nginx while everything else (the request for say index.html or "/") gets served through node.

  1. nginx listens on port 80.