Skip to content

Instantly share code, notes, and snippets.

View emersondemetrio's full-sized avatar

Emerson Demetrio emersondemetrio

View GitHub Profile
@emersondemetrio
emersondemetrio / fill-array.js
Last active April 24, 2024 12:32
Fill array with something
// 2024 version
const arr = Array.from({ length: 30 }, (_, id) => ({
id,
name: `item-${id}`
}));
// 2018 version
const arr = Array.from(Array(30), (_, id) => ({
id,
name: `item-${id}`
@emersondemetrio
emersondemetrio / slack-msg-to-alphabet.ts
Last active September 29, 2022 12:41
Message to Slack alphabet
console.clear()
const transformMap: { [key: string]: string } = {
'á': 'a',
'à': 'a',
'ó': 'o',
'é': 'e',
'ç': 'c',
'ã': 'a',
'¿': '?',
'o': 'o',
#!/bin/bash
# Branch Removing Tool
LIST=$(cat ./list.txt)
while read -r item; do
echo "Current item: $item"
done <<<"$LIST"
printf "> All done. Goodbye. \n\n"
exit
@emersondemetrio
emersondemetrio / circular-safe-json-stringfy.ts
Created September 16, 2022 15:55
Circular Safe Json Stringfy
type JsonLike = {
[key: string]: string | number | undefined | null | JsonLike;
};
const getCircularReplacer = () => {
const seen = new WeakSet();
return (_, value: JsonLike) => {
if (typeof value === 'object' && value !== null) {
if (seen.has(value)) {
@emersondemetrio
emersondemetrio / deleting-branchs.sh
Last active May 19, 2022 09:29
Deleting Branchs with bash
#!/bin/bash
while read -r branch;
do echo "deleting: $branch";
git branch -D $branch;
done <<< `git branch | grep 'bugfix'`
@emersondemetrio
emersondemetrio / server.sh
Last active May 19, 2022 09:29
python3 http server
# bash
python -m http.server 9000 --directory .
@emersondemetrio
emersondemetrio / promise-helper.ts
Last active November 17, 2021 16:30
Promise unwrapper to avoid nested try/catch blocks
export const isAFunction = (e: unknown) => e && typeof e === "function";
export interface GenericObject {
[key: string]: unknown;
}
export type ExecutedPromiseResponse<R> = [
data: R | null,
error: GenericObject | null
];
@emersondemetrio
emersondemetrio / run-python-server.sh
Last active November 17, 2021 16:24
Simple python HTTP Server
# PORT=8000
python -m SimpleHTTPServer 8000 # $PORT
@emersondemetrio
emersondemetrio / url2json.js
Last active July 23, 2019 17:01
Convert URLs to JSON
const url2JSON = source => {
const obj = {
source,
props: {},
keysList: [],
valuesList: []
};
const arr = source.split('?');
@emersondemetrio
emersondemetrio / function.sql
Created January 23, 2019 17:27
MYSQL Create Function Syntax
-- https://dev.mysql.com/doc/refman/8.0/en/create-procedure.html
DROP FUNCTION db.hello;
CREATE FUNCTION db.hello (s CHAR(20))
RETURNS CHAR(50) DETERMINISTIC
RETURN CONCAT('Hello, ',s,'!');
SELECT db.hello('eae')