Skip to content

Instantly share code, notes, and snippets.

View lubien's full-sized avatar
💭
Teaching people 🔥🦩 LiveView 🔥🦩

Lubien lubien

💭
Teaching people 🔥🦩 LiveView 🔥🦩
View GitHub Profile
function convertToRoman(inputNum) {
var letters = ['I', 'V', 'X', 'L', 'C', 'D', 'M'];
var digits = String(inputNum).split('').reverse();
var roman = [];
for (var i = 0, length = digits.length; i < length; i++) {
var value = Number(digits[i]);
var splitStart = i * 3 - i;
local AppendLists in
fun {AppendLists L1 L2}
local Aux in
fun {Aux List Acc}
case List of
Head|Tail then {Aux Tail (Head | Acc)}
else Acc
end
end
{Aux {Reverse L1} L2}
@lubien
lubien / pin.ex
Last active November 28, 2016 07:26
defmodule Pinner do
def first do
case 10 do
# `x` sempre dá match porque sendo ele
# uma variável, representa-se que qualquer
# valor arbitrário pode ser aceito no caso
x ->
"x"
10 ->
"10"
@lubien
lubien / template.html
Created February 16, 2017 03:56
Promise races
<h1 id="page">No Page</h1>
<button data-page="Home" data-delay="1000">Home</button>
<button data-page="Users" data-delay="1500">Users</button>
<button data-page="Posts" data-delay="3000">Posts</button>
@lubien
lubien / promise-races-first.js
Created February 16, 2017 03:57
Promise races v1
const $page = document.getElementById('page')
const setPage = title => {
$page.innerText = title
}
const loadPage = (title, time) =>
new Promise(resolve =>
setTimeout(() => resolve(title), time)
)
@lubien
lubien / promise-races-second.js
Created February 16, 2017 03:59
Promise races
const $page = document.getElementById('page')
let currentPage = 'no-page'
const setPage = title => {
if (currentPage !== title) return;
$page.innerText = title
}
const loadPage = (title, time) =>
new Promise(resolve =>
@lubien
lubien / promise-races-third.js
Last active February 16, 2017 04:01
Promise races
const $page = document.getElementById('page')
let currentPage = 0
const setPage = title => {
$page.innerText = title
}
const loadPage = (title, time) =>
new Promise(resolve =>
setTimeout(() => resolve(title), time)
@lubien
lubien / promise-races-fourth.js
Last active February 16, 2017 13:31
Promise races
const $page = document.getElementById('page')
const router = {
listeners: [],
onPageChange(fn) {
this.listeners.push(fn)
}
}
@lubien
lubien / counter-one.js
Last active March 5, 2017 22:06
Teaching some FP to friends
var counter = 0
function count() {
return counter++
}
@lubien
lubien / show-me.js
Last active March 14, 2017 04:30 — forked from anabastos/show-me.js
/**
* Show Me the Evens - Show me the Odds
* Diana is learning to count and she just learned the difference between odds and even numbers.
* She wants to have some fun, so she picks a random number.
* If that number is even, she decides to count all the even numbers up to it starting from 0 up to (but not including) the input.
* If not, she decides to count all the odd numbers up to that number starting from 1 (but not including) the input.
**/
function counting(x){
return [...Array(x).keys()]