Skip to content

Instantly share code, notes, and snippets.

@kputnam
kputnam / u.js
Created July 12, 2012 23:46
Functional combinators in JavaScript
var u = (function() {
var id = function(x) { return x; }
, single = function(x) { return [x]; }
, constant = function(x) { return function() { return x; }};
var curried = function(f, n, args) {
return (args.length >= n)
? f.apply(null, args)
: function() { return curried(f, n, args.concat(slice(arguments))); }; };
@iros
iros / API.md
Created August 22, 2012 14:42
Documenting your REST API

Title

<Additional information about your API call. Try to use verbs that match both request type (fetching vs modifying) and plurality (one vs multiple).>

  • URL

    <The URL Structure (path only, no root url)>

  • Method:

var empty_list = function(selector) {
return selector(undefined, undefined, true);
};
var prepend = function(el, list) {
return function(selector) {
return selector(el, list, false);
};
};
var head = function(list) {
@kaloprominat
kaloprominat / macos: manage add list remove login items apple script
Last active April 11, 2025 22:26
macos: manage add list remove login items apple script
# applescript
# add login item
osascript -e 'tell application "System Events" to make login item at end with properties {name: "Notes",path:"/Applications/Notes.app", hidden:false}'
# delete login item
osascript -e 'tell application "System Events" to delete login item "itemname"'
# list loginitems
osascript -e 'tell application "System Events" to get the name of every login item'
@jj-jabb
jj-jabb / lens.js
Created September 14, 2013 14:05
JavaScript immutable List and Lens implementation
var List = (function() {
function List(src) {
this._list = null
this._length = 0
if(src instanceof List) {
this._list = src._list
this._length = src._length
}
}
@gmanau
gmanau / nginx-socketio-ssl-reverse-proxy.conf
Last active March 25, 2024 12:15
How to setup nginx as nodejs/socket.io reverse proxy over SSL
upstream upstream-apache2 {
server 127.0.0.1:8080;
}
upstream upstream-nodejs {
server 127.0.0.1:3000;
}
server {
listen 80;
@divarvel
divarvel / continuation.js
Last active May 11, 2018 08:57
Continuation monad in JS. just run $ node continuation.js
console.log("\033[39mRunning tests…");
function assertEquals(actual, expected, description) {
if(typeof(actual) === "undefined") {
console.error("\033[31m" + description + " not implemented\033[39m");
} else {
if(actual !== expected) {
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m");
} else {
console.log(description + " \033[32m ok\033[39m");
}
@divarvel
divarvel / continuation.js
Last active May 27, 2023 08:12
implementation of the continuation monad in JS
console.log("\033[39mRunning tests…");
function assertEquals(actual, expected, description) {
if(typeof actual === "undefined") {
console.error("\033[31m" + description + " not implemented\033[39m");
} else {
if(actual !== expected) {
console.error("\033[31m" + description + " failed, expected " + expected + ", got " + actual + "\033[39m");
} else {
console.log(description + " \033[32m ok\033[39m");
}
@julien-f
julien-f / fibonacci.js
Created February 24, 2015 11:30
ES5 generators
var makeIterable = require('./make-iterable');
// Returns an iterator to the Fibonacci sequence.
function fibonacci() {
var prev = 0;
var curr = 1;
return makeIterable({
next: function () {
var tmp = curr;
@tel
tel / Cont.js
Created June 4, 2015 04:24
Continuation monad in Javascript
function Cont(contHandler) {
this.contHandler = contHandler;
};
Cont.unit = function(value) {
return new Cont(function (continue) { return continue(value); });
};
Cont.prototype.run = function(resume) {
return this.contHandler(resume);