Skip to content

Instantly share code, notes, and snippets.

View roman's full-sized avatar

Roman Gonzalez roman

View GitHub Profile
@roman
roman / cabal_sandbox_install.txt
Created May 30, 2013 20:40
Error when installing HsOpenSSL
$ cabal install HsOpenSSL
Resolving dependencies...
Configuring HsOpenSSL-0.10.3.3...
Building HsOpenSSL-0.10.3.3...
Preprocessing library HsOpenSSL-0.10.3.3...
[ 1 of 32] Compiling OpenSSL.ERR ( dist/dist-sandbox-dc2d92ee/build/OpenSSL/ERR.hs, dist/dist-san
dbox-dc2d92ee/build/OpenSSL/ERR.o )
[ 2 of 32] Compiling OpenSSL.Stack ( dist/dist-sandbox-dc2d92ee/build/OpenSSL/Stack.hs, dist/dist-s
andbox-dc2d92ee/build/OpenSSL/Stack.o )
[ 3 of 32] Compiling OpenSSL.DH.Internal ( dist/dist-sandbox-dc2d92ee/build/OpenSSL/DH/Internal.hs, di
@roman
roman / throttle.hs
Last active December 7, 2017 05:50
Implementation of throttle in Conduit 0.5.x
import Control.Concurrent (forkIO, killThread,
threadDelay, newEmptyMVar,
tryTakeMVar, putMVar)
import Control.Monad (void, forever)
import Control.Concurrent.STM (atomically)
import Control.Monad.Trans (MonadIO(..))
import Control.Monad.Trans.Resource (MonadResource, allocate)
import Data.Conduit (GInfConduit, awaitE)
throttle :: (MonadResource m) => Int -> GInfConduit a m a
@roman
roman / sourceTimer.hs
Last active December 17, 2015 08:09
Implementation of sourceTimer in Conduit 0.5.x
import Control.Concurrent (forkIO,
killThread,
threadDelay)
import Control.Monad (void)
import Control.Concurrent.STM (atomically)
import Control.Monad.Trans (MonadIO(..))
import Control.Concurrent.STM.TChan (TChan, newTChan, writeTChan, readTChan)
import Control.Monad.Trans.Resource (MonadResource, allocate)
import Data.Conduit (Source, awaitE)
import Data.Conduit.Internal (Pipe(..))
@roman
roman / dalap_rules.clj
Created November 29, 2012 00:32
An example of a dalap_rules.clj file for lein-dalap
{
["src/clj/util.clj" "src/cljs/util.clj"]
;; ^ this is the file-spec
;; bellow are the transformation rules that will work _only_ on util.clj
[
;; rule 1
JavaClass js_class ;; replace all the JavaClass symbols with js_class on cljs
;; rule 2
.findRegexp .findRgxp ;; replace all the .findRegexp invocations to .findRgxp
@roman
roman / project.clj
Created November 29, 2012 00:18
Example of how to include lein-dalap in your project.clj
(defproject some-project
;; ...
:plugins [[lein-dalap "0.1.0"]]
;;...
)
@roman
roman / client_code.cljs
Created November 23, 2012 21:22
help with macros in cljs
(ns buster-cljs.test.macros-test
(:require [buster-cljs.core :as core])
(:require-macros [buster-cljs.macros
:refer [initialize-buster deftest describe it is]]))
(deftest is-macro-with-exception-features
(it "assertions with `thrown?'"
(is (thrown? js/Error
(throw (js/Error. "an error"))))))
@roman
roman / latency.markdown
Created June 7, 2012 17:54 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@roman
roman / dummy-app.clj
Created June 6, 2012 03:09
ring usage example
(ns github
(:use [ring.middleware.cookies :only [wrap-cookies]]
[ring.middleware.session :only [wrap-session]]
[ring.middleware.lint :only [wrap-lint]]
[ring.middleware.session.cookie :only [cookie-store]]))
(defn index-handler [{:keys [session] :as req}]
(let [body (if (session :signed-in? false)
"welcome back!"
@roman
roman / Heap.java
Created May 22, 2012 19:49
Heap Implementation in Java [shivers]...
import java.util.ArrayList;
// This is a min heap
public class Heap {
protected int[] data = new int[1000];
public Heap() {
this.data[0] = 0;
}
@roman
roman / Graph.hs
Created April 23, 2012 17:24
Haskell BFS/DFS enumerators
module Main where
import Control.Monad.Identity (runIdentity)
import Data.Map (Map)
import Data.Set (Set)
import Data.Maybe (isNothing)
import qualified Data.Map as Map
import qualified Data.Set as Set