Skip to content

Instantly share code, notes, and snippets.

@quux00
quux00 / stdin-acc.clj
Created October 2, 2012 02:31
Example of how to read from STDIN in a Clojure program and accumulate the entries in a vector.
(ns example.stdin)
(defn do-something-cool [v]
(println v))
(defn -main
"Read from STDIN"
[& args]
(println "Enter text:")
@quux00
quux00 / override-paredit-keybindings.el
Created August 18, 2012 00:17
Emacs: override paredit keybindings
;; override the default keybindings in paredit
(eval-after-load 'paredit
'(progn
(define-key paredit-mode-map (kbd "<M-right>") 'paredit-forward-slurp-sexp)
(define-key paredit-mode-map (kbd "<M-left>") 'paredit-forward-barf-sexp)
(define-key paredit-mode-map (kbd "<C-right>") nil)
(define-key paredit-mode-map (kbd "<C-left>") nil)))
@quux00
quux00 / TryOutInterProcessMutex.java
Last active April 9, 2021 15:50
Test of ZK Curator InterProcessMutex
package quux00.curator;
import java.util.Collection;
import java.util.Iterator;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.apache.curator.RetryPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
@quux00
quux00 / search-google.go
Created January 5, 2013 01:56
Fake google search example in Go using concurrent Go routines pushing to a common Go channel. From Rob Pike's Google IO 2012 presentation: http://www.youtube.com/watch?v=f6kdp27TYZs&feature=youtu.be and adapted from Alexey Kachayev's transcription of Pike's slides: https://gist.github.com/3124594#file-go-channels-7-search-go
package main;
import (
"fmt"
"math/rand"
"time"
)
var (
Web1 = fakeSearch("web1")
@quux00
quux00 / knuth.go
Last active February 13, 2019 10:33
Knuth Fisher-Yates shuffle for Go (golang)
// implements Knuth or Fisher-Yates shuffle
package knuth
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UTC().UnixNano())
@quux00
quux00 / stdin.clj
Created October 2, 2012 02:01
Example of how to read from STDIN in a Clojure program
(ns example.stdin)
(defn -main
"Read from STDIN"
[& args]
(println "Enter text:")
(loop [input (read-line)]
(when-not (= ":done" input)
(println (str "You entered: >>" input "<<"))
@quux00
quux00 / concPrimeSieve.go
Created January 12, 2013 17:57
Implementation of a prime sieve using a series of cascading Go channels building on each to filter out non-primes. From: http://play.golang.org/p/9U22NfrXeq
package main
// A concurrent prime sieve
// from: http://play.golang.org/p/9U22NfrXeq
// Send the sequence 2, 3, 4, ... to channel 'ch'.
func Generate(ch chan<- int) {
for i := 2; ; i++ {
ch <- i // Send 'i' to channel 'ch'.
}
@quux00
quux00 / hof-reordered.rs
Last active January 4, 2016 21:19
Hof in Rust
fn double(a: int) -> int { a * 2 }
fn ntimes(f: proc(int) -> int, times: int) -> proc(int) -> int {
proc(x: int) {
match times {
0 => { x },
_ => { f(ntimes(f, times - 1)(x)) } // swap the order relative to the original example
}
}
}
use std::io::File;
use std::str;
fn main() {
let file_name_abs = ~"foo";
let mut response =~ "";
match File::open(&Path::new(file_name_abs)) {
Some(html_file) => {
let mut html_file_mut = html_file;
@quux00
quux00 / telephonic-whispers-with-maxprocs.go
Created January 26, 2014 17:15
Telephonic whispers with GOMAXPROCS set in Go.
package main
import (
"fmt"
"runtime"
)
func whisper(left, right chan int) {
left <- 1 + <- right
}