Skip to content

Instantly share code, notes, and snippets.

View AlBaker's full-sized avatar

Al Baker AlBaker

View GitHub Profile
@Dierk
Dierk / KanbanDemo.groovy
Created September 13, 2011 19:32
Classic concurrent producer-consumer problem with using a kanban system to avoid buffer overflows when consumers are slow
import groovyx.gpars.dataflow.DataFlowQueue
import groovyx.gpars.dataflow.operator.DataFlowPoisson
import static groovyx.gpars.dataflow.DataFlow.operator
import java.util.concurrent.atomic.AtomicInteger
def upstream = new DataFlowQueue() // empty trays travel back upstream to the producer
def downstream = new DataFlowQueue() // trays with products travel to the consumer downstream
def prodWiring = [inputs: [upstream], outputs: [downstream], maxForks: 3 ] // maxForks is optional
def consWiring = [inputs: [downstream], outputs: [upstream], maxForks: 3 ] // maxForks is optional
@alandipert
alandipert / kahn.clj
Last active June 24, 2023 17:59
Kahn's topological sort in Clojure
;; Copyright (c) Alan Dipert. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns alandipert.kahn
(:require [clojure.set :refer [difference union intersection]]))
@jboner
jboner / latency.txt
Last active November 15, 2024 14:00
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@benbalter
benbalter / gist.md
Last active October 15, 2024 15:32
Example of how to embed a Gist on GitHub Pages using Jekyll.

Here's an example of how to embed a Gist on GitHub Pages:

{% gist 5555251 %}

All you need to do is copy and paste the Gist's ID from the URL (here 5555251), and add it to a gist tag surrounded by {% and %}.

@timyates
timyates / logic.groovy
Last active December 23, 2015 12:59
A miniKanren in Groovy blatantly copied from https://github.com/funjs/friebyrd
import groovy.transform.*
//////////////////////////////////////
// Testing
//////////////////////////////////////
new MiniKanren().with {
// for a given 'q' and 'r'
def (q,r) = [ lvar( 'q' ), lvar( 'r' ) ]
@debasishg
debasishg / gist:8172796
Last active November 11, 2024 07:10
A collection of links for streaming algorithms and data structures

General Background and Overview

  1. Probabilistic Data Structures for Web Analytics and Data Mining : A great overview of the space of probabilistic data structures and how they are used in approximation algorithm implementation.
  2. Models and Issues in Data Stream Systems
  3. Philippe Flajolet’s contribution to streaming algorithms : A presentation by Jérémie Lumbroso that visits some of the hostorical perspectives and how it all began with Flajolet
  4. Approximate Frequency Counts over Data Streams by Gurmeet Singh Manku & Rajeev Motwani : One of the early papers on the subject.
  5. [Methods for Finding Frequent Items in Data Streams](http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.187.9800&rep=rep1&t
@gerritjvv
gerritjvv / clojure async channel bridge
Created December 31, 2013 16:58
Simple thing to do, but requires repeated typing. The only thing it does is move from channel-a to channel-b. This function is implemented in https://github.com/gerritjvv/fun-utils
(require '[clojure.core.async :refer [chan go >! <! >!! <!!]])
(require '[clojure.core.async :as async])
(defn chan-bridge
([ch-source map-f ch-target]
"map map-f onto ch-source and copy the result to ch-target"
(chan-bridge (async/map map-f [ch-source]) ch-target))
([ch-source ch-target]
"in a loop read from ch-source and write to ch-target
this function returns inmediately and returns the ch-target"
@rm-hull
rm-hull / blocks.cljs
Last active January 2, 2016 06:19
Core.async example from Timothy Baldridge's Clojure/Conj 2013 talk: http://youtu.be/enwIIGzhahw, demonstrating 4800 'green' threads. Code modified from: https://github.com/halgari/clojure-conj-2013-core.async-examples/blob/master/src/clojure_conj_talk/core.clj#L585
(ns clojure-conj-talk.core
(:use [enchilada :only [canvas ctx canvas-size]]
[monet.canvas :only [fill-style fill-rect]]
[jayq.core :only [show]])
(:require [cljs.core.async :refer [<! >! chan timeout]])
(:require-macros [cljs.core.async.macros :as m :refer [go]]))
(def colors
(rand-nth [
[
@schwarzmx
schwarzmx / .bash_profile
Created April 7, 2014 14:32
multiple JDKs - Mac OS X
alias usejava6='export JAVA_HOME=$(/usr/libexec/java_home -v 1.6) ; PATH=$JAVA_HOME/bin:$PATH'
alias usejava7='export JAVA_HOME=$(/usr/libexec/java_home -v 1.7) ; PATH=$JAVA_HOME/bin:$PATH'
alias usejava8='export JAVA_HOME=$(/usr/libexec/java_home -v 1.8) ; PATH=$JAVA_HOME/bin:$PATH'
@timyates
timyates / pisystem.groovy
Last active July 23, 2018 13:27
Pi Approximation With Akka and Groovy
@Grab( 'com.typesafe.akka:akka-actor_2.10:2.3.2' )
@Grab( 'com.typesafe:config:1.2.0' )
import groovy.transform.Immutable
import akka.actor.ActorRef
import akka.actor.ActorSystem
import akka.actor.Props
import akka.actor.UntypedActor
import akka.actor.UntypedActorFactory
import akka.routing.RoundRobinRouter
import scala.concurrent.duration.Duration