Skip to content

Instantly share code, notes, and snippets.

View yogthos's full-sized avatar
🤷‍♂️

Dmitri Sotnikov yogthos

🤷‍♂️
View GitHub Profile
(ns bloom.core
(:require [com.github.kyleburton.clj-bloom
:refer [make-optimal-filter
optimal-n-and-k
make-permuted-hash-fn
make-hash-fn-crc32
add!
include?]])
(:import [java.util BitSet]))
@yogthos
yogthos / html_pdf.clj
Created July 7, 2014 15:36
HTML to PDF example
(ns html-pdf
(:require [clojure.xml :refer [parse]]
[clj-pdf.core :refer [pdf]]))
(def tag-map
{:html [{}]
:h1 [:paragraph {:leading 20 :style :bold :size 14}]
:h2 [:paragraph {:leading 20 :style :bold :size 12}]
:h3 [:paragraph {:leading 20 :style :bold :size 10}]
:hr [:line]
(ns noise)
(def distributions
{:uniform 1
:triangular 2
:bell 5})
(defn random-parametric [n bias]
(Math/pow
(/ (->> #(Math/random)
@yogthos
yogthos / gist:838a2ab5653835a30b8d
Last active August 29, 2015 14:11
Guestbook app

Creating a guestbook application

install the Leiningen build tool

wget https://raw.githubusercontent.com/technomancy/leiningen/stable/bin/lein
chmod +x lein

create a new project

@yogthos
yogthos / ascii_table.clj
Created March 5, 2015 16:02
ascii table renderer for clj-pdf table format
(ns ascii-table)
(defn transpose [m]
(apply mapv vector m))
(defn col-width [rows text-width]
(let [num-cols (-> rows first count)]
(int (/ (- text-width 2 (dec num-cols)) num-cols))))
(defn height [length width]
@yogthos
yogthos / tinyurl.clj
Created April 1, 2015 12:42
short unique ID generator
(def dict-16 [\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \A \B \C \D \E \F])
(def dict-32 [\1 \2 \3 \4 \5 \6 \7 \8 \9 \A \B \C \D \E \F \G \H \J \K \M \N \P \Q \R \S \T \U \V \W \X \Y \Z])
(def dict-64 [\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \Z \a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z])
(def dict-89 [\0 \1 \2 \3 \4 \5 \6 \7 \8 \9 \A \B \C \D \E \F \G \H \I \J \K \L \M \N \O \P \Q \R \S \T \U \V \W \X \Y \Z \a \b \c \d \e \f \g \h \i \j \k \l \m \n \o \p \q \r \s \t \u \v \w \x \y \z \+ \" \@ \* \# \% \& \/ \| \( \) \= \? \~ \[ \] \[ \} \$ \- \_ \. \: \space \, \; \< \>])
(defn encode [dict value]
(let [base (-> dict count str BigInteger.)]
@yogthos
yogthos / ui
Last active August 29, 2015 14:18
(def messages (atom ["message 1" "message 2" "message 3"]))
(defn side-bar []
(let [users (atom ["Bob" "Jane" "Alice"])
selected-user (atom nil)]
(fn []
[:ul.list-group
(into
[:ul]
(map
@yogthos
yogthos / gist:7b6ab07449d9b40abc5f
Created July 9, 2015 15:50
reagent dynamic lists/tables
(def doc (atom {:items ["foo" "bar" "baz"]
:table-items [["foo" "bar" "baz"]
["blah" "bleh" "blub"]]}))
(defn remove-at [v i]
(vec (into (subvec v 0 i) (subvec v (inc i) (count v)))))
(defn list-field []
[:div
[:ul
@yogthos
yogthos / regex-text.clj
Created August 24, 2015 18:07
ClojureScript re-find and clojure.string/replace inconsistency
;;Clojure
(re-find #"(?i)ol" "HOLA")
;=>"OL"
(clojure.string/replace "HOLA" #"(?i)ol" "EY")
;=>"HEYA"
;;ClojureScript
(re-find #"(?i)ol" "HOLA")
;=>"OL"
(clojure.string/replace "HOLA" #"(?i)ol" "EY")
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferStrategy;
import java.awt.image.ImageObserver;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class Mandelbrot extends Canvas implements ImageObserver {