Skip to content

Instantly share code, notes, and snippets.

@chrislaughlin
chrislaughlin / gist:8751068
Created February 1, 2014 11:30
Using Objects as maps
var emptyMap = {};
var key = 'toString';
emptyMap[key] == undefined; // outputs false when it should be true
@chrislaughlin
chrislaughlin / gist:7054324
Created October 19, 2013 10:39
Grunt file
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jasmine_node: {
matchall: true, // load only specs containing specNameMatcher
projectRoot: ".",
requirejs: false,
forceExit: true,
jUnit: {
@chrislaughlin
chrislaughlin / gist:7053939
Created October 19, 2013 10:00
Jasmine Tests
describe("Main Server Tests", function() {
var request = require('request');
it("should respond with hello world", function(done) {
request("http://localhost:3000/hello", function(error, response, body){
expect(body).toEqual("Hello World");
done();
});
});
@chrislaughlin
chrislaughlin / gist:6926389
Created October 10, 2013 22:06
Reading in a search from twitter
console.log("Reading in the last 10 tweets with search: belfast");
T.get('search/tweets', { q: 'belfast', count: 10 }, function(err, reply) {
if (err) {
console.dir(err);
} else {
for (var i = 0; i < reply.statuses.length; i++) {
var status = reply.statuses[i];
console.log('*************************');
console.log(' username: ' + status.user.name);
console.log(' ' + status.text);
@chrislaughlin
chrislaughlin / gist:6926275
Created October 10, 2013 21:57
Posting a status using Twit
console.log("Posting Tweet");
var statusUpdate = 'Testing Status: ' + new Date().getTime();
T.post('statuses/update', { status: statusUpdate }, function(err, reply) {
if (err) {
console.dir(err);
} else {
console.dir(reply);
}
});
@chrislaughlin
chrislaughlin / gist:6926205
Last active December 25, 2015 05:39
Twit with node
var Twit = require('twit');
var T = new Twit({
consumer_key: 'j7e73ODaTmBLCjTebVuLyQ'
, consumer_secret: '********************************'
, access_token: '1952367470-wId4DkQc10jexSuUgg73Xo29Fjo53yCtc3Mzzkf'
, access_token_secret: '********************************'
});
@chrislaughlin
chrislaughlin / gist:6874254
Created October 7, 2013 20:19
Underscore.string
//format into name style case formatting
_.str.capitalize('chris')
=> "Chris"
//Compress white space
_.clean(" foo bar ")
=> 'foo bar'
//Swaps the case of the string
_.swapCase('hELLO')