Skip to content

Instantly share code, notes, and snippets.

View moatorres's full-sized avatar
👋

Moa Torres moatorres

👋
  • 16:39 (UTC -03:00)
View GitHub Profile
@moatorres
moatorres / interceptor.ts
Created November 6, 2023 22:43
Interceptor Decorator
/**
* Interceptor interface for intercepting method calls, requests, responses, process, and errors.
*/
export interface Interceptor {
before?(...args: any[]): Promise<void> | void
after?<T>(result: T, ...args: any[]): Promise<void> | void
error?(error: Error, ...args: any[]): Promise<void> | void
shouldThrow?: boolean
}
[
{
"code": 100,
"name": "Continue",
"enum": "CONTINUE",
"reference": {
"info": "RFC 7231, Section 6.2.1",
"url": "https://tools.ietf.org/html/rfc7231#section-6.2.1"
},
"description": "The server has received the request headers and the client should proceed to send the request body",
@moatorres
moatorres / proxyTrack.js
Created July 24, 2022 19:28 — forked from mrharel/proxyTrack.js
Using Proxy to Track Javascript Class
const callerMap = {};
function getCaller(error) {
if (error && error.stack) {
const lines = error.stack.split('\n');
if (lines.length > 2) {
let match = lines[2].match(/at ([a-zA-Z\-_$.]+) (.*)/);
if (match) {
return {
name: match[1].replace(/^Proxy\./, ''),
@moatorres
moatorres / remove-docker.sh
Created March 21, 2022 13:56
Docker Removal (macOSX)
#!/bin/bash
sudo rm -Rf /Applications/Docker.app
sudo rm -f /usr/local/bin/docker
sudo rm -f /usr/local/bin/docker-machine
sudo rm -f /usr/local/bin/com.docker.cli
sudo rm -f /usr/local/bin/docker-compose
sudo rm -f /usr/local/bin/docker-compose-v1
sudo rm -f /usr/local/bin/docker-credential-desktop
sudo rm -f /usr/local/bin/docker-credential-ecr-login
@moatorres
moatorres / Member.ts
Last active March 19, 2022 18:33
Sequelize + Typescript Setup
module.exports = (sequelize: any, DataTypes: any) => {
const Member = sequelize.define(
'member',
{
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
allowNull: false,
primaryKey: true,
},
@moatorres
moatorres / styled-components.spec.tsx
Created November 5, 2021 20:23
Get styles applied by `styled-components` with `jest` and `react-test-renderer`
import { getStyles } from './test-helpers'
describe('styled-components', () => {
test('extended components keep their styles', () => {
const Box = styled.div`
margin: 16px;
`
const Card = styled(Box)`
color: tomato;
`
@moatorres
moatorres / Option.js
Created June 27, 2021 14:22
Option monad in JS/Node (without classes)
import { isValid } from './utils'
const OptionType = {
Some: Symbol(':some'),
None: Symbol(':none'),
}
const makeSome = (val) => ({
type: OptionType.Some,
isSome: () => true,
@moatorres
moatorres / Result.js
Last active June 27, 2021 13:50
Result monad in JS/Node (without classes)
const makeReadOnly = (value) => Object.freeze(value)
const ResultType = {
Ok: Symbol(':ok'),
Err: Symbol(':err'),
}
const Ok = (val) => makeReadOnly({
type: ResultType.Ok,
isOk: () => true,
@moatorres
moatorres / List.js
Last active June 27, 2021 13:50
List type in JS/Node (without classes)
export const List = (x) => ({
emit: () => x,
head: () => x[0],
tail: () => List.of(x.splice(1)),
last: () => x[x.length - 1],
chain: (f) => x.map(f),
map: (f) => List.of(x.map(f)),
inspect: () => `List(${x})`,
concat: (a) => List.of(x.concat(a))
})
@moatorres
moatorres / Tuple.d.ts
Last active June 27, 2021 13:50
Tuple type in JS/Node (without classes)
interface ITuple<F, S> {
fst(): F
snd(): S
toArray(): [F, S]
unwrap(): [F, S]
toJSON(): [F, S]
inspect(): string
toString(): string
equals(other: ITuple<F, S>): boolean
bimap<F2, S2>(f: (fst: F) => F2, g: (snd: S) => S2): ITuple<F2, S2>