Skip to content

Instantly share code, notes, and snippets.

View brunoti's full-sized avatar
🎸

Bruno Oliveira brunoti

🎸
View GitHub Profile
@brunoti
brunoti / tryCatch.ts
Created August 14, 2022 21:53
Ramda tryCatch in pure TS
type AnyFunction = (...args: any[]) => any
/**
* `R.tryCatch` takes two functions, a `tryer` and a `catcher`.
* The returned function evaluates the `tryer`;
* if it does not throw, it simply returns the result.
* If the `tryer` does throw,
* the returned function evaluates the `catcher` function and returns its result.
*
* @note For effective composition with this function,
@brunoti
brunoti / index.js
Last active March 17, 2022 19:26
monads
const fn = {};
const __ = (window.global || window);
__.fn = fn;
/**
* Pipe function
*
* @param {*} initial - Initial value
* @param {...Function} functions - Pipe functions
*
@brunoti
brunoti / .nginx
Created April 4, 2021 21:54
[nginx proxy pass] #nginx #deploy
location / {
proxy_pass http://localhost:8080;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
@brunoti
brunoti / tutorial.md
Created April 4, 2021 21:40
[node js production ubuntu] #javascript #node #ubuntu #deploy

Install Node.js LTS, Yarn, and other deps

curl -fsSL https://deb.nodesource.com/setup_14.x | sudo -E bash -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt update
sudo apt install -y yarn nodejs nginx
@brunoti
brunoti / expect-values.js
Last active April 4, 2021 22:29
expect values #javascript #tests
expect(fn)
.toHaveBeenCalledWith(expect.anything())
.toHaveBeenCalledWith(expect.any(constructor))
.toHaveBeenCalledWith(expect.arrayContaining([ values ]))
.toHaveBeenCalledWith(expect.objectContaining({ props }))
.toHaveBeenCalledWith(expect.stringContaining(string))
.toHaveBeenCalledWith(expect.stringMatching(regexp))
@brunoti
brunoti / my-anime-tosho-hack.js
Created July 13, 2019 21:09
my anime tosho hack
const Maybe = folktale.maybe
const Result = folktale.result
const noop = () => {}
const { href: current } = document.location
const { compose, ifElse, any, curry, split, head, map, complement, allPass, is, chain, find, mapObjIndexed, type } = R
const stringIncludes = curry((neddles, haystack) => any(neddles, n => haystack.includes(n)))
const findByClass = className => Array.from(document.getElementsByClassName(className))
const safeContextQuery = curry((query, el) => Maybe.fromNullable(el.querySelector(query)))
const safeContextQueryMany = curry((query, el) => Array.from(el.querySelectorAll(query)))
const safeFindById = id => Maybe.fromNullable(document.getElementById(id))
@brunoti
brunoti / StorageCollection.js
Last active April 4, 2021 21:52
collection abstraction for local storage
import uuid from 'an-uuid';
import {find, filter, findIndex} from 'lodash';
class Collection {
constructor(schema, collection = [], clearFirst) {
this.schema = schema;
if(clearFirst) {
this.clear();