Skip to content

Instantly share code, notes, and snippets.

@aquach
aquach / 0_reuse_code.js
Created January 5, 2017 22:59
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
'use strict';
const _ = require('lodash');
const moment = require('moment');
function cliff(months, cliffMonths, totalMonths) {
return (months < cliffMonths) ? 0 : Math.min(1, months / totalMonths);
};
module.exports = {
@aquach
aquach / sorter_burkematcher.vim
Last active February 19, 2016 18:43
Unite.vim sorter for burke/matcher (provides Command-T fuzzy matching for Unite)
" Paste this into your .vimrc.
" It's very janky but hopefully easy to tweak for your own purposes.
" If you want to make this into a real plugin, be my guest.
" To use, put this in your .vimrc:
" call unite#custom#source('<source name>', 'sorters', 'sorter_burkematcher')
python << endpython
import vim
import subprocess
@aquach
aquach / automatic_hirb_timestamp.rb
Created September 4, 2015 01:16
Automatic Unix timestamp conversion for Hirb tables.
module AutoTimestamp
def query_callback(rows, options)
rows.each do |r|
r.each do |k, v|
if v.is_a?(Integer)
dates = [ Time.at(v), Time.at(v / 1000) ]
plausible_date = dates.find { |d|
d >= Time.now - 10.years && d <= Time.now + 10.years
}
@aquach
aquach / correlate.rb
Created September 4, 2015 01:07
Cheap pairwise correlation of two binary variables with confusion matrix
# Requires Hirb and Ruby 2.0+.
# The format for data is [[ test_positive, condition_positive ]], where each entry is a data point.
def correlate(data, test_event: 'Test', condition_event: 'Truth')
counts = data.group_by(&:itself).map { |bucket, v| [ bucket, v.length ] }.to_h
table = [
[ counts[[true, true]] || 0, counts[[true, false]] || 0 ],
[ counts[[false, true]] || 0, counts[[false, false]] || 0 ]
]
all_test_positive = table[0][0] + table[0][1]
all_test_negative = table[1][0] + table[1][1]
@aquach
aquach / amplitude_event.rb
Last active March 26, 2020 17:45
Exports Amplitude data to MySQL
class AmplitudeEvent < ActiveRecord::Base
end
@aquach
aquach / .vimrc
Created March 23, 2015 17:55
Minimal .vimrc to reproduce airline tab bug with Tomorrow-Night colorscheme.
" Vundle.
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'bling/vim-airline'
@aquach
aquach / ed-downloader.py
Last active August 10, 2016 16:15
Downloads updates to Elite Dangerous by imitating the patcher.
import gzip
import hashlib
import os
import StringIO
import sys
import urllib
import getpass
from xml.etree import ElementTree
@aquach
aquach / NumberUtils.scala
Created October 16, 2014 22:15
Numbers to English words
object NumberUtils {
private def numberUnderThousandToEnglish(number: Int) = {
val hundreds = number / 100
val tensAndOnes = number % 100
val tens = tensAndOnes / 10
val ones = number % 10
val hundredsStr = if (hundreds > 0) Some(numNames(hundreds) + " hundred") else None
val restStr = numNames.get(tensAndOnes).map(s => List(Some(s))).getOrElse(