Skip to content

Instantly share code, notes, and snippets.

View mhaemmerle's full-sized avatar

Marc Haemmerle mhaemmerle

View GitHub Profile
// Copyright (c) 2016 Juan Delgado (JuDelCo)
// License: MIT License
// MIT License web page: https://opensource.org/licenses/MIT
#include "EntitasPP/SystemContainer.hpp"
#include "EntitasPP/Matcher.hpp"
#include "EntitasPP/Pool.hpp"
#include <iostream>
#include <string>
(ns a)
(def ^:dynamic *p* nil)
(defprotocol P
(f [this]))
(deftype Foo []
P
(f [this]
@mhaemmerle
mhaemmerle / gist:4249604
Created December 10, 2012 09:35
protocols
(ns example.registry
(:require [zookeeper :as zk]))
(def ^:dynamic *registry* nil)
(defprotocol Registry
(register [this id])
(deregister [this id])
(defrecord InMemoryRegistry [store]
@mhaemmerle
mhaemmerle / gist:3733098
Created September 16, 2012 16:31
chunked transfer memory leak
(defproject chunked-transfer "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[aleph "0.3.0-SNAPSHOT"]
[ring "1.1.1"]
[compojure "1.1.1"]
[cheshire "4.0.1"]]
:jvm-opts ["-Djava.awt.headless=true"]
:main chunked-transfer.core)
(ns chunked-transfer.core
@mhaemmerle
mhaemmerle / gist:3723317
Created September 14, 2012 17:16
failed agent behaviour
(def a (agent 1))
(set-error-mode! a :fail)
(set-error-handler! a (fn [failed-agent exception]
(println "error-handler" failed-agent exception)
(restart-agent failed-agent @failed-agent)
(println "restart done")))
(send a / 0)
(await a)
@mhaemmerle
mhaemmerle / gist:3712523
Created September 13, 2012 07:12
update macro
(defmacro defupdate
[multi-fn dispatch-value & body-fn]
`(. ~(with-meta multi-fn {:tag 'clojure.lang.MultiFn})
addMethod
~dispatch-value
(fn [{:keys [action# verb# body#]}]
(fn [channel# state#]
(let [result# (apply ~@body-fn (state# body#))]
(enqueue-and-close channel# (:response result#))
(log/info "update" result#)
@mhaemmerle
mhaemmerle / gist:3604243
Created September 2, 2012 20:24
wrap-ring-handler
(defroutes routes
(GET "/" [] (index))
(GET "/events" [] (wrap-aleph-handler events-handler)))
(def app
(-> handler
wrap-error-handling))
(defn start
[port]
project.clj
(defproject tcp-test "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.4.0"]
[aleph "0.3.0-SNAPSHOT"]
[org.clojure/tools.cli "0.2.1"]]
:main tcp-test.core)
core.clj
@mhaemmerle
mhaemmerle / gist:1049708
Created June 27, 2011 20:09
netty upgrade request
import java.net.InetSocketAddress
import java.util.concurrent.Executors
import org.jboss.netty.bootstrap.ClientBootstrap
import org.jboss.netty.buffer.ChannelBuffers
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory
import org.jboss.netty.channel._
import org.jboss.netty.util.CharsetUtil
import org.jboss.netty.handler.codec.http.HttpClientCodec
object Client {