Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing on https://github.com/AppsFlyer/aerospike-clj

Ido Barkan barkanido

🎯
Focusing on https://github.com/AppsFlyer/aerospike-clj
View GitHub Profile
@barkanido
barkanido / setup-neovim-ubuntu.txt
Created Oct 19, 2020
a working neovim setup on Ubuntu + clojure dev env
View setup-neovim-ubuntu.txt
# tested on ubuntu 20.04
Install NeoVim
install a JDK (8/11 is fine) (I use azul)
install lein (a Clojure build tool)
sudo apt install nodejs git curl nvim python3-pip npm clang
sudo npm install -g neovim
pip3 install --upgrade pynvim jedi msgpack black
pip install --upgrade pynvim jedi msgpack
clone Clojure language server (clone https://github.com/snoe/clojure-lsp and run the install_clojure_lsp script.
View records.clj
(defprotocol Talker
(talk [this msg]))
(defrecord Hero
[name type position health objects]
Talker
(talk [this msg]
(println (:name this) ":" msg)))
(->Hero "Bad Guy" :warrior {:x 11 :y 344} 93 [:sword :dagger])
View clojure-map2.clj
{:type :sword
:name "excalibur"
:strength 50
:weight 40}
View simple-map.clj
{:type :warrior
:name "Bad guy"
:position {:x 11 :y 344}
:health 93
:objects [:sword :dagger]}
View mixed-data.clj
[1
"a string"
{"a-map-key" [42]}
['("this" "is" "a" "list" "of" "strings")]
#{\a \b}
]
@barkanido
barkanido / data-flow1.clj
Last active Dec 26, 2019
a simple clojure function
View data-flow1.clj
(defn foo [a b]
(let [x (+ a b)]
x))
(def result (foo 3 4))
result
@barkanido
barkanido / match_example.clj
Created May 13, 2019
beware of clojure.core.match
View match_example.clj
(match/match [a b]
[_ true] :first
[true false] :second
[_ false] :third)
(try
(cond
(= b true) :first
(= b false) (try
(cond
@barkanido
barkanido / DateTimeFormatter.java
Created Apr 2, 2019
multi fprmatter (parser) for timstamps in java 8 time aPI
View DateTimeFormatter.java
import java.time.LocalDateTime;
import java.time.ZonedDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;
import java.time.temporal.ChronoField;
public class Main {
@barkanido
barkanido / core.clj
Last active Mar 10, 2019
testing url query string parsing in clojure
View core.clj
(ns toy-url-decoder.core
(:require [cemerick.url :as c-url]
[criterium.core :as crit])
(:import [java.net URI URL]
[io.netty.handler.codec.http QueryStringDecoder]
[java.nio.charset Charset]
[org.apache.http.client.utils URLEncodedUtils]
[org.apache.http NameValuePair]
[java.util List Map Map$Entry]))
View transcoder-get.clj
user=> (aero/put c "index" "set-name" 42 1000)
<< … >>
user=> (defn inc-transcoder [rec] (when rec
#_=> (update rec :payload inc)))
#'user/inc-transcoder
user=> (d/chain (aero/get-single c "index" "set-name" {:transcoder inc-transcoder})
#_=> :payload
#_=> println)
<< … >>
43