Skip to content

Instantly share code, notes, and snippets.

View halan's full-sized avatar
🛹

Halan Pinheiro halan

🛹
View GitHub Profile
@halan
halan / gist:567583fd8f7fb0219b8323ebca5eab62
Created March 13, 2022 15:05 — forked from e1024kb/gist:41bf38fdb1a2cb19a781
Country - state list in JSON
{
"countries": [
{
"country": "Afghanistan",
"states": ["Badakhshan", "Badghis", "Baghlan", "Balkh", "Bamian", "Daykondi", "Farah", "Faryab", "Ghazni", "Ghowr", "Helmand", "Herat", "Jowzjan", "Kabul", "Kandahar", "Kapisa", "Khost", "Konar", "Kondoz", "Laghman", "Lowgar", "Nangarhar", "Nimruz", "Nurestan", "Oruzgan", "Paktia", "Paktika", "Panjshir", "Parvan", "Samangan", "Sar-e Pol", "Takhar", "Vardak", "Zabol"]
},
{
"country": "Albania",
"states": ["Berat", "Dibres", "Durres", "Elbasan", "Fier", "Gjirokastre", "Korce", "Kukes", "Lezhe", "Shkoder", "Tirane", "Vlore"]
},
@halan
halan / ca.md
Created March 25, 2021 17:00 — forked from soarez/ca.md
How to setup your own CA with OpenSSL

How to setup your own CA with OpenSSL

For educational reasons I've decided to create my own CA. Here is what I learned.

First things first

Lets get some context first.

const reduce = (reducer, initial, [head, ...tail]) =>
head // condition to go or stop
? reduce(reducer, reducer(initial, head), tail) // recursion
: initial // stop
const map = (mapper, [head, ...tail]) =>
head // condition to go or stop
? [ mapper(head), ...map(mapper, tail) ] //recursion
: [] // stop
@halan
halan / lens.js
Created March 23, 2020 11:53
A pure lens implementation strongly based on ramda implementation, made to teaching my internships at Codeminer42.com
o = { user: { name: 'foo' } }
const get = key => obj => obj[key]
const set = key => (x, obj) =>
({ ...obj, [key]: x })
Identity = v => ({
value: v,
@halan
halan / catamorphism.js
Created March 23, 2020 12:18
Catamorph structure
Loop = (value, {x, y}) => ({
value: value,
cata: mapping =>
x > y
? value
: Loop(mapping(value, x), {x: x + 1, y})
.cata(mapping)
});
console.log(
@halan
halan / monads.js
Last active March 13, 2020 14:51
Example of monads to manage validations
// base
const Valid = x => ({
map: f => Valid(f(x)),
chain: f => f(x),
bimap: ({valid}) => Valid(valid(x)),
cata: ({valid}) => valid(x)
})
const Wrong = x => ({
@halan
halan / fantasyland.js
Last active February 21, 2020 20:01
Fantasy Land // based on the specs described here https://github.com/fantasyland/fantasy-land
// Setoid
a.equals(a) === true // reflexivity
a.equals(b) === b.equals(a) // summetry
a.equals(b) && b.equals(c) == q.equals(c) // transitivity
// Ord
// must also implement the Setoid
a.lte(b) || b.lte(a) === true // totality
{ "_id" : { "$oid" : "50747679c863c75a39000000" }, "cols" : [ { "news" : [ { "ref_id" : "233636", "type" : "noticia", "imag" : "104328", "perm" : "/noticia/pp-e-o-campeao-de-votos-na-eleicao-para-vereador/233636", "titl" : "PP é o campeão de votos na eleição para vereador", "chap" : "Política", "suti" : "", "styl" : "direita" } ] }, { "news" : [ { "ref_id" : "233638", "type" : "noticia", "perm" : "/noticia/candidatos-estao-em-busca-de-apoios-para-o-2o-turno/233638", "titl" : "Candidatos estão em busca de apoios para o 2º turno", "chap" : "Política", "suti" : "", "styl" : "direita" } ] }, { "news" : [ { "ref_id" : "233660", "type" : "noticia", "perm" : "/noticia/resultado-da-eleicao-em-quatro-cidades-sera-alterado/233660", "titl" : "Resultado da eleição em quatro cidades será alterado", "chap" : "Política", "suti" : "", "styl" : "esquerda" } ] } ] }
{ "_id" : { "$oid" : "5074767bc863c75a39000001" }, "cols" : [ { "news" : [ { "ref_id" : "233636", "type" : "noticia", "imag" : "104328", "perm" : "/noticia/pp-e-o-
@halan
halan / accounting.sql
Created August 8, 2018 21:32 — forked from 001101/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@halan
halan / decode.md
Created March 12, 2017 03:26 — forked from yang-wei/decode.md
Elm Json.Decode tutorial and cheatsheet

When receiving JSON data from other resources(server API etc), we need Json.Decode to convert the JSON values into Elm values. This gist let you quickly learn how to do that.

I like to follow working example code so this is how the boilerplate will look like:

import Graphics.Element exposing (Element, show)
import Task exposing (Task, andThen)
import Json.Decode exposing (Decoder, int, string, object3, (:=))

import Http