Skip to content

Instantly share code, notes, and snippets.

@mbchoa
mbchoa / 8queens.js
Last active July 26, 2020 00:27
Recursive backtracking algorithm for solving the "8 Queens" problem
const UNASSIGNED = -1;
const ASSIGNED = 1;
class Board {
constructor(size, options) {
this.board = [];
this.size = size;
this.options = options;
for (let row = 0; row < size; row++) {
@mbchoa
mbchoa / pseudo-recursive-backtracker
Created July 24, 2020 08:00
Pseudocode describing general structure of a recursive backtracker
bool Solve(configuration conf) {
if (no more choices) { // base case
return (conf is goal state)
}
for (all available choices) {
try one choice C:
// solve here, if it works, you're done
if (Solve(conf with choice C made) return true;
undo choice C
import get from 'lodash/get';
/**
* Helper function to transform an array of objects to an object containing arrays, keyed by the common properties.
* This assumes that the array of objects have the same set of properties.
*
* Input:
* [{ size: 48,length: "L"}, {size: 42, length: "R'}]
*
* Output:
@mbchoa
mbchoa / appEntryPoint.js
Created May 25, 2019 17:34 — forked from markerikson/appEntryPoint.js
Webpack React/Redux Hot Module Reloading (HMR) example
import React from "react";
import ReactDOM from "react-dom";
import configureStore from "./store/configureStore";
const store = configureStore();
const rootEl = document.getElementById("root");
@mbchoa
mbchoa / gist:af34608b037fa31d2f83ec83aa140541
Created January 12, 2019 08:40
Uninstall minikube on OSX
minikube stop; minikube delete &&
docker stop $(docker ps -aq) &&
rm -rf ~/.kube ~/.minikube &&
sudo rm -rf /usr/local/bin/localkube /usr/local/bin/minikube &&
launchctl stop '*kubelet*.mount' &&
launchctl stop localkube.service &&
launchctl disable localkube.service &&
sudo rm -rf /etc/kubernetes/ &&
docker system prune -af --volumes
@mbchoa
mbchoa / main.go
Created December 25, 2018 21:32
Example usage of MongoDB's official Go Driver with nested struct types
package main
import (
"context"
"fmt"
"log"
"github.com/mongodb/mongo-go-driver/bson"
"github.com/mongodb/mongo-go-driver/mongo"
"github.com/mongodb/mongo-go-driver/mongo/options"
@mbchoa
mbchoa / gist:ef877bd1cdd3d2309525878b3f971175
Created November 10, 2018 20:08
Find raspberrypi on local network
arp -na | grep -i b8:27:eb
@mbchoa
mbchoa / rom2Int.js
Created October 31, 2018 00:54
Roman Numeral to Integer
function valOf(letter) {
const map = {
'I': 1,
'V': 5,
'X': 10,
'L': 50,
'C': 100,
'D': 500,
'M': 1000,
};
@mbchoa
mbchoa / clearAllTimers.js
Last active July 24, 2020 08:06
IIFE clearAllTimers()
(function (global) {
// save references to native setTimeout() and clearTimeout() functions
const defaults = {
'setTimeout': global.setTimeout,
'clearTimeout': global.clearTimeout
};
// create empty array to store timer IDs
const timeoutIds = [];
@mbchoa
mbchoa / .gitconfig
Created August 17, 2017 20:42 — forked from robmiller/.gitconfig
Some useful Git aliases that I use every day
#
# Working with branches
#
# Get the current branch name (not so useful in itself, but used in
# other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track
# the upstream branch
publish = "!git push -u origin $(git branch-name)"