Skip to content

Instantly share code, notes, and snippets.

@evaporei
evaporei / Example.hs
Last active May 8, 2019 02:26
Haskell help, pattern match list of variants
data Alphabet = A Int | B Float | C String
cool :: [Alphabet] -> Bool
cool [] = error "Should not call `cool` with empty list"
cool alphabetList = case alphabetList of
[A] -> coolInt alphabetList
[B] -> coolFloat alphabetList
[C] -> coolString alphabetList
_ -> error "Shouldn't call `cool` with list of different variants"
@evaporei
evaporei / byte_array_state_machine.rs
Created May 8, 2019 04:03
How to parse array of bytes using a state machine (in Rust!)
struct State {
step: Step,
data: Vec<u8>,
}
impl State {
pub fn new() -> Self {
Self { step: Step::Initial, data: vec![] }
}

Aulas de JS

Tópicos a serem abordados

  • Tipos de variáveis, escopo e closures (var, let, const, escopos function e {})
  • Tipos e coerção (Boolean, null, undefined, Number, String, Object, Symbol e tabela de coerção)
  • this, prototypes e classes
  • Assincronia (event loop, setTimeout, setInterval, setImmediate, process.nextTick, Promise, function*, coroutines e async await)
@evaporei
evaporei / group-by-without-ramda.js
Created May 28, 2019 23:16
Group by without Ramda
const data = [
{
category: 'action',
value: 'jorgs'
},
{
category: 'comedy',
value: 'lucians'
},
{
@evaporei
evaporei / ugly-typescript-monoid.ts
Last active September 13, 2019 19:07
Ugly TypeScript Monoid
class MyNumber extends Number implements Monoid<MyNumber> {
public x: Number;
constructor(x: Number) {
super(x)
this.x = x;
}
toString(): string {
return this.x.toString()
}
@evaporei
evaporei / linkedin-accept-invites.js
Created July 24, 2020 14:23
LinkedIn snippet for accepting all invites
document.querySelectorAll('ul.mn-invitation-list button.artdeco-button--secondary').forEach(btn => btn.click())
@evaporei
evaporei / contiguous-array-chunks.js
Last active October 11, 2021 14:23
JS contiguous array chunks
const getChunk = (arr, from, size) => {
const clampedFrom = (from + size) > arr.length
// Trying to get chunk bigger than end of array.
// Here we reduce `from` so that the chunk size is always preserved.
? arr.length - size
: from
return arr.slice(clampedFrom, from + size)
}
@evaporei
evaporei / boolean_algebra.js
Last active January 8, 2022 17:22
Boolean functions
const assert = require('assert')
function test(title, fn) {
try {
fn()
console.log(`✅ '${title}' test passed`)
} catch (error) {
console.error(`❌ '${title}' test failed`)
throw error
}
@evaporei
evaporei / xor.rs
Created January 8, 2022 18:40
Xor in Rust cause HDL sucks
struct In {
a: bool,
b: bool,
}
#[derive(Debug, PartialEq)]
struct Out {
out: bool,
}
@evaporei
evaporei / artblocks_error.rs
Created January 20, 2022 18:49
ArtBlocks Error
// Cargo.toml dependencies:
// hex = "0.4.3"
// ethabi = "16.0.0"
use ethabi::*;
use ethabi::ParamType::*;
use ethabi::StateMutability::*;
fn main() {