Skip to content

Instantly share code, notes, and snippets.

View jprudent's full-sized avatar
🦋
Chasing butterflies

Jérôme Prudent jprudent

🦋
Chasing butterflies
View GitHub Profile
@jprudent
jprudent / functionalWay.scala
Last active February 17, 2023 16:02
Using Type Classes to Solve the Expression Problem
// you can't modify shipped code
object VendorLib {
trait Json
case class JsonString(get: String) extends Json
case class JsonObject(get: Map[String, Json]) extends Json
case class JsonArray(get: List[Json]) extends Json
@jprudent
jprudent / gist:aee4f4d0f9eba64110565bed6c73cfb5
Created February 10, 2023 08:55
extension-problem-functional-way.sc
import VendorLib.JsonString
// rules :
// 1) You can't change VendorLib
// 2) You can't change UserCode
// 3) Type safety
object VendorLib {
sealed trait Json
case class JsonString(s: String) extends Json
case class JsonArray(a: Seq[Json]) extends Json
//> using lib "org.scalameta::munit:1.0.0-M6"
//@annotation.tailrec
def fib(n: Int): Int =
if (n == 0) 0
else if (n == 1) 1
else fib(n - 1) + fib(n - 2)
def fib2(n: Int): Int =
@annotation.tailrec
@jprudent
jprudent / Function_syntax.clj
Last active September 22, 2022 15:48
Functions (clojure) example
;; no arguments
(fn [] (println "Hello"))
;; one argument
(fn [s] (println s))
;; two arguments
(fn [x y] (+ x y))
;; with type hint
@jprudent
jprudent / ambiant.rb
Created March 11, 2022 15:45
Ambiant music for sonic-pi
use_bpm 89
def tl(name)
in_thread(name: name) do
loop do
send(name)
end
end
end
@jprudent
jprudent / random_album.js
Last active February 21, 2022 13:24
Play random album on deezer
/*
This is semi-automated (read quick & dirty, didn't polished) way to play a random album on Deezer
You need to navigate to the fav albums page, press F12 and past this gist in the console.
*/
(async function() {
for(let i = 0; i< 500; i++) {
window.scrollTo(0, document.body.scrollHeight);
await new Promise(r => setTimeout(r, 2));
}
var playBtn = document.querySelectorAll('button.action-item-btn[aria-label=\'Pause\']');
@jprudent
jprudent / dub.rb
Created February 19, 2022 18:21
Sonic Pi - Dub
use_bpm 128
tpb = 60 / 128.0
chord_trigg = [0, 0,1,0]
kick_trigg = [1, 0,0,0]
snare_trigg = [1, 0 ,0,0]
bass_trigg = [0,1, 0 ,1]
ks = [:kick, :snare]
define :orchestrator do
cue ks.tick(:ks) if kick_trigg.tick(:kick) > 0
@jprudent
jprudent / Oblique strategies
Created January 13, 2022 04:10
Oblique strategies
["A line has two sides", "Abandon desire", "Abandon normal instructions", "Accept advice", "Adding on", "Always the first steps", "Ask people to work against their better judgement", "Ask your body", "Be dirty", "Be extravagant", "Be less critical", "Breathe more deeply", "Bridges -build -burn", "Change ambiguities to specifics", "Change nothing and continue consistently", "Change specifics to ambiguities", "Consider transitions", "Courage!", "Cut a vital connection", "Decorate", "Destroy nothing; Destroy the most important thing", "Discard an axiom", "Disciplined self-indulgence", "Discover your formulas and abandon them", "Display your talent", "Distort time", "Do nothing for as long as possible", "Do something boring", "Do something sudden", "Do the last thing first", "Do the words need changing?", "Don't avoid what is easy", "Don't break the silence", "Don't stress one thing more than another", "Emphasize differences", "Emphasize the flaws", "Faced with a choice", "Find a safe part and use it as an anchor
@jprudent
jprudent / french.adventuron
Created October 14, 2021 20:25
Adventuron - Template français
######################################
# Adventuron en français #
######################################
start_at = plage
######################################
# Locations #
######################################
@jprudent
jprudent / reggaeish.rb
Created September 20, 2021 21:35
Some generated music with sonic-pi, reaggae like
use_bpm 128
tpb = 60 / 128.0
chord_trigg = [0, 0,1,0]
kick_trigg = [1, 0,0,0]
snare_trigg = [1, 0 ,0,0]
bass_trigg = [0,1, 0 ,1]
ks = [:kick, :snare]
define :orchestrator do