This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(ring). | |
-export([start/3]). | |
-export([loop/1, loop/2]). | |
start(N, M, Message) when N > 1 -> spawn(fun() -> ring(N-1, M, Message) end). | |
ring(N, M, Message) when M > 0 -> | |
P = lists:foldl(fun(_, Proc) -> spawn(fun() -> loop(Proc) end) end, self(), lists:seq(1, N)), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(generic_server). | |
-export([start/0, loop/2]). | |
-export([request/1, change_state/1, change_function/1]). | |
%% Server | |
start() -> | |
register(?MODULE, spawn(?MODULE, loop, [2, fun erlang:'+'/2])). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LazyList { | |
private Closure list | |
private LazyList(list) { | |
this.list = list | |
} | |
static LazyList nil() { | |
new LazyList( {-> []} ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
/** | |
* Usage: ./SolrExporter.groovy query url [url] | |
* | |
* ./SolrExporter.groovy "id:12345" "http://your.solr.host:8983/solr/core/" | |
* | |
* ./SolrExporter.groovy "id:12345" "http://old.solr.host:8983/solr/core/" "http://new.solr.host:8983/solr/core/" | |
* | |
* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import zlib | |
import json | |
import pymongo | |
import sys | |
URL = 'http://api.stackoverflow.com/1.1' | |
ANSWERS = URL + '/questions/{0}/answers' | |
def load_url(url): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
cd /opt/zookeeper/zookeeper | |
rm -rf cluster | |
mkdir -p cluster/server{1,2,3}/{conf,data,logs} | |
cp conf/log4j.properties cluster/server1/conf/ | |
cp conf/log4j.properties cluster/server2/conf/ | |
cp conf/log4j.properties cluster/server3/conf/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; https://github.com/ndpar/clojure/blob/master/src/dojo/poker.clj | |
; https://github.com/ndpar/clojure/blob/master/test/dojo/poker_test.clj | |
(defn card-ranks | |
"Return a vector of the ranks, sorted with higher first" | |
[hand] | |
(let [ranks (map #(->> % first str (.indexOf "--23456789TJQKA")) hand) | |
ranks (vec (sort > ranks))] | |
(if (= [14 5 4 3 2] ranks) [5 4 3 2 1] ranks))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;; Inspired by SICP, chapter 5.2.2, and | |
;; https://www.youtube.com/watch?v=SrKj4hYic5A | |
(define (rzip c1 c2) | |
(let iter ([a c1] [z c2] [receive (λ (x y) y)]) | |
(if (null? a) | |
(receive z '()) | |
(iter (cdr a) z |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-syntax-rule | |
(redefine (f args ...) body ...) | |
(set! f (λ (args ...) body ...))) | |
(define (double x) | |
(+ x x)) | |
(redefine (double x) | |
(* 2 x)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Y = { f -> | |
{ x -> x(x) } { x -> f { y -> x(x)(y) } } | |
} | |
def triangular = Y { f -> | |
{ n -> n == 0 ? 0 : n + f(n - 1) } | |
} | |
triangular(3000) |
OlderNewer