Skip to content

Instantly share code, notes, and snippets.

View fxg42's full-sized avatar

François-Xavier Guillemette fxg42

View GitHub Profile
@fxg42
fxg42 / maybe.js
Last active March 9, 2023 18:44
Do-notation for the Maybe monad implemented in JavaScript with a generator function
//
// Simplified (and mostly incorrect) definition of the Maybe monad.
//
class Maybe { }
class Nothing extends Maybe { }
class Just extends Maybe {
constructor(v) {
@fxg42
fxg42 / optional.ex
Last active January 21, 2022 12:48
Maybe monad with an Elixir macro dsl
defmodule Optional do
defmacro __using__(_opts) do
quote do
require unquote(__MODULE__)
import unquote(__MODULE__)
end
end
def unit(nil), do: {:err, nil}
def unit(value), do: {:ok, value}
@fxg42
fxg42 / flow-4.png
Last active September 9, 2021 19:01
8 implementations of the same pipeline in JavaScript
flow-4.png
@fxg42
fxg42 / api
Last active April 9, 2021 11:41
Bash script used to call HTTP/JSON api
#!/usr/bin/env bash
CURL=$(which curl)
if [[ ! -x "${CURL}" ]]; then
echo "Missing dependency. Please install curl (https://formulae.brew.sh/formula/curl):
$ brew install curl" 1>&2
exit 1
fi
readonly PROGRAM=$(basename -- $0)
@fxg42
fxg42 / index.js
Last active July 31, 2019 16:46
Create key from UTF-8 string
const { asKey } = require('./utils');
const text = {
"520407a476092ac19c671e1e75d052bd": "i18n!",
};
const gettext = (str) => text[asKey(str)] || str
console.log(gettext("Iлtèrnåtïonɑlíƶatï߀ԉ")); //=> "i18n!"
console.log(gettext("Autre chose!")); //=> "Autre chose!"
@fxg42
fxg42 / github-mvc-es209.js
Created July 17, 2019 15:39
INF5190 - Exemple d'une application MVC
class Model {
constructor() {
this.userCollection = [ ]
this.selectedUser = null
this.listeners = {
'selectedUser': [ ],
'userCollection': [ ]
}
}
@fxg42
fxg42 / chart.groovy
Created December 14, 2011 00:34
JFreeChart with Kendo style
@Grab('org.jfree:jfreechart:1.0.14')
import java.awt.*
import java.awt.geom.*
import java.io.*
import java.text.*
import org.jfree.chart.*
import org.jfree.chart.annotations.*
import org.jfree.chart.axis.*
import org.jfree.chart.block.*
import org.jfree.chart.labels.*
@fxg42
fxg42 / connect-jmx.jsh
Last active April 2, 2018 18:15
JShell script to connect to JMX server
import javax.management.*
import javax.management.remote.*
var serverUrl = "service:jmx:rmi:///jndi/rmi://0.0.0.0:9090/jmxrmi"
var connection = JMXConnectorFactory.connect(new JMXServiceURL(serverUrl)).getMBeanServerConnection()
var objectName = new ObjectName("my-domain:type=my-bean-type,name=my-bean-name")
var pingResult = (int) connection.invoke(objectName, "ping", null, null) // Assumes an `int ping()` method that returns the error code.
/exit pingResult
@fxg42
fxg42 / wsd.coffee
Created December 10, 2012 18:32
build urls for websequencediagrams.com
qs = require 'querystring'
diagram = """
title Foo bar baz
a -> b: do b.m()
b -> c: do c.m()
"""
baseUrl = "http://www.websequencediagrams.com/cgi-bin/cdraw"
@fxg42
fxg42 / split.py
Created October 14, 2017 12:58
Split a youtube soundtrack into multiple files. Requires youtube-dl, ffmpeg and python3
import sys
import re
import subprocess
import os
#
# Usage:
# $ youtube-dl -f 140 https://www.youtube.com/watch?v=Iq0xfewozjw
# $ python3 split.py <input file name>.m4a tracks.txt
#