Skip to content

Instantly share code, notes, and snippets.

View marco-souza's full-sized avatar
🦕

Marco Antônio marco-souza

🦕
View GitHub Profile
@marco-souza
marco-souza / mod.ts
Created April 1, 2021 19:11
hello-world-deno-deploy
addEventListener("fetch", (event) => {
const response = new Response("Hello World!", {
headers: { "content-type": "text/plain" },
});
event.respondWith(response);
});
@marco-souza
marco-souza / useFetch.ts
Created August 8, 2020 01:32
JS/TS useFetch react hook
import { useState, useEffect } from "react";
export enum FetchStatus {
IDLE,
LOADING,
SUCCESS,
FAILURE,
CANCELED,
}
@marco-souza
marco-souza / sha256.ts
Created August 3, 2020 18:19
JS/TS Async SHA-256
async function sha256(message: string): Promise<string> {
// encode as UTF-8
const msgBuffer = new TextEncoder().encode(message);
// hash the message
const hashBuffer = await crypto.subtle.digest('SHA-256', msgBuffer);
// convert ArrayBuffer to Array
const hashArray = Array.from(new Uint8Array(hashBuffer));
// convert bytes to hex string
const hashHex = hashArray.map(b => ('00' + b.toString(16)).slice(-2)).join('');
return hashHex;
@marco-souza
marco-souza / sleep.ts
Created August 3, 2020 18:14
Async Sleep
const sleep = (ms: number): Promise<void> =>
new Promise(resolve => setTimeout(resolve, ms));
export default sleep;
@marco-souza
marco-souza / fileToBase64.ts
Created July 14, 2020 17:15
Convert File to Base64 in JavaScript/TypeScript
export const toBase64 = (file: File) =>
new Promise((resolve, reject) => {
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => resolve(reader.result);
reader.onerror = (error) => reject(error);
});
@marco-souza
marco-souza / main.di.ts
Created July 11, 2020 15:57
Typescript/Node Dependency Injector (DI) - Koa server sample
import * as Koa from "koa";
let koaInstance: Koa;
class AppInjector {
static injectApp() {
if (!koaInstance) {
koaInstance = new Koa();
koaInstance.use(async (ctx) => {
ctx.body = "Hello World";
@marco-souza
marco-souza / estrela.json
Created March 27, 2020 20:24
test lottie animation
{"v":"5.6.6","fr":24,"ip":0,"op":48,"w":1080,"h":1080,"nm":"Teste","ddd":0,"assets":[],"layers":[{"ddd":0,"ind":1,"ty":4,"nm":"Shape Layer 2","sr":1,"ks":{"o":{"a":1,"k":[{"i":{"x":[0.833],"y":[0.833]},"o":{"x":[0.167],"y":[0.167]},"t":22,"s":[0]},{"t":27,"s":[100]}],"ix":11},"r":{"a":1,"k":[{"i":{"x":[0.295],"y":[1.212]},"o":{"x":[0.721],"y":[-0.232]},"t":12,"s":[0]},{"t":38,"s":[720]}],"ix":10},"p":{"a":0,"k":[540.004,548.22,0],"ix":2},"a":{"a":0,"k":[-3.033,-50.04,0],"ix":1},"s":{"a":0,"k":[65.947,65.947,100],"ix":6}},"ao":0,"shapes":[{"ty":"gr","it":[{"ty":"sr","sy":1,"d":1,"pt":{"a":0,"k":5,"ix":3},"p":{"a":0,"k":[0,0],"ix":4},"r":{"a":0,"k":0,"ix":5},"ir":{"a":0,"k":100,"ix":6},"is":{"a":0,"k":0,"ix":8},"or":{"a":0,"k":262,"ix":7},"os":{"a":0,"k":0,"ix":9},"ix":1,"nm":"Polystar Path 1","mn":"ADBE Vector Shape - Star","hd":false},{"ty":"fl","c":{"a":0,"k":[1,0,0,1],"ix":4},"o":{"a":0,"k":100,"ix":5},"r":1,"bm":0,"nm":"Fill 1","mn":"ADBE Vector Graphic - Fill","hd":false},{"ty":"tr","p":{"a":0,"k":[-3.03
@marco-souza
marco-souza / structure.md
Created February 13, 2020 17:34
Podcast

Define a podcast minimal structure

Rules

  • Rule #1: should never more than 2 minutes of silence
  • pass emotion by voice
  • make 15 minutes blocks
    • 3 blocks gives you 45 minutes
  • use first 5-10 min for
@marco-souza
marco-souza / README.md
Last active February 1, 2020 17:26
Use external HD as Steam Storage Disk

Steam over an external HD

Why?

When you have small SSD disk, you can't be a gammer on linux :/

A simple way to solve that is to use this script to move you steam storage folter to an external HD, to install as many games as you want!

Usage

@marco-souza
marco-souza / FAQ.md
Last active July 17, 2020 07:14
React Testing Cookbook
  • Q: Makes sense to move useEffects to hooks which you have to load data? > A: I believe so. Every time I access a duck which loads external data, I'm interested in its data, not in calling a funciton to load it.