Skip to content

Instantly share code, notes, and snippets.

View moatorres's full-sized avatar
👋

Moa Torres moatorres

👋
View GitHub Profile
@moatorres
moatorres / cli.ts
Created May 6, 2025 13:30
Effect CLI
import { join } from 'path'
import { error, info, warn } from '@blog/utils'
import { Args, Command, Options } from '@effect/cli'
import { NodeContext, NodeRuntime } from '@effect/platform-node'
import { Console, Effect, Option, pipe } from 'effect'
const root = Args.text({ name: 'root' }).pipe(
Args.withDescription('Path to the project root directory')
)
@moatorres
moatorres / config.ts
Created May 2, 2025 14:35
Effect Config
import { resolve } from 'path'
import { NodeContext, NodeRuntime } from '@effect/platform-node'
import dotenv from 'dotenv'
import { Config, Effect, identity, Logger, LogLevel } from 'effect'
import { argv } from 'process'
const ENV_FILE = resolve(
process.cwd(),
`${argv[2]?.includes('.env') ? argv[2] : `${argv[2]}/.env`}`
@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,