Skip to content

Instantly share code, notes, and snippets.

View guilsa's full-sized avatar
👋
@ Looking for projects

Guilherme Sa guilsa

👋
@ Looking for projects
View GitHub Profile
@guilsa
guilsa / vaiLula.sh
Last active October 3, 2022 00:14
Eleição Brasil - Primeiro Turno 2022
#!/bin/bash
while true
do
lula=$(curl -s https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json | jq '.cand[] | select(.nm == "LULA").vap | tonumber' 2> /dev/null )
bozo=$(curl -s https://resultados.tse.jus.br/oficial/ele2022/544/dados-simplificados/br/br-c0001-e000544-r.json | jq '.cand[] | select(.nm == "JAIR BOLSONARO").vap | tonumber' 2> /dev/null )
echo $(( $lula - $bozo ))
sleep 30
@guilsa
guilsa / leetcode.js
Last active March 11, 2022 18:35
Leetcode Stuff
// Remove Element (3/11)
// https://leetcode.com/problems/remove-element/
// time o(n) | space o(1)
var removeElement = function(nums, val) {
let count = 0;
for (let i = 0; i < nums.length; i++) {
if (nums[i] !== val) {
nums[count] = nums[i];
count++;
@guilsa
guilsa / fbTechnicalScreen.js
Last active March 3, 2022 22:39
Solutions - FB Technical Screen Interview Guide (Algorithms)
// Max Ice Cream (3/3)
var maxIceCream = function(costs, coins) {
costs.sort();
for (let i = 0; i < costs.length; i++) {
if (coins >= costs[i]) {
coins -= costs[i];
} else {
return i
}
}
@guilsa
guilsa / data-structures.js
Last active May 3, 2022 15:01
CS Data Structures
// Min Heap
// since JS does not have a native heap,
// for an interview you can quickly code-up something like this
// letting interviewer know what you are doing
class MinHeap {
constructor(compareFunc) {
this.compareFunc = compareFunc;
this.heap = [];
}
@guilsa
guilsa / node_databases.md
Last active December 22, 2021 17:30
Node.js database tools (notes)

better-sqlite3

  • great for prototyping all kinds of apps (non production usages) or unit testing
  • pretty good experience with raw queries

sequelize

  • it's an orm, so boooo!
  • plug n play
  • creation of models feels mandatory (sequelize-auto can be used to auto-generate your models if there's an existing db)
  • there is no pluck() to flatten queries like select * from table1 (currently resolving this by writing out another variable for every query)
@guilsa
guilsa / createElementScript.js
Created December 8, 2021 21:43
Load JavaScript files dynamically from browser console
// source: https://aaronsmith.online/easily-load-an-external-script-using-javascript/
/**
* Loads a JavaScript file and returns a Promise for when it is loaded
*/
const loadScript = src => {
return new Promise((resolve, reject) => {
const script = document.createElement('script')
script.type = 'text/javascript'
script.onload = resolve
@guilsa
guilsa / CS_algorithms.js
Last active May 31, 2022 00:15
Algorithm Problems
// Climbing Stairs (5/13)
// - can be modeled as a graph problem
// - starting from 0 we can take 1 step and get to 1 or take 2 steps and get to 2
// - then from 1 we can take 1 step and get to 2 or take 2 steps and get to 3, and so on
// - if we get to n from a branch, we've found one way
// - recursion can be used to count number of unique paths that can count to n
// - to avoid repeated work, we can cache
// - if we don't cache, it's 2^n time because we must branch out two ways, n times
// - if we cache, it's linear time/space
// - finally, we can reduce to constant space by computing total distinct ways
@guilsa
guilsa / countingMins.js
Created January 24, 2021 17:42
countingMins.js
function CountingMinutes(str) {
const convertTo24hours = (time) => {
let [ hours, mins ] = time.split(':')
if (mins.includes('pm') && hours >= 1 && hours <= 11) {
hours = parseInt(hours) + 12
}
if (mins.includes('am') && hours == 12) {
hours = '00'
}
@guilsa
guilsa / audible_to_m4b_conversion.md
Last active July 24, 2023 06:16
Audible to M4B conversion (or How to listen to audible books on your Garmin watch) on Mac OS

At the end of the steps below, when you've generated your m4b file, you want to drag it into Apple Books app. This is actually the only way to get the file to show up on Garmin Express Manager under Audiobooks.

Screenshot

So... onto intructions...

First run these commands:

Notes:

  • FYI, if you already have pip3 installed, use pip3 instead.
@guilsa
guilsa / mac-setup.sh
Last active December 1, 2022 00:11 — forked from codeinthehole/osx_bootstrap.sh
Script to install stuff I want on a new OSX machine (last tested on macOS Catalina)
#!/usr/bin/env bash
#
# Bootstrap script for setting up a new OSX machine
#
# Before you begin:
# - Install nvm: `curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | bash && nvm install node`
# - Install rvm:
# - `curl -sSL https://get.rvm.io | bash -s stable`
# - `rvm install {{version}}`
#