Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
// Section: "Prototype-based OO programming", 2nd example
var bFunc = function() { return this }
var b = { name: "b", fun: bFunc }
b.fun()
// => Object {name: "b", fun: function}
import java.util.concurrent.atomic.AtomicReference
class Atom[T](private val state: AtomicReference[T]) {
def get = state.get()
def swap(f: T => T): T = {
val v = state.get()
val newv = f(v)
if (state.compareAndSet(v, newv)) newv else swap(f)
$stack, $draws = [], {}
def method_missing *args
return if args[0][/^to_/]
$stack << args.map { |a| a or $stack.pop }
$draws[$stack.pop(2)[0][0]] = args[1] if args[0] == :<
end
class Array
def +@
(ns enliven.lenses
(:refer-clojure :exclude [get put update]))
(defprotocol Lens
(-get [lens data])
(-put [lens data v]))
(defprotocol Updatable
(-update [lens data f]))
;; I wrote this in the Eurostar on my way back from the last lambdanext.eu clojure course.
(ns comprehensions
(:refer-clojure :exclude [for doseq])
(:require [clojure.core.reducers :as r]))
;; borrowed from clojure.core
(defmacro ^{:private true} assert-args
[& pairs]
`(do (when-not ~(first pairs)
import Data.Monoid
pipeline :: [a -> a] -> a -> a
pipeline = appEndo . getDual . mconcat . fmap (Dual . Endo)
main = print $ pipeline [(+1), (*10)] 100
(ns barker.client.main
(:require [shoreleave.client.worker :as swk]))
; Take any function in your source...
(defn echo-workerfn [data] data)
; Drop it into a worker...
(def nw (swk/worker echo-workerfn))
; The worker implements IWatchable
;;; Clojure port of http://dysphoria.net/code/hindley-milner/HindleyMilner.scala
(ns hindley-milner
(:require [clojure.string :as str]))
(declare occurs-in? occurs-in-type?)
(defn map-state
"Evaluate a list of state monad values in sequence, producing
a list of the results of each evaluation."

For example, one of the many current day standards that was dismissed immediately is the WWW (one could hardly imagine more of a mess).

But the functionality plus more can be replaced in our "ideal world" with encapsulated confined migratory VMs ("Internet objects") as a kind of next version of Gerry Popek's LOCUS.

The browser and other storage confusions are all replaced by the simple idea of separating out the safe objects from the various modes one uses to send and receive them. This covers files, email, web browsing, search engines, etc. What is left in this model is just a UI that can integrate the visual etc., outputs from the various encapsulated VMs, and send them events to react to. (The original browser folks missed that a scalable browser is more like a kernel OS than an App)

These are old ideas, but the vendors etc didn't get it ...

@fogus
fogus / gist:5481182
Last active December 16, 2015 18:58 — forked from hintjens/gist:5480625
// Minimal HTTP server in 0MQ
#include "czmq.h"
int main (void)
{
zctx_t *ctx = zctx_new ();
void *router = zsocket_new (ctx, ZMQ_ROUTER);
zsocket_set_router_raw (router, 1);
int rc = zsocket_bind (router, "tcp://*:8080");
assert (rc != -1);