Skip to content

Instantly share code, notes, and snippets.

@laser
laser / connections.js
Created September 24, 2014 05:58
connections from binder
var connections = Bacon.fromBinder(function(sink) {
io.on('connection', sink)
});
@laser
laser / vanilla.js
Last active November 4, 2023 04:01
Socket.IO + Vanilla JS
var request = require('request-json'),
express = require('express'),
app = express(),
http = require('http').Server(app),
io = require('socket.io'),
db = require('mongodb').MongoClient;
///////////////////////////////////////////////////////////
// boilerplate code: ignore
//
@laser
laser / streams.js
Last active March 27, 2018 00:30
Socket.IO + Bacon.js
var request = require('request-json'),
express = require('express'),
app = express(),
http = require('http').Server(app),
io = require('socket.io'),
Bacon = require('baconjs').Bacon,
client = request.newClient('http://localhost:3000/api/'),
db = require('mongodb').MongoClient;
///////////////////////////////////////////////////////////
@laser
laser / foo.md
Created September 24, 2014 02:03
Foo

Bacon.js + Node.js: Functional Reactive Programming on the Server

What

The following demonstrates the usage of the Bacon.js library in implementing a Node.js chat application in the functional reactive programming style. We'll start by re-implementing the canonical Socket.IO chat application in an FRP-idiomatic way, moving on to stream composition, sampling, debouncing, error handling and logging.

Why

@laser
laser / seattle_chat.js
Last active August 29, 2015 14:06
Socket.IO Chat App
/*
We'll be building a chat application for Seattle-based weather aficionados.
On top of basic chat functionality (sending messages to a chat room, being
notified when users enter/leave the room), the application will provide two
interesting, user-facing features:
1. New users, upon connection to the server, will be sent a private message
containing a summary of the current weather in Seattle.
@laser
laser / prunable.rb
Created August 29, 2014 15:34
Identifying properties of is_prunable?
class Prunable
THIRTY_DAYS_AGO_SEC = 60 * 60 * 24 * 30
def self.from_assets(exclusion_time, assets)
assets.select do |asset|
self.is_prunable?(exclusion_time, asset)
end
end
def self.is_prunable?(exclusion_time, asset)
@laser
laser / API.hs
Last active August 29, 2015 14:04
Bro, do you even liftA2?
module Main where
import Control.Applicative
-- represents our API - its constructor takes two functions
--
data API = API { apiDouble :: Integer -> Integer, apiTriple :: Integer -> Integer }
-- run a pure function as a computation in the IO monad.
-- note that the function won't be run until you bind the
@laser
laser / three.md
Last active August 29, 2015 14:04
Challenge Three

CHALLENGE #3

HIGHER-ORDER FUNCTIONS

  1. implement a function "foldFromRight" which takes:
  • a function with two parameters (a "binary function")
  • a starting value (the accumulator)
  • a list of values to reduce into a single value

The behavior of your foldFromRight function will be similar to "reduce" in JavaScript and Ruby - except for the fact that it will move from the end of the list to the beginning (instead of from the beginning to the end).

@laser
laser / dubbler_type_class.hs
Last active August 29, 2015 14:04
Haskell Type Class Basics
module Main where
-- essentially we're defining functions that makes sense to
-- call with things that can be doubled. it can be, well,
-- a value of any type (as long as that type instantiates
-- the Dubbleable type class). Dispatch can happen by virtue
-- of what you're going to do with the return value of the
-- function or what you're passing to the function as its
-- arguments
--
@laser
laser / matches.idl
Created June 11, 2014 01:23
Matches.idl
struct MatchSearch {
combineId int [optional]
}
struct Match {
id int
name string
startsAt int
teams []Team
heats []Heat