Skip to content

Instantly share code, notes, and snippets.

View rikukissa's full-sized avatar
🍔

Riku Rouvila rikukissa

🍔
View GitHub Profile
@rikukissa
rikukissa / myController.js
Last active August 29, 2015 13:56
Example "Collection" implementation for angularFire
function MyController($scope, $firebaseCollection) {
// "images" - contains for example >10 000 children and we don't want to fetch them all at once
var imagesRef = new Firebase("https://<my-firebase>.firebaseio.com/images");
// Creates an empty collection for images
// Collection should now track changes in imagesRef.
// Example methods:
// $push( snapshot ) - Push new children to collection
$scope.images = $firebaseCollection(imagesRef);
form(data-bind='submit: loadFoobar')
button(type='submit', data-bind='css: { loading: loadFoobar.loading }')
phoneBook =
[("betty","555-2938")
,("bonnie","452-2928")
,("patsy","493-2928")
,("lucille","205-2928")
,("wendy","939-8282")
,("penny","853-2492")
]
getNumberByName :: (Eq a) => a -> [(a, c)] -> Maybe c
@rikukissa
rikukissa / todo.hs
Created March 7, 2014 14:41
Haskell todo-app
import System.Environment
import System.Directory
import System.IO
import Data.List
dispatch :: [(String, [String] -> IO ())]
dispatch = [ ("add", add)
, ("view", view)
, ("remove", remove)
, ("bump", bump)
@rikukissa
rikukissa / index.js
Created April 20, 2014 21:24
ES6 Generator testing
function getData(callback) {
setTimeout(function() {
callback(null, Date.now());
}, 1000);
}
function asyncCallback(generator) {
return function() {
var resolve = function(gen, data) {
var next = gen.next(data);
@rikukissa
rikukissa / gulpfile.coffee
Created April 24, 2014 09:31
Run casperjs tests with gulp
gulp.task "test", ->
server = require('./server/server.coffee').listen 9002
new Promise (resolve, reject) ->
test = spawn 'casperjs', ['test', './test'],
stdio: 'inherit'
test.on 'close', (code) ->
server.close()
return reject(new Error("Tests failed")) unless code is 0
#!/usr/bin/env node
var readline = require('readline');
var actions = [],
actionCount = null;
var debug = function(data) {
require('fs').writeFileSync(Date.now() + '.log', data);
};
user.populate 'creators', (err, user) ->
return next err if err?
async.map user.creators, (creator, done) ->
creator.populate 'city', done
, (err, creators) ->
return next err if err?
next response.ok creators
@rikukissa
rikukissa / fooService.coffee
Created June 5, 2014 14:23
Angular service with coffeescript
module.exports = ['$rootScope', 'Restangular', class FooService
constructor: (@$rootScope, @Restangular) ->
$rootScope.on '$foo', ->
# ...
getBars: ->
@Restangular.all('bars').getList()
module.exports = ['$rootScope', 'Restangular', ($rootScope, Restangular) ->
$rootScope.on '$foo', ->
path = require 'path'
express = require 'express'
bodyParser = require 'body-parser'
app = express()
if app.get('env') in ['development', 'test']
app.use express.static path.join __dirname, '../', 'public'