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
| (require '[clojure.pprint :as pp] | |
| '[clojure.edn :as edn]) | |
| (def collection-to-print {:a 1 | |
| :b 2 | |
| :c 3 | |
| :d [1 2 3 4 5]}) | |
| (defn pretty-spit | |
| [file-name collection] | |
| (spit (java.io.File. file-name) |
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
| function partition(array, partitionSize) { | |
| if (partitionSize >= array.length) | |
| return array; | |
| var result = []; | |
| var partition = []; | |
| for (var i = 0; i < array.length; i++) { | |
| if (partition.length < partitionSize) { | |
| partition.push(array[i]); | |
| console.log(partition); | |
| } |
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
| (defn maze [n] | |
| (->> (repeatedly (* n n) #(rand-nth "╱╲")) | |
| (partition n) | |
| (transduce | |
| (comp | |
| (map #(apply str %)) | |
| (interpose "\n")) | |
| str))) |
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 bash | |
| a=$(ifconfig en0 | grep ether | sed -e 's/^[[:space:]]*ether//') | |
| echo "Current MAC address:$a" | |
| r=$(openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//') | |
| echo "New MAC address: $r" | |
| echo $r | xargs sudo ifconfig en0 ether |
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 numpy as np | |
| class NeuralNetwork: | |
| def __init__(self, x, y): | |
| self.input = x | |
| self.weights1 = np.random.rand(self.input.shape[1],4) | |
| self.weights2 = np.random.rand(4,1) | |
| self.y = y | |
| self.output = np.zeros(self.y.shape) |
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 java.util.function.Predicate; | |
| import java.util.function.Supplier; | |
| import java.util.stream.Stream; | |
| public class ConditionalComposedProducer { | |
| /** | |
| * Takes a variable number of {@code {@link Supplier}}s that supply the same | |
| * nullable type {@code T} and a {@code {@link Predicate}}. | |
| * Iterate through all {@code {@link Supplier}}s and applies the predicate |
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 is-prime? | |
| (memoize | |
| (fn [^Number num] | |
| ^Boolean | |
| (cond | |
| (<= num 1) false | |
| (<= num 3) true | |
| (or (zero? (mod num 2)) (zero? (mod num 3))) false | |
| :else (reduce #(if (<= (* %2 %2) num) | |
| (reduced true) |
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
| (defn write-to-file | |
| [stream file-name] | |
| (let [buff (byte-array 1024)] | |
| (with-open [os (java.io.FileOutputStream. (java.io.File. file-name))] | |
| (loop [] | |
| (let [size (.read stream buff)] | |
| (when (> size 0) | |
| (.write os buff 0 size) | |
| (recur))))))) |