Skip to content

Instantly share code, notes, and snippets.

View masotime's full-sized avatar
💭
I may be slow to respond.

Benjamin Goh masotime

💭
I may be slow to respond.
  • San Francisco
  • 13:36 (UTC -08:00)
View GitHub Profile
/*****************
* bossFight.js *
*****************
*
* NO FARTHER, DR. EVAL!!!!
* YOU WILL NOT GET OUT OF HERE ALIVE!!!!
* IT'S TIME YOU SEE MY TRUE FORM!!!!
* FACE MY ROBOT WRATH!!!!!
*/
/***************
* pointers.js *
***************
*
* You! How are you still alive?
*
* Well, no matter. Good luck getting through this
* maze of rooms - you'll never see me or the Algorithm again!
*/
/*
* robotNav.js
*
* The green key is located in a slightly more
* complicated room. You'll need to get the robot
* past these obstacles.
*/
function startLevel(map) {
// Hint: you can press R or 5 to "rest" and not move the
@masotime
masotime / automatic_download.sh
Last active June 14, 2020 21:58
Download stuff from Automatic Dashboard API
#!/bin/bash
START_TIME=1420099200000 # Unix timestamp
END_TIME=1592164819833 # Unix timestamp
INDEX=0
PREFIX='drives' # name is up to you
BEARER_TOKEN="<fill-this-with-your-token>"
URL="https://api.automatic.com/trip/?started_at__gte=${START_TIME}&started_at__lte=${END_TIME}&limit=250" # limit cannot be > 250 I think
set_current_file () {
CURRENT="${PREFIX}_${INDEX}.json"
@masotime
masotime / reduce.sh
Created March 2, 2017 18:49
Using bash to implement recursion-based reduce
#!/bin/bash
function testRecurse {
ONE=${1:0}
TWO=("${@:1}")
if [[ $# -eq 1 ]]; then
echo Final answer $ONE
else
@masotime
masotime / unbox.sh
Created January 7, 2017 20:55
Box and Unbox
#/bin/bash
# Emoji / logging nonsense
SPACE=$'\xe2\x80\x83'
ERROR=$'\xF0\x9F\x94\xB4'$SPACE
INFO=$'\xF0\x9F\x94\xB5'$SPACE
OK=$'\xE2\x9C\x85'$SPACE
error() { echo "$ERROR $1"; }
warn() { echo "$INFO $1"; }
ok() { echo "$OK $1"; }
@masotime
masotime / mrt.sg.js
Last active June 21, 2016 01:18
Getting a JSON matrix of MRT travel times
/* global $ */
function getInputs() {
return $('#stations-list li').map(function() {
return {
symbol: $(this).data('skey'),
name: $(this).text()
};
}).toArray();
}
@masotime
masotime / download.js
Last active June 19, 2016 12:36
Automated humble bundle comic downloading script because humble bundle sucks
function guessDownloadDuration($cbz, MBps) {
if ($cbz.length === 0) {
return 0;
}
const rawValue = $cbz.parent().find('.right-align').contents().get(0).textContent;
if (rawValue.includes('MB')) {
const sizeInMb = parseFloat(rawValue.split('MB')[0].trim());
const durationInMs = Math.round(sizeInMb / MBps * 1000);
@masotime
masotime / craigslist-scroll.js
Created December 20, 2015 04:21
Craigslist "infinite scroll"
function track() {
var scrollCount = 0;
var fetching = false;
return function () {
if($(window).height() + $(window).scrollTop() >= $('.content').offset().top + $('.content').outerHeight() && !fetching) {
scrollCount += 100;
fetching = true;
$.ajax('http://sfbay.craigslist.org/search/bka' + ( scrollCount > 0 ? '?s='+scrollCount : '' )).then(function(x) {
@masotime
masotime / rectangle-puzzle.js
Created December 7, 2015 17:00
Karat Puzzle
/*var _ = require('underscore')
function sayHello() {
console.log('Hello, World');
}
_.times(5, sayHello);
*/
var image = [
[1, 1, 1, 1, 1, 1, 1],