(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
// Dependency resolution, adapted from https://gist.github.com/1232505/f16308bc14966c8d003c2686b1c258ec41303c1f | |
function resolve(graph) { | |
var sorted = [], // sorted list of IDs ( returned value ) | |
visited = {}; // hash: id of already visited node => true | |
// 2. topological sort | |
Object.keys(graph).forEach(function visit(name, ancestors) { | |
if (!Array.isArray(ancestors)) ancestors = []; | |
ancestors.push(name); | |
visited[name] = true; |
import util.parsing.json.JSON | |
import io.Source | |
import scala.language.dynamics | |
object Example extends App{ | |
val json = """{ | |
"name" : "Adam Slodowy", | |
"active": "true", | |
"roles" : [ "teacher", "admin" ], |
# Thanks to: http://stackoverflow.com/questions/8566667/split-javascript-array-in-chunks-using-underscore-js | |
_.mixin | |
chunk: (array, unit) -> | |
result = _.groupBy array, (element, index) -> | |
Math.floor index / unit | |
_.toArray result | |
data = [1,2,3,4,5,6,7,8,9] | |
# We pass the array and the size of the chunk | |
list = _.chunk data, 2 |
import sbt._ | |
import Keys._ | |
import java.net._ | |
import java.io.File | |
import play.PlayRunHook | |
/* | |
Grunt runner should be in project directory to be picked up by sbt | |
*/ | |
object Grunt { |
// Fonts mixin | |
font-url(file) | |
return '../fonts/' + file | |
webfont(family, file, hack-chrome-windows = false, weight = 'normal') | |
@font-face | |
font-family family | |
src url(font-url(file + '.eot')) | |
src url(font-url(file + '.eot?#iefix')) format('embedded-opentype'), | |
url(font-url(file + '.woff')) format('woff'), |
import scala.concurrent.{ExecutionContext, Future} | |
import spray.routing.{AuthenticationFailedRejection, RequestContext} | |
import spray.routing.authentication.{Authentication, ContextAuthenticator} | |
/** Token based authentication for Spray Routing. | |
* | |
* Extracts an API key from the header or querystring and authenticates requests. | |
* | |
* TokenAuthenticator[T] takes arguments for the named header/query string containing the API key and | |
* an authenticator that returns an Option[T]. If None is returned from the authenticator, the request |
//gulp & plugins | |
var gulp = require('gulp'); | |
var gutil = require('gulp-util'); | |
var jshint = require('gulp-jshint'); | |
var browserify = require('gulp-browserify'); | |
var jade = require('gulp-jade'); | |
var stylus = require('gulp-stylus'); | |
var mocha = require('gulp-mocha'); | |
var nodemon = require('gulp-nodemon'); | |
var livereload = require('gulp-livereload'); |
// === Arrays | |
var [a, b] = [1, 2]; | |
console.log(a, b); | |
//=> 1 2 | |
// Use from functions, only select from pattern | |
var foo = () => [1, 2, 3]; |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
// Coproduct is extension of Either concept, to N multually exlusive choices | |
type ISB = Int :+: String :+: Boolean :+: CNil | |
val isb = Coproduct[ISB]("foo") //> isb : qaaz.ISB = foo | |
isb.select[Int] //> res0: Option[Int] = None | |
isb.select[String] //> res1: Option[String] = Some(foo) |