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
@gf3
gf3 / gist:166083
Created August 11, 2009 20:09
Truncate a string to the closest word
// Truncate a string to the closest word
String.prototype.truncateToWord = function( length ) {
return this
.slice( 0, length + 1 )
.split( /\s+/ )
.slice( 0, -1 )
.join( " " )
}
// Examples

Using CouchDB with node.js

First, get yourself a CouchDB! You can get a free hosted CouchDB in seconds or download a binary from the Couchio downloads page.

Next, install npm because all awesome node packages are in npm :)

Node has better support for HTTP than any language I've ever worked with and coincidentally CouchDB's interface is solely accessible via HTTP. First, let's just talk to CouchDB using an HTTP library and later we'll look at some higher level abstractions.

Talking to CouchDB using request

@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"; }
@fhemberger
fhemberger / nodecamp.eu-talks-2011.md
Created June 13, 2011 11:31
A collection of talks and presentations held at nodecamp.eu 2011
@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)
@indexzero
indexzero / README.md
Created January 14, 2012 04:38
npmcount output for groups of node.js thought leaders
@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`.
*
@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);
}
@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('-')
@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.