Skip to content
View correctly-refactored-AutoMaker.js
'use strict'
// Factory, correctly-refactored implementation:
const AutoMaker = {
// Use function literal to make this function constructable.
Car: function (bundle) {
// No one uses `this` to access static properties (e.g. bundle).
return Object.create(AutoMaker.bundle[bundle || 'premium']);
},
View midi_to_txt.rb
require 'midilib'
seq = MIDI::Sequence.new()
File.open(ARGV[0], 'rb') { |file| seq.read(file) }
events = [ ]
id = 0
seq.tracks.each do |track|
View README.md

Sort by (predicted) satisfaction

Based on an article: How Not To Sort By Average Rating

This code snippet sorts the restaurant listing in Foodpanda.co.th by using the equation from the above article.

Assumptions: Since the article is for binary rating (+/−), I’m going to make an assumption that the stars represent the proportion of delighted customers. For example, if a restaurant gets 4.5 stars and has 2,000 reviews, it is assumed that there are 1,800 delighted customers out of 2,000.

Usage:

View nwb.config.js
'use strict'
module.exports = {
// Let nwb know this is a React app when generic build commands are used
type: 'react-app',
loaders: {
'stylus-css': {
query: {
modules: true,
localIdentName: '[name]の[local]/[hash:base64:7]',
View bms-to-song.rb
require 'tmpdir'
require 'digest'
# Returns the MP3 file name and other meta information about a BMS.
# XXX: This should be split into two functions.
def get_name(file)
data = File.read(file, encoding: 'Shift_JIS')
attrs = { }
data.scan(/\n\s*?#(TITLE|GENRE|ARTIST|STAGEFILE)[ ]+(.+)/i) do
attrs[$1.downcase] = $2.encode('UTF-8').strip
View Checkbox.js
export function Checkbox (props) {
return <div style={{ margin: '8px 16px' }}>
<MaterialCheckbox
label={props.label}
checked={props.checked}
onCheck={e => {
props.onPropChange('checked', !props.checked)
if (props.onchange) props.onchange(e)
}}
disabled={props.disabled}
View manifester.js
// Wow cool hack to generate a manifest on-the-fly!!
var manifest = {
short_name: inferApplicationName({ app: this.props.app }),
icons: [
{
src: 'https://ss16-wonderstudio.firebaseapp.com/images/default_icon.png',
sizes: '144x144',
type: 'image/png'
}
],
View _README.md

My Atom hack (init script) for speed programming in Ruby. This code is very ugly but works.

Features

Upon saving,

  • Ruby code in the specified directory is run.
  • Test input data (after 1st __END__ but before 2nd __END__) is sent to the script via stdin.
  • Output and/or errors are displayed in a popup.
  • Program output is compared to test output data (after 2nd __END__). If it matches, then the popup becomes green.
View renote.js
function renote () {
var text = clipboard.readText()
var lines = text.trim().split(/\r\n|\r|\n/).slice(1)
var out = ['iBMSC Clipboard Data xNT']
var nextColumn = 5
var columns = { }
var moved = 0
var items = document.querySelector('#input').value
var COLUMN_MAP = {
a: 12,
Something went wrong with that request. Please try again.