This file contains 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
public interface IBufferPool | |
{ | |
byte[] TakeBuffer(int size); | |
void ReturnBuffer(byte[] buffer); | |
} | |
public class BufferPoolWithLeakDetection : IBufferPool | |
{ | |
public class MemoryLeakException : Exception | |
{ |
This file contains 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
(ns sort | |
(:use clojure.test)) | |
(defn qsort [xs] | |
"Sorts the specified sequence using the quick sort algorithm" | |
(if-let [[pivot & rest] (seq xs)] | |
(let [smaller? #(< % pivot)] | |
(lazy-cat (qsort (filter smaller? rest)) | |
[pivot] | |
(qsort (remove smaller? rest)))))) |
This file contains 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
# I want this method in ruby-core | |
def let | |
yield | |
end | |
def fib(i) | |
let do |n = 1, result = 0| | |
if i == -1 | |
result | |
else |
This file contains 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
public static class AsyncEnumerator | |
{ | |
// | |
// Asynchronously but sequentially executes all tasks returned by the specified enumerator. | |
// | |
public static Task Run(this IEnumerator<Task> source, | |
CancellationToken token = default(CancellationToken)) | |
{ | |
return runInternal<object>(source, token); |
This file contains 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
(defn commatize [n] | |
(->> n str reverse (partition-all 3) (interpose \,) flatten reverse (apply str))) |
This file contains 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 C | |
{ | |
static C() | |
{ | |
// Let's run the initialization on another thread! | |
var thread = new System.Threading.Thread(Initialize); | |
thread.Start(); | |
thread.Join(); | |
} | |
static void Initialize() { } |
This file contains 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 ^{:private true} not-nil? (comp not nil?)) | |
(defprotocol Matcher | |
"Protocol for types that can be used to search a Hiccup data structure." | |
(matches [this elem])) | |
(defn- comp-name [x y] | |
(and (not-nil? y) (= (name x) (name y)))) | |
(extend-protocol Matcher |
This file contains 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
type Partition[A] = List[List[A]] | |
def partitions[A](xs: List[A]): List[Partition[A]] = l match { | |
case Nil => Nil | |
case h :: Nil => List(List(List(h))) | |
case h :: t => | |
val ps = partitions(t) | |
ps.map(List(h) :: _) ::: ps.flatMap(interpolate(h, _)) | |
} |
This file contains 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
int conditional(int x, int y, int z) { | |
int nx = !x - 1; | |
return (nx & y) | (~nx & z); | |
} |
This file contains 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
nSumCombinations :: (Integral a) => Int -> a -> [a] -> [[a]] | |
nSumCombinations _ _ [] = [] | |
nSumCombinations 1 s xs = map (\x -> [x]) $ filter (== s) xs | |
nSumCombinations n s (x:xs) = (map (x:) $ nSumCombinations (n - 1) (s - x) xs) ++ (nSumCombinations n s xs) |