Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View lucas-janon's full-sized avatar
:electron:
Focusing

Lucas lucas-janon

:electron:
Focusing
View GitHub Profile
@lucas-janon
lucas-janon / cloudSettings
Last active February 27, 2022 01:58
Visual Studio Code Settings Sync Gist
{"lastUpload":"2022-02-27T01:58:56.837Z","extensionVersion":"v3.4.3"}
@lucas-janon
lucas-janon / formatmuiimports
Last active April 17, 2019 13:52
Script to format material-ui imports
#!/usr/bin/env node
const fs = require('fs')
if (!process.argv[2]) {
console.log('File path needed')
process.exit()
}
const rx = /import (.*?) from '@material-ui\/(.*?)\/(.*?)';/
@lucas-janon
lucas-janon / .bash_profile
Last active May 16, 2019 00:46
~/.bash_profile
# rar
export PATH="/Applications/rar:${PATH}"
# shortcuts to folders
alias dt='cd /Users/lucasjanon/Desktop'
alias rt='cd ~/'
alias docs='cd /Users/lucasjanon/Documents'
alias shortcuts='cat ~/.bash_profile'
# command shortcuts
@lucas-janon
lucas-janon / numberAsArs.js
Last active October 17, 2018 20:10
Format number as currency (USD) and format USD as ARS, avoids using toLocaleString (compatibility)
const numberAsUsd = price => price.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,'); // numberAsUsd(1000) === 1,000
const usdToArs = price => price.replace(/[,.]/g, x => (x === ',' ? '.' : ',')); // usdToArs(1,000) === 1.000
const deleteZerosAfterComma = price => price.replace(',00', ''); // deleteZerosAfterComma(1.000,00) === 1.000
export const numberAsArs = price => `$ ${deleteZerosAfterComma(usdToArs(numberAsUsd(price)))}`; // numberAsArs(1000) === '$ 1.000'
@lucas-janon
lucas-janon / cloudSettings
Last active April 4, 2020 18:58
Visual Studio Code Settings Sync Gist
{"lastUpload":"2020-04-04T18:58:21.162Z","extensionVersion":"v3.4.3"}
@lucas-janon
lucas-janon / validateTree.js
Last active March 10, 2019 02:18
Best algorithm to validate binary search trees
/**
* The logic is the following: first call: no parents, then the node can have any value
* then it goes down recursively on both left and right nodes, checking that left.value < node.value & right.value > node.value
* but the magic is the following, and it's where most algorithms fail (or use much more computation than this one):
* in the recursive call involving the left node, the algorithm sets a maximum value to subsequent recursive calls, so when the left node
* calls validateTree on its right node, that right node is forced to not just being higher than its parent but also
* being lower than the parent of its parent, because remember that a binary search tree can't have any direct or indirect higher value
* on its left. The same logic is applied to its right, but of course with a minimum value.
*/
const validateTree = (node, min = Number.MIN_SAFE_INTEGER, max = Number.MAX_SAFE_INTEGER) => {
@lucas-janon
lucas-janon / minHeap.js
Created July 2, 2018 04:01
Min heap javascript implementation
class MinHeap {
constructor ({ items } = {}) {
this.heap = items ? [...items] : []
this.length = this.heap.length
}
get () {
return this.heap
}

Keybase proof

I hereby claim:

  • I am luqih on github.
  • I am lucasjanon (https://keybase.io/lucasjanon) on keybase.
  • I have a public key whose fingerprint is 136F 8334 AF90 55DD 3513 6A0F 910C D2A6 3691 CAA4

To claim this, I am signing this object:

@lucas-janon
lucas-janon / highestCombination.js
Created June 24, 2018 05:51
Gets highest combination possible from a positive integer array
const arr = [9, 90, 95, 99, 50, 5, 56, 504, 5006, 544, 1]
const highestCombination = (a) => {
const grouped = a.reduce(
(acc, c) => {
const cInitial = `${c}`.split('')[0]
acc[cInitial] ?
acc[cInitial].items.push(c)
:
acc[cInitial] = { items: [c], longest: 0 }
@lucas-janon
lucas-janon / asyncErrorHandler.js
Created June 12, 2018 01:10
Async/Await wrapper for express routes (to avoid try/catching every route)
// Adds a .catch to the express callback to handle errors that happen in async/await functions
// you should wrap every route with this handler
// ie: errorHandler((req, res) => res.send(JSON.stringify(res.locals.user)))
const errorHandler = fn => (req, res, next) => {
Promise.resolve(fn(req, res, next))
.catch(error => {
if (process.NODE_ENV === 'development') console.log(require('util').inspect(error))
next(error)
})
}