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:53 (UTC -08:00)
View GitHub Profile
@masotime
masotime / install.sh
Created November 12, 2012 02:40
Quick script to set up yeoman on a Mac
#!/bin/bash
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
brew doctor
sudo gem update --system
gem install compass
brew install phantomjs
brew install jpeg-turbo && brew link jpeg-turbo
brew install optipng
sudo npm install -g yeoman
@masotime
masotime / index.js
Created May 14, 2015 23:06
sudoku-generator-WIP
(function sudokuGenerator() {
'use strict';
var test4 = [
1, 2, 3, 4,
3, 4, 1, 2,
2, 3, 4, 1,
4, 1, 2, 3
];
@masotime
masotime / ellipsis-detection.js
Last active August 29, 2015 14:26
Determining if one-liner span has ellipsis overflow
function getVisibleWidth(elem) {
// cross browser, returns decimals for ultra-precision
return elem.getBoundingClientRect().right - elem.getBoundingClientRect().left;
}
function getNaturalWidth(elem) {
var old = {
overflow: elem.style.overflow,
width: elem.style.width,
display: elem.style.display
@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],
@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 / 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 / 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 / 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 / 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 / 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"