Skip to content

Instantly share code, notes, and snippets.

View srdjan's full-sized avatar

⊣˚∆˚⊢ srdjan

View GitHub Profile
@srdjan
srdjan / fold.js
Last active September 9, 2015 23:19 — forked from kpuputti/fold.js
Functional acrobatics using folds in JavaScript.
/*eslint-env es6 */
// Inspired by the paper "A tutorial on the universality and
// expressiveness of fold" by Graham Hutton (available at
// http://www.cs.nott.ac.uk/~gmh/fold.pdf), implementing some generic
// list handling functions in JavaScript in terms of `fold`.
// Personally I had an enlightnening moment when I realised the
// beautiful interplay of cons lists and foldr during the FP101x
// Haskell course. JavaScript's syntax doesn't make this very apparent
@srdjan
srdjan / observer.coffee
Created November 1, 2011 19:49 — forked from sdiehl/observer.coffee
Observer Pattern in Coffeescript
class Observer
bind : (event, fn) ->
this._events ||= {}
this._events[event] ||= []
this._events[event].push(fn)
unbind: (event, fn) ->
@_events ||= {}
@srdjan
srdjan / xhr.js
Created November 3, 2011 00:49 — forked from mythz/xhr.js
Standalone jQuery-like Ajax Client
//Adds $.xhr and jQuery-like $.ajax methods to the prescribed namespace.
//Inspired from David Flanagans excellent cross-platform utils http://www.davidflanagan.com/javascript5/display.php?n=20-1&f=20/01.js
//Includes underscore.js _.each and _.extend methods
//modified to behave like jQuery's $.ajax(), not complete.
(function($) {
var win=window, xhrs = [
function () { return new XMLHttpRequest(); },
function () { return new ActiveXObject("Microsoft.XMLHTTP"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP.3.0"); },
function () { return new ActiveXObject("MSXML2.XMLHTTP"); }
@srdjan
srdjan / i18n.coffee
Created November 14, 2011 20:06 — forked from madrobby/i18n.coffee
Backbone i18n with CoffeeScript
window.t = (id, vars = {}) ->
template = i18n[__locale][id] or i18n['en'][id] or "(?) #{id}"
_.template(template, vars)
# yes, that's it
@srdjan
srdjan / dnsd.rb
Created February 12, 2012 19:41 — forked from peterc/dnsd.rb
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL
@srdjan
srdjan / AA.md
Created July 10, 2012 12:12 — forked from sadache/AA.md
Is socket.push(bytes) all what you need to program Realtime Web apps?

Is socket.push(bytes) all what you need to program Realtime Web apps?

One of the goals of Play2 architecture is to provide a programming model for what is called Realtime Web Applications.

Realtime Web Applications

Realtime Web Applications are applications making use of Websockets, Server Sent Events, Comet or other protocols offering/simulating an open socket between the browser and the server for continuous communication. Basically, these applications offer to users delivery of information as it is published without having the user periodically pinging the service.

There are quite a few web frameworks that target the development of this type of applications. Mostly, however, the solution is by providing an API that allows developers to push/receive messages from/to an open channel, something like:

module BorrowABook =
type BookLoanProblem =
NotInCatalogue
| OutOnLoan
| InsufficientPermission
| Failed of string
type Book = Book
type BookModel = BookModel
using System;
using System.Linq;
using Raven.Abstractions.Data;
using Raven.Abstractions.Logging;
using Raven.Bundles.Replication.Plugins;
using Raven.Json.Linq;
namespace RavenConflictResolverPlugin
{
public class LastInWinsReplicationConflictResolver
@srdjan
srdjan / ddd.fsx
Created June 11, 2016 15:07 — forked from hodzanassredin/ddd.fsx
monadic ddd in fsharp
type Request<'i,'o,'k> = 'i * ('o -> 'k)
let bindRequest bind f (s,k) = s, fun v -> bind(k v,f)
type Id = int
type Entity<'e> = Entity of Id option * 'e
[<Measure>] type money
type User = {name : string; email : string; ballance : int<money>}
type Product = { name : string; quantity : int; price : int<money>}
type Email = {body:string; subject : string}
@srdjan
srdjan / qs.js
Created July 21, 2016 11:14 — forked from yoshuawuyts/qs.js
const reg = new RegExp("([^?=&]+)(=([^&]*))?", "g")
function qs (uri) {
const obj = {}
uri = uri.replace(/^.*\?/, '')
uri.replace(reg, map)
return obj
function map (a0, a1, a2, a3) {
obj[decodeURIComponent(a1)] = decodeURIComponent(a3)