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 / encode-url-preserve-macro.clj
Created April 16, 2018 11:52
Encode url and preserve macro
(defn- encoded-macros-map
[macros]
(->> macros
(map (fn [macro]
[(codec/url-encode macro) macro]))
(into {})))
(defn- macro-decoder
[macros-map s]
(reduce (fn [acc [escaped-macro macro]]
$ lein repl
Exception in thread "main" java.lang.ExceptionInInitializerError
at clojure.main.<clinit>(main.java:20)
Caused by: java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkState(ZLjava/lang/String;Ljava/lang/Object;)V, compiling:(closure.clj:100:1)
at clojure.lang.Compiler$DefExpr.eval(Compiler.java:470)
at clojure.lang.Compiler.eval(Compiler.java:7067)
at clojure.lang.Compiler.load(Compiler.java:7514)
at clojure.lang.RT.loadResourceScript(RT.java:379)
at clojure.lang.RT.loadResourceScript(RT.java:370)
at clojure.lang.RT.load(RT.java:460)
@piotr-yuxuan
piotr-yuxuan / gist.md
Created March 23, 2018 19:55
Non-standard PostgreSQL clause RETURNING

I stumbled upon a rather uncommon feature of PostgreSQL recently, namely, clause RETURNING. Let's say I have a database which contains a table products. I needed to copy some products directly in SQL, and then to invoke a function with the ids of both the old and the new products (for some side-effects irrelevant here).

At first I felt quite confident that a simple INSERT would do the job, but how to get the new ids in the most elegant way? As the doc states:

INSERT conforms to the SQL standard, except that the RETURNING clause is a PostgreSQL extension

So here it is:

INSERT INTO products (name,
@piotr-yuxuan
piotr-yuxuan / gitflow-breakdown.md
Created March 23, 2018 16:31 — forked from JamesMGreene/gitflow-breakdown.md
A comparison of using `git flow` commands versus raw `git` commands.

Initialize

gitflow git
git flow init git init
  git commit --allow-empty -m "Initial commit"
  git checkout -b develop master

Connect to the remote repository

File /var/folders/0w/wdz5xrr9505_qs_0c49npdcc0000gn/T/com.apple.dt.XCTest/IDETestRunSession-5FA9BD83-ED86-4301-A220-AA3BBF0B277E/FutureAppTests-BC28F6DF-4026-4464-B9D8-2F7B10C9617D/Session-FutureAppTests-2018-02-09_191615-Eme9Bz.log
19:16:15.698 xcodebuild[50950:1216444] Beginning test session FutureAppTests-4AFD66E0-4F23-4D5A-9EEF-D41D0018197B at 2018-02-09 19:16:15.698 with Xcode 9C40b on target <DVTiPhoneSimulator: 0x7fc423412c40> {
SimDevice: iPhone 6 (C32AE35F-AC5D-486C-B37A-2F27D98B70A3, iOS 11.2, Booted)
} (11.2 (15C107))
19:16:15.699 xcodebuild[50950:1216444] /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild
-workspace
native/ios/FutureApp.xcworkspace
-scheme
FutureApp
(require '[graph-fnk-viz :as viz] ;; git clone https://github.com/RedBrainLabs/graph-fnk-viz then lein install
'plumbing.graph
;; Namespaces of graphs
'…)
(def graphs
"Would be wonderful if these graphs would be programmatically found with static code analysis.
So we could run this snippet once in a while and store files in a doc/."
['…])
@piotr-yuxuan
piotr-yuxuan / fizzbuzz.md
Last active May 5, 2020 13:56
FizzBuzz test

Assignment:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

First, explicit solution. The one wich I immediately conceive when hearing at the problem.

(for [x (range 1 (inc 100))]
  (cond
    (and (zero? (mod x 3)) (zero? (mod x 5))) "FizzBuzz"
@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

@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 / 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