Skip to content

Instantly share code, notes, and snippets.

View piotr-yuxuan's full-sized avatar
💣
Breaking things, carefully

胡雨軒 Петр piotr-yuxuan

💣
Breaking things, carefully
View GitHub Profile
@piotr-yuxuan
piotr-yuxuan / .hyperterm.js
Last active September 25, 2016 18:21
hyperterm settings
module.exports = {
config: {
// default font size in pixels for all tabs
fontSize: 14,
// font family with optional fallbacks
fontFamily: '"Fira Code", Menlo, "DejaVu Sans Mono", "Lucida Console", monospace',
// terminal cursor background color and opacity (hex, rgb, hsl, hsv, hwb or cmyk)
cursorColor: 'rgba(100,255,229,0.75)',
@piotr-yuxuan
piotr-yuxuan / read-effective-structure.clj
Last active May 24, 2016 23:45
read effective structure
(def firsts
'((rand-nth [:a :b :c])
(rand-nth ["TW" "DE" "UK" "FR" "US" "JP"])
(rand-nth [:bob :alice :charles :georges :matz :is :nice])))
(def key-length 2)
(def sample-depth 300)
(def sample
(->> (repeat (+ key-length 2) '(rand-int 10))
@piotr-yuxuan
piotr-yuxuan / core-logic-chess-mock.clj
Created January 27, 2016 05:08
How to use clojure functions in core.logic?
;; I have defined a function, let's call it modifier, which has a
;; specific logic inside. I want core.logic to deal with it in order to
;; find the correct parameters for this function to output the
;; result I want.
;; Let's define two states. The goal is to find out how to go from the
;; depart state to the arrival one. These states are not that very
;; difficult structures, they're basically maps.
(def depart-state {:a {:a 1 :c 4} :b {:a 2 :b 3 :c 6} :c 3})
(def arrival-state {:a {:a 1 :b 2 :c 4} :b {:a 2 :b 3 :c 6} :c 3})
@piotr-yuxuan
piotr-yuxuan / math-and-simple-call-in-core-logic.clj
Created January 16, 2016 16:10
Learning try-and-diy: how can I simplify this example?
(ns firstshot.chessknightmove
(:refer-clojure :exclude [== >= <= > < =])
(:use clojure.core.logic
clojure.core.logic.arithmetic))
(defn knight-moves
"Returns the available moves for a knight (on a 8x8 grid) given its current position."
[x y]
(let [xmax 8 ymax 8]
(run* [q]
@piotr-yuxuan
piotr-yuxuan / regex-for-hex-range.clj
Last active August 29, 2015 14:27
Draft for Clojure implementation of the handy algorithm published here: http://utilitymill.com/utility/Regex_For_Range
(ns regex-for-hex-range
(:use clojure.test))
(defn dec-to-hex
[number]
(clojure.string/upper-case (format "%x" number)))
(defn hex-to-dec
[string]
(let [conversion-table (zipmap
@piotr-yuxuan
piotr-yuxuan / .clj
Created July 23, 2015 12:27
Buggy Clojure assoc-in implementation
(defn my-assoc-in
"Implement built-in assoc-in in the way I get it. It nicely inserts a value in the nested map and doesn't overwrite."
[map keys value]
(let [[k & keys] (reverse keys)]
(loop [[key & keys] keys
final map
initial (assoc {} k value)]
(if (not (empty? keys))
(recur keys
final
We couldn’t find that file to show.