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
We couldn’t find that file to show.
@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
@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 / 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 / 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 / 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 / .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 / box-keywords-to-int.cljs
Last active December 3, 2016 01:51
Just an attempt to get rid of keys like :1, :2, :3, etc.
;; We have a problem because of json serialisation / deserialisation: in its
;; narrow way, when a map keyed with integers is sent over the network, the
;; deserialised result contains keys like :1, :234, which are integers
;; represented by keywords. There are good reasons to this but we also have
;; good reasons to find integers are more properly represented by numbers.
;;
;; There can be numerous ways to avoid this problem. The first one here is
;; very narrow and focus on our mere goal: box keys to integers.
(defn- deep-key-cast
@piotr-yuxuan
piotr-yuxuan / ClojureScript tooling.md
Last active May 9, 2017 13:01
ClojureScript tooling with BinaryAge's wonders + flexsurfer's re-frisk + IntelliJ

What is this about?

What it changes

  • Re-frisk Visualize re-frame pattern data or reagent ratom data as a tree structure, watch re-frame events and export state in the debugger
  • Dirac A Chrome DevTools fork for ClojureScript developers
  • BinaryAge custom formatters for ClojureScript

Awesome stuff

@piotr-yuxuan
piotr-yuxuan / README.md
Last active May 23, 2017 13:32
Mere attempt for an idiomatic way to populate app-db with data from the outter world in re-frame

Mere attempt for an idiomatic way to populate app-db with data from the outter world in re-frame

This is a short code snippet from a pet project I used to have fun with five or six months ago. It may not work as I just pasted code from it but I hope it shows the main ideas.

What is this gist for

This gist takes as granted you know the documentation of re-frame. It give an example to this part of the documentation: subscribing to external data Poke me if you want help about it.

What this gist contains