Skip to content

Instantly share code, notes, and snippets.

View jotafeldmann's full-sized avatar
🐙
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn

Jota Feldmann jotafeldmann

🐙
Ph'nglui mglw'nafh Cthulhu R'lyeh wgah'nagl fhtagn
  • São Paulo, SP, Brazil
View GitHub Profile
@jotafeldmann
jotafeldmann / save-path.sh
Created January 23, 2025 23:33
save-path.sh
# . save-path.sh
# . save-path.sh save
SAVE_PATH_FILE=$1
OPTION=$2
if [ "$OPTION" = "save" ]; then
echo $PWD > $SAVE_PATH_FILE
elif [ "$OPTION" = "create" ]; then
touch $SAVE_PATH_FILE
@jotafeldmann
jotafeldmann / ubuntu_simple_bash_git_prompt.sh
Last active August 26, 2024 18:27
ubuntu_simple_bash_git_prompt.sh
# Source: https://code.mendhak.com/simple-bash-prompt-for-developers-ps1-git/
function parse_git_dirty {
[[ $(git status --porcelain 2> /dev/null) ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ (\1$(parse_git_dirty))/"
}
export PS1="\n\t \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ "
@jotafeldmann
jotafeldmann / console.utils.js
Created August 16, 2024 01:38
console.utils.js
// map for list-like things
// mmap(document.querySelectorAll('a'),console.log)
function mmap (listLike, lambda){ for(let i of listLike){lambda(i)} }
@jotafeldmann
jotafeldmann / typescript-method-decorator.ts
Last active April 29, 2024 22:35
typescript-method-decorator.ts
// Edit on https://gist.github.com/jotafeldmann/c3129225ba5d0c26b5fb32273752e8fc
// Test on https://replit.com/@jotafeldmann/typescript-method-decorator#index.ts
// "experimentalDecorators": true
function log(target: any, propertyName: string, descriptor: PropertyDescriptor) {
const originalMethod = descriptor.value;
descriptor.value = function (...args: any[]) {
const result = originalMethod.apply(this, args);
console.log(`${propertyName}(${args}) = ${result}`);
@jotafeldmann
jotafeldmann / generate_query_to_sort_cols.sql
Created March 9, 2022 23:45
Generate query to sort cols (PostgreSQL)
-- Generate query to sort cols (PostgreSQL)
-- https://gist.github.com/jotafeldmann/5eeca544c8e86afe546c794636d27ebf
drop function if exists get_sorted_cols_from_table;
CREATE OR REPLACE FUNCTION get_sorted_cols_from_table(_tbl regclass, OUT result text)
LANGUAGE plpgsql AS
$func$
BEGIN
EXECUTE format('
select
@jotafeldmann
jotafeldmann / docker_zfs_removal.sh
Created September 22, 2021 21:00
Docker ZFS removal solution
# Docker solution for "removal of container X is already in progress"
# driver "zfs" failed to remove root filesystem: exit status 1: "/usr/sbin/zfs fs destroy -r rpool/"
# Based on https://github.com/moby/moby/issues/40132#issuecomment-570000174
docker ps -a | grep Removal | cut -f1 -d' ' | xargs -rt docker rm 2>&1 >/dev/null | grep "dataset does not exist" | awk '{print $(NF-4)}' | sed "s/'//g" | cut -f1 -d':' | xargs -L1 sh -c 'for arg do sudo zfs destroy -R "$arg"; sudo zfs destroy -R "$arg"-init ; sudo zfs create "$arg" ; sudo zfs create "$arg"-init ; ...; done' _ ; docker ps -a | grep Removal | cut -f1 -d' ' | xargs -rt docker rm 2>&1 >/dev/null
@jotafeldmann
jotafeldmann / launch.json
Created December 2, 2020 15:35
Debug TypeScript Node app and Jest TypeScript tests for Visual Studio Code (VSC)
{
// Put this file inside ${workspaceFolder}/.vscode/launch.json
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node-terminal",
"request": "launch",
@jotafeldmann
jotafeldmann / __init__.py
Last active November 24, 2020 06:17
Python: set same import context for ./src and ./tests
# Expected folder structure
#
# ./project
# src/
# tests/
#
# Put this file inside ./project/tests
#
# Then, for every test file inside ./project/tests:
# from src.package import function
@jotafeldmann
jotafeldmann / indexPairs.js
Created May 26, 2020 19:33
Write a function that: 1. Takes 2 parameters - an array of #'s and a target # 2. Return all index pairs that equal the target #
/*
Write a function that:
1. Takes 2 parameters - an array of #'s and a target #
2. Return all index pairs that equal the target #
3. Based on the values below the output should be
[[3, 5]],[1, 6]] (e.g. 2 & 7 and 5 & 4)
*/
const nums = [1, 5, 12, 2, 3, 7, 4, 11, 15];
const target = 9
@jotafeldmann
jotafeldmann / monthsEnumSwaggerJson.json
Created March 11, 2020 22:21
Months Enum Swagger JSON
"months": {
"type":"string",
"enum": [
"JANUARY",
"FEBRUARY",
"MARCH",
"APRIL",
"MAY",
"JUNE",
"JULY",