Skip to content

Instantly share code, notes, and snippets.

# https://gist.github.com/martinos/1076522bb326cc19b68978ac6227d4c3
require "fn_reader"
class Object
def _(fn)
fn.(self)
end
end
module HashFn
@martinos
martinos / data_fns.rb
Last active June 1, 2021 15:41
Collections of lambda for processing data in a functionnal way
class Object
def _(fn)
fn.(self)
end
end
module DataFn
class DoubleEntries < StandardError
end
@martinos
martinos / minimal_build_rust.md
Last active February 6, 2019 14:36 — forked from ihrwein/README.md
Building minimal Rust containers with Docker multi stage builds

The built image for a hello world project is less than 8 MB.

Builder image (it'd be best to upload this image to Docker Hub. This is 100% percent reusable).

FROM ubuntu:latest

ENV TARGET=x86_64-unknown-linux-musl
ENV BUILD_DIR=/src/target/x86_64-unknown-linux-musl/release/

Display input names with Boostrap 3

If you have tooltips installed you can display all the form input names, by pasting this snippet in the console.

$("form :input").each(function(index, elm) { $(elm).tooltip({title: elm.name, trigger: "manual"}).tooltip('toggle')});

Display input names with Boostrap 3

If you have tooltips installed you can get display all the form input names, by pasting this snippet in the console.

var items = $("form :input").map(function(index, elm) {
    $(elm).tooltip({title: elm.name, trigger: "manual"}).tooltip('show');
    return {name: elm.name, type:elm.type, value: $(elm).val()};
});
friend = hash_of.(name: scalar,
family: hash_of.(name: scalar),
hobbies: array_of.(scalar))
user = hash_of.({ name: scalar,
emails: array_of.(scalar),
friends: array_of.(friend)})
my_hash = {name: "Martin", emails: ["chabotm@gmail.com"], friends: [{name: "Bob", family: {name: "Joe"}, hobbies: ["Golf", "Ping Pong"]}]}
Benchmark.measure { 100_000.times { user.(my_hash)} }
@martinos
martinos / monoids.ex
Last active December 5, 2022 00:02
Monoid examples in elixir
defmodule Monoid do
defmacro __using__(_opts) do
quote do
def concat([head|tail]) do
append(head, concat(tail))
end
def concat([]) do
empty
@martinos
martinos / foo_test.rb
Created March 22, 2017 15:22 — forked from xymbol/foo_test.rb
Inspired by "FP Concepts" talk by @martinosis at Ruby Montreal.
require "minitest/autorun"
module Foo
class << self
attr :add, :sub, :mul, :div
end
@add = -> (a, b) { a + b }.curry
@sub = -> (a, b) { a - b }.curry
@mul = -> (a, b) { a * b }.curry
@martinos
martinos / foo_test.rb
Created March 22, 2017 15:22 — forked from xymbol/foo_test.rb
Inspired by "FP Concepts" talk by @martinosis at Ruby Montreal.
require "minitest/autorun"
module Foo
class << self
attr :add, :sub, :mul, :div
end
@add = -> (a, b) { a + b }.curry
@sub = -> (a, b) { a - b }.curry
@mul = -> (a, b) { a * b }.curry
12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890