Skip to content

Instantly share code, notes, and snippets.

View 28's full-sized avatar
🌴

Dejan Josifović 28

🌴
View GitHub Profile
@28
28 / pretty-spit.clj
Last active June 29, 2022 21:09
A simple way to pretty print Clojure data/code to a file.
(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)
@28
28 / partition.js
Created February 19, 2019 14:26
Multiple implementations of partition function in JavaScript.
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);
}
(defn maze [n]
(->> (repeatedly (* n n) #(rand-nth "╱╲"))
(partition n)
(transduce
(comp
(map #(apply str %))
(interpose "\n"))
str)))
@28
28 / change_mac_address.sh
Created January 9, 2019 21:32
Change your MAC address to a random value
#!/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
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)
@28
28 / ConditionalComposedProducer.java
Last active October 8, 2019 16:13
A construct that replaces multiple if x ==/!= null statements in a row when trying to produce a value of the same type in different ways.
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
@28
28 / prime_numbers_fun.clj
Last active November 8, 2016 10:03
A collection of all things for prime numbers that are fun...
(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)
@28
28 / write-stream-to-file.clj
Last active October 20, 2016 10:27
A code snippet for reading stream and writting to file.
(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)))))))