Skip to content

Instantly share code, notes, and snippets.

View emersondemetrio's full-sized avatar

Emerson Demetrio emersondemetrio

View GitHub Profile
@emersondemetrio
emersondemetrio / rnb.js
Created October 22, 2018 17:04
Random Number Between Range
const rnb = (max, min) => Math.floor(Math.random() * (max - min + 1)) + min;
@emersondemetrio
emersondemetrio / replica.js
Created October 22, 2018 17:10
Replicate Object
const replicateObject = (obj, times) => {
const tmp = JSON.stringify(obj);
return JSON.parse("[" + tmp.concat(",").repeat(times).slice(0, -1) + "]");
};
const example = {
n: 10,
prop1: "My Name",
prop2: "My Other Name"
};
@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')
@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 / run-python-server.sh
Last active November 17, 2021 16:24
Simple python HTTP Server
# PORT=8000
python -m SimpleHTTPServer 8000 # $PORT
@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 / server.sh
Last active May 19, 2022 09:29
python3 http server
# bash
python -m http.server 9000 --directory .
@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 / 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)) {
#!/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