Skip to content

Instantly share code, notes, and snippets.

@joebalancio
joebalancio / _setup.js
Last active August 29, 2015 14:21
Overriding default behavior in Mio using wrapper Resources
/**
* I want to be able to post a list of items, filter out relevant items, then continue with the post
* Afterwards I want to get the collection that was just created and add some stuff to it
*
* 1. Post list
* 2. Filter items from list
* 3. Continue with post
* 4. Add stuff to collection after
*/
var mio = require('mio')
@joebalancio
joebalancio / gist:8af9525e6c8797c22fb2
Created May 22, 2015 19:07
Using Mio to retrieve different types of docs in a collection
var mio = require('mio');
var Message = mio.Resource.extend({
attributes: {
id: {
primary: true,
},
type: {},
text: {}
}
@joebalancio
joebalancio / process.coffee
Created June 2, 2014 17:47
Quick project to determine how many hashtags an Instagram user has used. First grab all posts by user, then process posts and perform hashtag calculation.
fs = require 'fs'
files = fs.readdirSync "#{process.cwd()}/json"
dataMap = {}
for file in files
raw = require "#{process.cwd()}/json/#{file}"
for x in raw.data
dataMap[x.id] = x
@joebalancio
joebalancio / fizzbuzz.scala
Last active August 29, 2015 14:01
Fizz Buzz in Scala
val rules = Map(3 -> "fizz", 5 -> "buzz")
for {
i <- 1 to 100
val out = rules.map { case (m, w) => if (i % m == 0) Option(w) else None }.flatten.reduceOption(_ + _).getOrElse(i)
} println(out)
@joebalancio
joebalancio / unit-testing-promises.coffee
Created February 13, 2013 21:30
Resolved issue of testing nested promises
Q = require('q')
sinon = require('sinon')
sinonChai = require('sinon-chai')
chai.use(sinonChai)
sinon.should()
describe 'testing promises', ->
aDeferred = Q.defer()
bDeferred = Q.defer()
@joebalancio
joebalancio / unit-testing.js
Last active December 13, 2015 17:28
I'm having trouble testing 2 modules that have methods which return promises. When I chain the calls together and test if the methods have been called, only 1 out of the 2 were called. The second nested method is never called according to Q. However, both resolved values are logged and inspecting the method within the callback reveals that it ha…
Q = require('q');
sinon = require('sinon')
sinonChai = require('sinon-chai');
chai.use(sinonChai);
sinon.should()
describe('testing promises', function() {
var aDeferred, bDeferred, moduleA, moduleB;
aDeferred = Q.defer();