Skip to content

Instantly share code, notes, and snippets.

View kutyel's full-sized avatar
🌊
数学者に俺は成る!

Flavio Corpa kutyel

🌊
数学者に俺は成る!
View GitHub Profile
@kutyel
kutyel / linkedList.js
Last active August 30, 2018 18:32
Simplest Singly Linked List in JavaScript
class LinkedList {
head = null
tail = null
add (value) {
const node = { value, next: null }
if (!this.head) this.head = node
if (this.tail) {
this.tail.next = node
}
@kutyel
kutyel / FAQ.md
Last active November 15, 2018 13:47
JavaScript Star Q/A 🌟

Typical JS Interview Questions

What is a Closure?

Closure is when a function "remembers" its lexical scope even when the function is executed outside that lexical scope. (IMO: just a stupid function returning another partially applied function).

What is Hoisting?

Variable and function declarations are put into memory during the compile phase, but stays exactly where you typed it in your coding. There is no physically lifting to the top of the file at all.

@kutyel
kutyel / unfollow.fp.js
Created December 19, 2017 13:48
Twitter Unfollow Bot
'use strict'
require('now-env')
const Twit = require('twit')
const Task = require('data.task')
const Maybe = require('data.maybe')
const bot = new Twit({
consumer_key: process.env.CONSUMER_KEY,
consumer_secret: process.env.CONSUMER_SECRET,
access_token: process.env.ACCESS_TOKEN,
@kutyel
kutyel / copySort.js
Last active January 31, 2018 09:17
Sort an array of objects based on another ordered array of objects 🤓
const copySort = (array, order, key) =>
[...array].sort(
(a, b) => order.findIndex(x => x[key] === a[key]) - order.findIndex(x => x[key] === b[key])
)
const order = [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }]
const unordered = [
{ id: 2, label: 'Two' },
{ id: 3, label: 'Three' },
{ id: 5, label: 'Five' },
{ id: 4, label: 'Four' },
@kutyel
kutyel / git_clear_local_branches.fish
Created February 21, 2018 14:28
Fish function that removes all the local git branches that have already been merged
function clear_local_branches --description 'Removes all the local branches that have already been merged'
command git fetch -p; and git branch -vv | awk '/: gone]/{print $1}' | xargs git branch -D
end
@kutyel
kutyel / node_sos.fish
Created February 21, 2018 14:34
This Fish function will solve the 99% of your Node.js problems 🎉
function node_sos --description 'Node plz SAVE ME!!!'
rm -rf node_modules package-lock.json; and npm install $argv;
end
@kutyel
kutyel / tuples.md
Last active February 27, 2018 21:01
Tuples, isomorphisms and dimap

Starting code:

const getRanges = compose(
  chain(([x, y]) => range(x, y + 1)),
  map(compose(map(Number), split('..'))),
  match(rangeRegex)
)
const getNumbers = compose(
  chain(identity),
  map(compose(map(Number), split(','))),
const foo = { a: 1, b: 2, c: 3 }
const { x, ...y } = foo // rest properties
console.log(x) // 1
console.log(y) // { b: 2, c: 3 }
const bar = { d: 4, e: 5 }
const baz = { ...foo, ...bar } // spread properties
console.log(baz) // { a: 1, b: 2, c: 3, d: 4, e: 5 }
for await (const line of readLines(filePath)) {
console.log(line)
}
fetch('http://example/endpoint')
.then(data => data.json()) // todo bien, todo correcto...
.catch(err => console.error(err)) // oh oh...
.finally(() => console.log('...y yo que me alegro!')) // <-- lo nuevo 😎