View gist:6385704
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 FILES "abcdefgh") | |
(def RANKS (range 1 9)) | |
(def squares (for [f FILES r RANKS] {:file f :rank r :name (str f r)})) | |
(defn opposite-color [col] (if (= col :light) :dark :light)) | |
(defn alternate-colors [start-with] | |
(lazy-seq (cons start-with (alternate-colors (opposite-color start-with))))) | |
(def file-first-square-color (take 8 (alternate-colors :dark))) |
View cartesian_product.clj
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
(defmacro product [xs dim] | |
"Creates a dim dimension cartesian product of the xs sequence. | |
For example (product \"ab\" 3) returns ((a a a) (b a a) (a b a) ...)" | |
(let [syms (take dim (repeatedly gensym)) | |
seq-expr (vec (interleave syms (repeat xs))) | |
body-expr (cons 'list syms)] | |
(list 'for seq-expr body-expr))) |
View gist:6431618
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 product | |
([] []) | |
([xs] (if (empty? xs) [] (seq xs))) | |
([xs & rest] | |
(for [x xs p (apply product rest)] (flatten (list x p))))) | |
(defn endless-product [xs] | |
(let [repeat-xs (map #(repeat % xs) (drop 1 (range)))] | |
(apply concat (map #(apply product %) repeat-xs)))) |
View codegen.py
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
""" | |
All credits to https://github.com/andreif/codegen/blob/master/codegen.py | |
Just quicly edited everything in place to transform python conditional expressions to their JS equivalent. | |
Scroll to the bottom of the file for examples. | |
""" | |
from ast import * | |
BINOP_SYMBOLS = {} |
View bash
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
docker run \ | |
-h 'squid' --net bridge -m 0b -p 3128:8000 \ | |
-d \ | |
-v /srv/squid:/data \ | |
-v /etc/localtime:/etc/localtime:ro \ | |
-e USE_ACL=0 \ | |
--name squid \ | |
--restart=always \ | |
muccg/squid-deb-proxy:latest |
View list_unused_security_groups.py
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
#!/usr/bin/env python | |
import boto3 | |
ec2 = boto3.resource('ec2') | |
FMT = '{sg.group_id},{sg.group_name},"{sg.description}"' |
View python_deep_eq.py
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
In [4]: l = [{'x': [254, 247, 230, 225, 222, 221, 231, 247, 281, 314, 381, 461, 487, 508, 517 | |
...: , 504, 460, 431, 380, 346, 318, 301, 305, 309, 328, 359, 400, 413, 438, 441, 447, 472 | |
...: , 490, 511, 519, 529, 529], 'y': [26, 25, 26, 28, 32, 37, 51, 58, 59, 56, 44, 34, 34, | |
...: 34, 35, 46, 60, 66, 75, 83, 91, 99, 101, 102, 105, 105, 105, 106, 110, 113, 116, 116 | |
...: , 116, 116, 116, 112, 107]}, {'x': [479], 'y': [123]}, {'x': [20, 24, 27, 34, 45, 48, | |
...: 51, 59, 67, 71, 76, 80, 97, 108], 'y': [46, 48, 51, 58, 69, 72, 75, 82, 86, 87, 88, | |
...: 89, 93, 96]}, {'x': [619, 619, 620, 620, 620, 620], 'y': [29, 37, 41, 50, 55, 64]}] | |
...: | |
In [5]: l2 = [{'x': [254, 247, 230, 225, 222, 221, 231, 247, 281, 314, 381, 461, 487, 508, 51 |
View george.clj
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 select-georges-wine [wines] | |
(condp = (count wines) | |
0 nil | |
1 (first wines) | |
(second (sort-by :price wines)))) | |
(def choose-wine (comp :name select-georges-wine)) |
View fizz_buzz.clj
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
;; First solution | |
(defn fizz-buzz-or-number | |
[x] | |
( | |
["FizzBuzz" x x "Fizz" x "Buzz" "Fizz" x x "Fizz" "Buzz" x "Fizz" x x] | |
(mod x 15))) | |
(defn fizz-buzz |
View eredmeny.txt
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
0 | |
2 4 | |
6 8 10 | |
12 14 16 18 | |
20 22 24 26 28 | |
30 32 34 36 38 40 | |
42 44 46 48 50 52 54 | |
56 58 60 62 64 66 68 70 | |
72 74 76 78 80 82 84 86 88 | |
90 92 94 96 98 100 102 104 106 108 |
OlderNewer