Skip to content

Instantly share code, notes, and snippets.

View metruzanca's full-sized avatar

Sam Zanca metruzanca

View GitHub Profile
@metruzanca
metruzanca / 401k-contribution-calculator.ipynb
Created May 11, 2023 18:16
Starting a new job in the middle of a calendar year? Want to max out employer contribution match? Use this.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@metruzanca
metruzanca / goAsync.ts
Created May 3, 2023 15:02
Inspired by Golang's error handling, using typescript's to provide a type safety without try-catch blocks.
type Error = { type: 'error'; error: any; };
type Success<R> = { type: 'success'; data: R; };
/**
* No more try catch blocks
*
* Inspired by {@link [Golang's error handling](https://gabrieltanner.org/blog/golang-error-handling-definitive-guide)}
* using typescript's {@link [narrowing](https://www.typescriptlang.org/docs/handbook/2/narrowing.html)}
* to provide a type-safe DX.
*
@metruzanca
metruzanca / onChange-proxy.js
Created February 13, 2023 18:24
Using Proxy API to detect a change in an object and calling a function after the update.
function onChange(data, callback) {
return new Proxy(data, {
set(target, prop, value) {
target[prop] = value;
callback(target, value);
return true;
}
});
}
{
"$schema": "https://solid-resume.vercel.app/schema.json",
"meta": {
"canonical": "https://gist.github.com/metruzanca/751361e5ba58ad06f361ebd430ae6e10",
"version": "v1.0.0",
"lastModified": "2025-03-06T14:56:49.946Z",
"theme": "actual"
},
"basics": {
"name": "Samuele Zanca",
@metruzanca
metruzanca / goErrors.ts
Last active March 10, 2022 07:42
Async/Await error handling using a golang inspired pattern.
const isPromise = <T = any>(promise: any): promise is Promise<T> => promise.constructor.name === 'Promise'
type Error = {
type: 'error';
error: any;
};
type Success<R> = {
type: 'success';
@metruzanca
metruzanca / readme.md
Last active August 14, 2021 00:43
Nodejs create release script

Usage

  1. Install dependencies
npm i -D inquirer chalk exec-sh ts-node
  1. Add this structure to your package.json and include all file paths that have a version key that you want to modify.

This assumes version key in the first level of the jsons.

Rip, CORS in discord's console :(

This doesn't work, like I feared.

Usage

Paste this into the discord console

fetch("https://api.github.com/gists/81b426f83604964ad6935b99693eec97")
  .then(d => d.json())
 .then(d =&gt; eval(d.files['tally.js'].content))
const fs = require('fs');
const meta = require('./config.json')
// Cannot use classes for some reason. Using prototypal inheritance
module.exports = function Fs({tp, cwd = process.cwd()}) {
if(!tp) return 'tp is required for Fs'
this.tp = tp
this.vaultRoot = cwd + meta.vault.path
/**
FROM python:3.8-slim
# Install dependencies: ffmpeg & git
RUN apt-get -y update; \
apt-get -y upgrade; \
apt-get install -y ffmpeg; \
apt-get install -y git
# Manual install ytmdl (https://github.com/deepjyoti30/ytmdl)
RUN pip install setuptools; \
@metruzanca
metruzanca / typescript-react-gatsby.code-snippets
Last active December 29, 2020 02:31
VSCode Snippets I use
{
"Gatsby Function Component": {
"prefix": "gfc",
"body": [
"import React from \"react\"",
"import { useStaticQuery, graphql } from \"gatsby\"",
"",
"// import {} from './styles'",
"",
"interface Props {",