Skip to content

Instantly share code, notes, and snippets.

View Grohden's full-sized avatar
:shipit:
*tec tec tec noises*

Gabriel Rohden Grohden

:shipit:
*tec tec tec noises*
View GitHub Profile
@Grohden
Grohden / cuchi_morse.rb
Created March 17, 2022 04:12
morse code but with paulo cuchi
# frozen_string_literal: true
dot = 'cuchi'
dash = 'paulo'
# our tree is based on this image
# https://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Morse-code-tree.svg/1280px-Morse-code-tree.svg.png
$morse_tree = {
dot => {
char: 'e',
@Grohden
Grohden / pad_csv.js
Created February 25, 2022 18:45
Script to pad CSV columns (for readability)
const fs = require('fs');
const filterMap = (list, map) => {
const mapped = [];
for (let i = 0; i < list.length; i++) {
const transformed = map(list[i]);
if (transformed) {
mapped.push(transformed);
}
@Grohden
Grohden / barrel-file-info.js
Created November 23, 2021 19:27
Script that resolves all exports + paths from TS barrel files, meant to be used with babel-transform-imports
const fs = require('fs');
const path = require('path');
const ts = require('typescript');
/**
* Parses a barrel (index) file, extracts all it's export
* names and returns an object that maps
* a import name to the path + some meta infos.
*
@Grohden
Grohden / first-one.ts
Last active October 21, 2021 16:50
Collection of typescript type system issues or bugs that don't get caught by it.
type Foo = {
// Assigning undefined here is wrong.
// this value either HAVE A KEY WITH VALUE or DON'T HAVE A KEY
[key: string]: { foo: string }
// const foo: Foo = { key: undefined }
// 'key' in foo // true, but should never be the case, because if there's a key, there's a value.
}
// note: the only case where the index signature might be correctly represented
// is when we use a proxy, that way we can guarantee that we always return something
@Grohden
Grohden / short-cut-fusion.js
Last active October 6, 2021 14:40
simple impl of shortcut fusion(also called: deflorestation, stream fusion) using javascript generators
function* map(morphism, itr) {
let value;
while(value = itr.next().value) {
yield morphism(value);
}
}
function* filter(predicate, itr) {
let value;
@Grohden
Grohden / create-item.executor.ts
Last active July 21, 2021 13:41
Simple offline queue implementation for react native
import { createAsyncThunk } from '@reduxjs/toolkit';
import type { AppDispatch, RootState } from './my-store-file';
import { useAppDispatch } from './my-store-file';
import { useCallback } from 'react';
import { useOfflineExecutor } from './offline-executor';
import { createItem } from './create-item-slice.ts';
import { ItemService } from './services';
export type CreateItemThunkArg = {
@Grohden
Grohden / shrekd.dart
Created July 6, 2020 20:42
Shrek ascii art found somewhere on internet
// ⡴⠑⡄⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣤⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠸⡇⠀⠿⡀⠀⠀⠀⣀⡴⢿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠑⢄⣠⠾⠁⣀⣄⡈⠙⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⢀⡀⠁⠀⠀⠈⠙⠛⠂⠈⣿⣿⣿⣿⣿⠿⡿⢿⣆⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⢀⡾⣁⣀⠀⠴⠂⠙⣗⡀⠀⢻⣿⣿⠭⢤⣴⣦⣤⣹⠀⠀⠀⢀⢴⣶
// ⠀⠀⢀⣾⣿⣿⣿⣷⣮⣽⣾⣿⣥⣴⣿⣿⡿⢂⠔⢚⡿⢿⣿⣦⣴⣾⠁⠸⣼
// ⠀⢀⡞⠁⠙⠻⠿⠟⠉⠀⠛⢹⣿⣿⣿⣿⣿⣌⢤⣼⣿⣾⣿⡟⠉⠀⠀⠀⠀
// ⠀⣾⣷⣶⠇⠀⠀⣤⣄⣀⡀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
// ⠀⠉⠈⠉⠀⠀⢦⡈⢻⣿⣿⣿⣶⣶⣶⣶⣤⣽⡹⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠉⠲⣽⡻⢿⣿⣿⣿⣿⣿⣿⣷⣜⣿⣿⣿⡇⠀⠀⠀⠀⠀
@Grohden
Grohden / parallel_functions.py
Last active April 19, 2021 16:54
Promise.all like function for python running in threads
import concurrent.futures
from time import sleep
def expensive_computation(number):
sleep(10)
return number
class Runnable:
def __init__(self, original_target, *args, **kwargs):
self.original_target = original_target
{{>header}}
{{>part_of}}
class ApiClient {
ApiClient({this.basePath = '{{{basePath}}}'}) {
{{#hasAuthMethods}}
// Setup authentications (key: authentication name, value: authentication).
{{#authMethods}}
{{#isBasic}}
{{#isBasicBasic}}
_authentications[r'{{{name}}}'] = HttpBasicAuth();
@Grohden
Grohden / docs.json
Created November 26, 2020 03:07
Big treta com o openapi-generator
{
"openapi": "3.0.0",
"info": {
"title": "Foo",
"description": "Foo",
"version": "1.0",
"contact": {}
},
"tags": [],
"servers": [],