Skip to content

Instantly share code, notes, and snippets.

View seanstrom's full-sized avatar
:octocat:

Sean Hagstrom seanstrom

:octocat:
View GitHub Profile
@seanstrom
seanstrom / identity.ls
Created May 31, 2015 01:59
identity function livescript
identity = (x) -> x
@seanstrom
seanstrom / example.js
Last active August 29, 2015 14:13
Async JS/Node - Promises Always Async Output
var endpoint = 'my/endpoint'
var dataPromise = getData(endpoint)
console.log(1)
dataPromise.then(function(data) {
console.log(2)
})
console.log(3)
@seanstrom
seanstrom / example.js
Created January 20, 2015 22:24
Async JS/Node - Callbacks Not Alway Async Output - Sync
var endpoint = 'my/endpoint'
console.log(1)
getData(endpoint, function(err, data) {
console.log(2)
})
console.log(3)
@seanstrom
seanstrom / example.js
Last active August 29, 2015 14:13
Async JS/Node - Callbacks Not Alway Async Output - Async
var endpoint = 'my/endpoint'
console.log(1)
getData(endpoint, function(err, data) {
console.log(2)
})
console.log(3)
@seanstrom
seanstrom / example.js
Created January 20, 2015 19:24
Async JS/Node - Sequential Promises Example - Part 2
// Part 2
var username = 'seanghagstrom'
findLikesForPostsByUsername(username)
.then(function(totalLikes) {
console.log(username + ' total number of likes: ' + totalLikes)
})
.catch(function(err) {
console.error(err)
@seanstrom
seanstrom / example.js
Last active August 29, 2015 14:13
Async JS/Node - Sequential Promises Example - Part 1
// Part 1
function findLikesForPostsByUsername(username, callback) {
var promise = new Promise(function(resolver, rejector) {
findUserByUsername(username)
.then(findPostsByUser)
.then(findLikesByPosts)
.then(function(likes) {
var totalLikes = likes.reduce(function(x, y) { return x + y })
resolver(totalLikes)
@seanstrom
seanstrom / example.js
Last active August 29, 2015 14:13
Async JS/Node - Using Promise Example
var endpoint = 'my/endpoint'
var dataPromise = getData(endpoint)
dataPromise.then(function(data) {
console.log(data)
}, function(error) {
console.error(error)
})
@seanstrom
seanstrom / example.js
Created January 20, 2015 16:19
Async JS/Node - Create Promise Example
var http = require('special-http')
function getData(endpoint) {
var promise = new Promise(function(resolver, rejector) {
http.get(endpoint).then(function(data) {
resolver(data)
}, function(err) {
rejector(err)
})
})
@seanstrom
seanstrom / example.js
Last active August 29, 2015 14:13
Async JS/Node - Parallel Async.js Example - Part 2
// Part 2
var username = 'seanghagstrom'
getTweetsPostsRepos(username, function(err, tweetsPostsRepos) {
if(err) {
console.error(err)
} else {
console.log(username + ' has this stuff ' + tweetsPostsRepos)
}
@seanstrom
seanstrom / example.js
Created January 20, 2015 06:26
Async JS/Node - Parallel Async.js Example - Part 1
// Part 1
function getTweetsPostsRepos(username, mainCallback) {
async.parallel([
function(callback) {
getTweets(username, callback)
},
function(callback) {
getPosts(username, callback)
},