Skip to content

Instantly share code, notes, and snippets.

View AlexJuarez's full-sized avatar

Alex Juarez AlexJuarez

View GitHub Profile
@AlexJuarez
AlexJuarez / mongodb-example.js
Created June 29, 2022 12:29
a example query
// MongoDB Playground
// To disable this template go to Settings | MongoDB | Use Default Template For Playground.
// Make sure you are connected to enable completions and to be able to run a playground.
// Use Ctrl+Space inside a snippet or a string literal to trigger completions
// Select the database to use.
const { MongoClient } = require("mongodb");
const uri = 'mongodb+srv://regen:Ba6qFCPCctcvW8DHavCu@regen-staging.fmfup.mongodb.net/admin';
class Heap {
constructor(comparator) {
this.arr = [];
this.compare = (i, j) => comparator(this.arr[i], this.arr[j]);
}
get size() {
return this.arr.length;
}
@AlexJuarez
AlexJuarez / .gitconfig
Last active July 6, 2020 19:21
Git and Vim config files
[alias]
s = status --short
cam = commit -a --no-verify -m
cm = commit --no-verify -m
l = !git log --oneline -n 10 --color | cat
aliases = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\ \t => \\2/' | sort
br = branch -av
unstage = reset HEAD --
b = !git branch --color | cat
bd = branch -D
@AlexJuarez
AlexJuarez / Search.js
Created June 20, 2020 01:14
Find in 2d matrix
right.
const exampleMatrix = [
[ 1, 2, 6, 10, 17],
[ 3, 5, 8, 12, 19],
[ 7, 9, 13, 15, 24],
[11, 14, 16, 20, 26],
[18, 22, 25, 29, 30],
];
/**
* @param {string} color
* @return {string}
*/
const doubles = new Array(16).fill(0).map((_, i) => i * 17);
var similarRGB = function(color) {
const red = binarySearch(doubles, toRGB(color));
const blue = binarySearch(doubles, toRGB(color, 2));
const ws281x = require('rpi-ws281x-native');
const EventEmitter = require('events');
function parse(i, min, max) {
const num = Number(i);
if (isNaN((num))) {
return min;
}
@AlexJuarez
AlexJuarez / FastPixel.js
Last active March 14, 2019 21:13
Mative ws2812b bindings wrapper.
const ws281x = require('rpi-ws281x-native');
const EventEmitter = require('events');
function parse(i, min, max) {
const num = Number(i);
if (isNaN((num))) {
return min;
}
@AlexJuarez
AlexJuarez / Path.js
Last active October 31, 2018 18:03
Ast walker and modifier
class Path {
constructor(node, parent = null, key = null) {
this.node = node;
this.parent = parent;
this.key = key;
}
replace(node) {
node.leadingComments = [...(this.node.leadingComments || [])];
node.trailingComments = [...(this.node.trailingComments || [])];
{
"workbench.iconTheme": "vscode-icons",
"editor.tabSize": 2,
"terminal.integrated.fontFamily": "Source Code Pro for Powerline",
"window.zoomLevel": 0,
}
@AlexJuarez
AlexJuarez / Mastermind-solver.js
Created November 28, 2017 03:34
Write a way to play mastermind.
// The other player starts with a code that you are trying to guess
// the code is 4 digits 1-6, on each guess the other player will
// tell you the number of digits in your guess that are in the final solution
// and the exact number of digits that matches.
// e.g. code: '1234', guess: '1111' => '1 1'
const parse = (code) => code.split('').map((n) => parseInt(n, 10));
const MASTER_CODE = parse('1234');