Skip to content

Instantly share code, notes, and snippets.

View collardeau's full-sized avatar
🏠
Working from home

Thomas Collardeau collardeau

🏠
Working from home
View GitHub Profile
@collardeau
collardeau / demo.svelte
Last active September 8, 2023 16:59
Svelte: SweetAlert2 setup
<script>
import Swal from "sweetalert2";
// npm i sweetalert2@9.7.2
// https://sweetalert2.github.io/
</script>
<!-- a simple alert -->
<button
on:click={() => {
Swal.fire('hello sweet alert');
@collardeau
collardeau / demo.svelte
Created February 21, 2020 18:05
Svelte: RoughJS setup
<script>
import rough from "roughjs/bin/rough";
// npm i roughjs@4.0.4
// https://roughjs.com/
let roughSvg;
function action(node) {
roughSvg = rough.svg(node);
class Box {
constructor(x) {
this.value = x;
}
static of(x) {
return new Box(x);
}
log() {
console.log(this.value);
}
@collardeau
collardeau / script.js
Last active November 10, 2015 11:25
Intro To FP Concepts, Part 3
// functor factory
const right = {
of: val => functor(right, val),
fmap: function(f){
return right.of(f(this.val));
}
}
const left = {
@collardeau
collardeau / script.js
Last active November 6, 2015 14:27
Intro To FP Concepts, part2
const Maybe = val => {
return {
val: val,
fmap: function(fn) {
if(this.val === null) return Maybe(null);
return Maybe(fn(this.val));
}
}
};
@collardeau
collardeau / script.js
Last active October 24, 2015 10:21
JYpLEY
const Maybe = val => ({
val,
fmap(f) {
if(this.val === null || this.val === undefined) return Maybe(null);
return Maybe(f(this.val));
}
});
const getFirstName = maybeName => maybeName.fmap(name => name.split(" ")[1]);
const getFirstLetter = maybeString => maybeString.fmap(string => string[0]);
// Standalone ES6 composition mentions "person" twice
const getFirstInitial = person => getFirstLetter(getFirstName(person))
// vs. Ramda's pipe composition
const firstInitial = pipe(getFirstName, getFirstLetter);
@collardeau
collardeau / func.js
Last active October 23, 2015 19:20
func-js-01
const getFirstName = person => person.split(" ")[1]; // second word
const getFirstLetter = string => string[0]; // first letter
const getFirstInitial = person => {
return getFirstLetter(getFirstName(person)); // nested function!
}
// try it
getFirstInitial("Doc Emmett Brown"); // "E"
const getFirstName = maybeName => maybeName.fmap(name => name.split(" ")[1]);
const getFirstLetter = maybeString => maybeString.fmap(string => string[0]);
const Maybe = val => ({
val,
fmap(f) {
if(this.val === null) return Maybe(null);
return Maybe(f(this.val));
}
});
// lets create some containers with our Maybe factory
let user = Maybe("Slacker George McFly");