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
package main | |
import ( | |
"fmt" | |
"io" | |
"io/ioutil" | |
"log" | |
"sync" | |
) |
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
function Animal(name) { | |
this.name = name; | |
} | |
Animal.prototype = { | |
weight: 0, | |
eat: function() { | |
console.log("Animal is eating!"); | |
} | |
} |
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 gen-uniq-rand-seq | |
[n gen-elem-fn] | |
(loop [xs (java.util.ArrayList.) x (gen-elem-fn)] | |
(cond | |
(= n (count xs)) xs | |
(some #(= % x) xs) (recur xs (gen-elem-fn)) | |
:else (do | |
(.add xs x) | |
(recur xs (gen-elem-fn)))))) |
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
import java.io.IOException; | |
import java.net.InetSocketAddress; | |
import java.net.ServerSocket; | |
import java.nio.ByteBuffer; | |
import java.nio.channels.SelectionKey; | |
import java.nio.channels.Selector; | |
import java.nio.channels.ServerSocketChannel; | |
import java.nio.channels.SocketChannel; | |
import java.util.Iterator; | |
import java.util.Set; |
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
#include <stdio.h> | |
#include <string.h> | |
int main(void) { | |
char pw[8] = "pass"; | |
char in[8]; | |
while (1) { | |
scanf("%s", in); | |
if (strcmp(in, pw) == 0) { | |
printf("yes\n"); |
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 class ClhSpinLock { | |
private final ThreadLocal<Node> pred; | |
private final ThreadLocal<Node> node; | |
private final AtomicReference<Node> tail = new AtomicReference<Node>(new Node()); | |
public ClhSpinLock() { | |
this.node = new ThreadLocal<Node>() { | |
protected Node initialValue() { | |
return new Node(); | |
} |
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
(import '[java.io PushbackReader]) | |
(defn make-name [f] | |
(str "memo/" (clojure.string/replace (str f) #" " "") "-memo-function.clj")) | |
(defn- open-memo-file [name] | |
(let [name (make-name name)] | |
(try | |
(with-open [r (clojure.java.io/reader name)] | |
(read (PushbackReader. r))) |
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
import itertools | |
import functools | |
def min(x): | |
fn = lambda lst: int(''.join(map(str, lst))) | |
return fn(functools.reduce(lambda x,y: fn(x) < fn(y) and x or y, itertools.permutations(x))) | |
print(min([9,12,34])) |
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
(for [col (partition-by #(> (second %) 0) (map-indexed vector lst)) | |
:when (every? #(> (second %) 0) col)] | |
[(count col) [(first (first col)) (first (last col))]]) | |
;user> ([3 [3 5]] [8 [11 18]] [7 [24 30]] [6 [36 41]]) |