Skip to content

Instantly share code, notes, and snippets.

View valentingavela's full-sized avatar

Valentín Gavela valentingavela

  • Argentina
View GitHub Profile
############################
# USE TYPE AS KEY OF OBJECT#
############################
type DayOfTheWeek = "sunday" | "monday" | "tuesday" | "wednesday" | "thursday" | "friday" | "saturday";
type ChoresMap = { [day in DayOfTheWeek]: string };
const chores: ChoresMap = { // ERROR! Property 'saturday' is missing in type '...'
"sunday": "do the dishes",
"monday": "walk the dog",
@valentingavela
valentingavela / script: pluralsight downloader
Last active July 11, 2019 19:39
pluralsigth video download
/*
DISCLAIMER: this snippet is just for educational purposes. Use at your own risk.
Instructions:
-Step 1: Get a Pluralsight account.
-Step 2: Start the first video of a course.
-Step 3: paste the following code in the console.
Your videos will be downloaded in your current downloads folder.
*/
var video = document.querySelector('video');
Find whole lines not match with word
^((?!playerUrl).)*$
Find whole lines match with work
^.*\b(one|two|three)\b.*$
Find newline
([\n])
Match alphanumeric case insensitive
@valentingavela
valentingavela / links.txt
Last active July 11, 2019 15:05
Programming links
const ascending = prices.sort((a, b) => a - b);
const descending = prices.sort((a, b) => a + b);
function swap(arr, index1, index2) {
if (index1 === index2) throw Error;
[arr[index1], arr[index2]] = [arr[index2], arr[index1]];
return arr;
}
@valentingavela
valentingavela / Javascript check if number is integer or float
Created May 17, 2019 14:26
Javascript check if number is integer or float
function isInt(n){
return Number(n) === n && n % 1 === 0;
}
function isFloat(n){
return Number(n) === n && n % 1 !== 0;
}
@valentingavela
valentingavela / Array Generator Looper
Last active July 11, 2019 15:18
Array Looper generator
function* arrayLooper(arr = []) {
let i = 0;
while (1) {
i = i === arr.length ? 0 : i;
yield arr[i];
i++;
}
}
@valentingavela
valentingavela / arrayTo2DArray2
Created May 17, 2019 12:40
transform a array in a 2D array
function arrayTo2DArray2(list, howMany) {
var idx = 0
result = []
while (idx < list.length) {
if (idx % howMany === 0) result.push([])
result[result.length - 1].push(list[idx++])
}
return result
@valentingavela
valentingavela / Bitwise operators
Last active July 11, 2019 15:16
Convert string to int with bitwise OR operator
// Convert int to string:
// | OR operator
console.log('20' | 0);