Skip to content

Instantly share code, notes, and snippets.

@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![] }
}
@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"

Arch linux setup

Instalando Rust

paru -S rustup
rustup default stable

Instalando paru

@evaporei
evaporei / enable_usb_device.sh
Created February 26, 2019 16:50
Script to make USB device work on Linux
device_info_output="$(lsusb | grep $1)"
device_info_array=($device_info_output)
bus_number="${device_info_array[1]}"
device_number="${device_info_array[3]::-1}"
echo "${bus_number}"
echo "${device_number}"
@evaporei
evaporei / config.yml
Created January 10, 2019 21:29
Circle CI sample workflow
version: 2
jobs:
one:
docker:
- image: circleci/ruby:2.4.1
steps:
- checkout
- run: echo "A first hello"
- run: sleep 25
two:
@evaporei
evaporei / promise.all.js
Created October 8, 2018 13:36
How promise.all rejection works
const resolvable200 = () => new Promise((resolve, reject) => {
console.log('resolvable200 begin')
resolve(200)
console.log('resolvable200 end')
})
const rejectable400 = () => new Promise((resolve, reject) => {
console.log('rejectable400 begin')
reject(400)
console.log('rejectable400 end')
@evaporei
evaporei / Dockerfile
Created June 25, 2018 03:43
graceful-shutdown/Dockerfile
FROM node:alpine
COPY package.json package.json
COPY server.js server.js
RUN npm install
EXPOSE 8000
@evaporei
evaporei / package.json
Created June 25, 2018 03:38
graceful-shutdown/package.json
{
"name": "graceful-shutdown",
"version": "1.0.0",
"description": "Example of graceful shutdown of web server! :)",
"main": "server.js",
"scripts": {
"start": "node server.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
@evaporei
evaporei / express-with-graceful.js
Created June 25, 2018 02:59
graceful-shutdown/express-with-graceful.js
const express = require('express')
const app = express()
app.get('/wait', (req, res) => {
console.log('Started wait!')
setTimeout(() => {
res.send('Done!')
console.log('Done!')
@evaporei
evaporei / express-without-graceful.js
Last active June 25, 2018 02:50
graceful-shutdown/express-without-graceful.js
const express = require('express')
const app = express()
app.get('/wait', (req, res) => {
console.log('Started wait!')
setTimeout(() => {
res.send('Done!')
console.log('Done!')