Skip to content

Instantly share code, notes, and snippets.

@mrbalihai
mrbalihai / instructions.md
Last active July 6, 2023 09:15
Shortest path to the finish (Taxicab Geometry / Manhattan Problem)

You are facing north, you can either turn left (L) or right (R) 90 degrees and walk forward the given number of blocks, ending at a new intersection.

given: R1, R1, R3, R1, R1, L2, R5, L2, R5, R1, R4, L2, R3, L3, R4, L5, R4, R4, R1, L5, L4, R5, R3, L1, R4, R3, L2, L1, R3, L4, R3, L2, R5, R190, R3, R5, L5, L1, R54, L3, L4, L1, R4, R1, R3, L1, L1, R2, L2, R2, R5, L3, R4, R76, L3, R4, R191, R5, R5, L5, L40, L5, L3, R1, R3, R2, L2, L2, L4, L5, L4, R5, R4, R4, R2, R3, R4, L3, L2, R5, R3, L2, L1, R2, L3, R2, L1, L1, R1, L3, R5, L5, L1, L2, R5, R3, L3, R3, R5, R2, R5, R5, L5, L5, R25, L3, L5, L2, L1, R2, R2, L2, R2, L3, L2, R3, L5, R4, L4, L5, R3, L4, R1, R3, R2, R4, L2, L3, R2, L5, R5, R4, L2, R4, L1, L3, L1, L3, R1, R2, R1, L5, R5, R3, L3, L3, L2, R4, R2, L5, L1, L1, L5, L4, L1, L1, R1

What is the shortest path to the finish?

For example:

  • R2, L3 leaves you 2 blocks east and 3 blocks north (shortest path would be 5)
@mrbalihai
mrbalihai / my-test.js
Last active November 22, 2020 20:32
Poor man's NodeJS test runner
import * as assert from 'assert';
test('1 should equal 1', () => {
assert.equal(1, 1);
});
test('async 1 should equal 1', async () => {
await new Promise(r => setTimeout(r, 1000));
assert.equal(1, 1);
});
@mrbalihai
mrbalihai / es5-example.js
Last active November 7, 2020 20:36
Code examples for mrbalihai.github.io/2016/02/07/javascript-function-composition.html
var add = function(a, b) { return a + b; };
var sum = function (arr) { return arr.reduce(add, 0) };
var getProperty = function(obj, propName) { return obj[propName]; };
var getWhisky = function (obj) { return getProperty(obj, 'whisky' };
var getPrices = function (arr) {
return arr.map(function (a) {
return getProperty(a, 'price');
});
};
@mrbalihai
mrbalihai / arrow-function-es5.js
Created November 7, 2020 20:25
Code examples for mrbalihai.github.io/2016/01/24/making-the-most-of-es6.html
var myArray = [1, 2, 3, 4, 5, 6],
add = function (a, b) {
return a + b;
},
getTotal = function (arr) {
return arr.reduce(add, 0);
};
getTotal(myArray); // => 21
@mrbalihai
mrbalihai / browserify-babelify.sh
Created November 7, 2020 19:49
Code examples for mrbalihai.github.io/2016/01/15/making-the-most-of-the-javascript-language.html
npm install -g browserify babelify
browserify -t babelify es6code.js > es5code.js
@mrbalihai
mrbalihai / toggle-pandoc-md-strikethrough.vim
Last active July 31, 2020 12:02
Toggle strike through in pandoc markdown
function! ToggleStrikethrough()
let line = getline('.')
if stridx(line, "~~") == -1
call setline(line('.'), substitute(line, '\(\s*-\s\)\(.*\)', '\1\~\~\2\~\~', "g"))
else
call setline(line('.'), substitute(line, '\~\~', '', "g"))
endif
endfunction
map <localleader>d :call ToggleStrikethrough()<CR>
@mrbalihai
mrbalihai / rpi-fan.py
Last active July 30, 2020 08:24
Triggering a Raspberry PI Fan via GPIO port in python or bash
#!/usr/bin/python3
import sys
import time
from gpiozero import LED # doc: https://gpiozero.readthedocs.io/
# define the GPIO to control the transistor's B pin
fan = LED(21)
def cpu_temp():
import L from 'leaflet';
import 'leaflet-routing-machine';
import data from '../../data.json';
const tileLayerUrl = `https://cartodb-basemaps-{s}.global.ssl.fa
import { Component, Vue } from 'vue-property-decorator';
import AppHtml from './app.html';
import { MapComponent, HeaderComponent, LeftPanelComponent } from '../';
@Component({
@mrbalihai
mrbalihai / .cvimrc
Last active October 18, 2019 07:26
cvimrc
map <C-b> :buffer<Space>