Skip to content

Instantly share code, notes, and snippets.

View viebel's full-sized avatar

Yehonathan Sharvit viebel

View GitHub Profile
@viebel
viebel / join-arrays.js
Created April 15, 2021 05:17
Joining arrays in JavaScript (like in SQL)
function joinArrays(a, b, keyA, keyB) {
var mapA = _.keyBy(a, keyA);
var mapB = _.keyBy(b, keyB);
var mapsMerged = _.merge(mapA, mapB);
return _.values(mapsMerged);
}
var dbBookInfos = [
{
"isbn": "978-1982137274",
@viebel
viebel / progcat.md
Last active March 31, 2021 04:46
Programming languages categorization

| | Object-Oriented | Functional |
|----- | ----- | | | Statically-typed | Java
C#
C++ | OCaml
Haskell
Scala | | Dynamically-typed | Ruby Python | JavaScript Clojure Erlang Elixir |

function setVerbatim (obj, k, v) {
// In Lodash, a dot in a key is interpreted as a nesting object
// For instance, _.set({}, "a.b", 2) returns {"a": {"b": 2}}
// While setVerbatim({}, "a.b", 2) returns {"a.b": 2}
return _.merge(obj, {[k]: v})
}
function flattenObject(obj, prefix = '') {
return _.reduce(obj,
function(acc, v, k) {
@viebel
viebel / protocol-do.clj
Last active November 26, 2020 14:32
Protocol and records in a DO compliant way
(defprotocol FullName
(full-name [person]))
(defrecord AuthorEncapsulation [firstname lastname]
FullName
(full-name [author] (str (:firstname author)
" "
(:lastname author))))
(defrecord AuthorData [firstname lastname])
(ns simple.core
(:require
[reagent.core :as reagent :refer-macros [with-let]]
[reagent.dom :refer [render]]))
(def my-org
{:name "nestle"
:description "bla bla bla"
:children [{:name "Choco"
:description "woo"}
(ns simple.core
(:require [reagent.core :as reagent]
[reagent.dom :refer [render]]))
(defn ui []
[:div
[:h1 "Hello world"]])
(defn fizzbuzz-clean [n]
(let [fizzes (cycle ["" "" "Fizz"])
buzzes (cycle ["" "" "" "" "Buzz"])
words (map str fizzes buzzes)
numbers (map str (rest (range)))]
(take n (map choice words numbers))))
(require '[clojure.walk :refer [prewalk postwalk]])
(def data {:a 1
:b {:c 2}
:d [3 {:e 4}]})
;; prewalk: node -> map f to children of f(node)
;; prewalk: [a b c] -> (map f (f [a b c]))
;; prewalk: transform node and then transform chilren
@viebel
viebel / README.md
Last active July 30, 2020 17:42 — forked from mfikes/README.md

Self-hosted:

$ plk
ClojureScript 1.10.597
cljs.user=> (require '[foo.core :refer [defnmy]])
nil
cljs.user=> (defnmy FOO clojure.string/lower-case [x]
       #_=>   (inc x))
#'cljs.user/foo
(defn vec->matrix [n v]
(->> v
(partition n)
(mapv vec)))
(defn empty-vec [n]
(into [] (repeat n nil)))
(defn rand-numbers [n k]
(->> (range n)