Skip to content

Instantly share code, notes, and snippets.

View emersondemetrio's full-sized avatar

Emerson Demetrio emersondemetrio

View GitHub Profile
@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 / 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 / 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 / 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}`