View myParser.js
const babylon = require('babylon')
const fs = require('fs')
const code = fs.readFileSync('omg.js', 'utf-8')
const ast = babylon.parse(code, {plugins: ['jsx']})
console.dir(ast.program.body, {depth: 10})
View microsoft_surface_pro.md

Kudos for asking at the beginning, if you were just tracking all the stuff I did w/o asking, I'd just be frustrated about the network activity. But by asking, you got my consent, which means I don't mind the tracking pixels firing as I scroll.

I don't know much about Microsoft, so having several products that all sound similar, makes it difficult to be confident that I'm looking at the thing I'm looking for. Eg I think there's a desktop surface, and I think there's a laptop surface. I want the laptop, but then there's also a "Surface" and "Surface Book", the latter sounds like a laptop, the former is presumably the desktop, "Surface Pro" is presumably the beefed up version of the "Surface", but when I watch the videos, it looks like a laptop... So, I'm honestly a bit confused right now.

Given how horrible Apple's latest MBPs are, you might have an entire demographic of people like me, searching for a reasonable machine to work on. If your analytics are good enough to identify this demographic, then it would

View settlers_of_catan_dice.rb
# http://www.itl.nist.gov/div898/handbook/eda/section3/eda3674.htm
def chi_sqr(rolls)
counts = rolls.group_by(&:itself).map { |k, v| [k, v.length] }.sort.to_h
expected = rolls.length / 6.0
chis = 1.upto(6).map do |n|
counts[n]
counts[n] - expected
(counts[n] - expected)**2
((counts[n] - expected)**2) / expected
end
View matrix.sh
# https://vimeo.com/248529140
ruby -r io/console -e '
h, w = $stdin.winsize
time = []
def time.[](i)
super || (
moment = {green: [], white: [], off: []}
self[i] = moment if 0 <= i
moment
)
View parsing-json-from-stdin.sh
# jq is the swiss army knife of piping JSON :)
echo '{"abc":123,"NodeVersion":"7.10.1","xyz":456}' | jq -r .NodeVersion
echo '{"abc":123,"NodeVersion":"7.10.1","xyz":456}' | ruby -rjson -e 'puts JSON.parse($stdin.read).fetch("NodeVersion")'
echo '{"abc":123,"NodeVersion":"7.10.1","xyz":456}' | ruby -054ne 'puts $1 if /NodeVersion":"([^"]*)/'
echo '{"abc":123,"NodeVersion":"7.10.1","xyz":456}' | tr , \\n | sed -En '/NodeVersion/s/^.*"([[:digit:]].+)".*$/\1/p'
echo '{"abc":123,"NodeVersion":"7.10.1","xyz":456}' | awk 'BEGIN { RS=","; FS="\"" } /NodeVersion/ {print $4}'
View distinct_array_postgresql.rb
require 'pg'
db = PG.connect(dbname: 'josh_testing')
# PG.connect(dbname: 'postgres').exec('drop database josh_testing')
# PG.connect(dbname: 'postgres').exec('create database josh_testing')
db.exec 'begin' # throws away changes when process exits
def db.exec(*)
super.to_a
rescue Exception
$!.set_backtrace caller.drop(1)
View rule30.js
// you can also paste it into here: http://hello.processing.org/editor/
// (but use their `rect` function, not the one below)
function rect(x,y,w,h) {
//console.log("rect("+x+", "+y+", "+w+", "+h+");")
x /= 3
y /= 6
x = parseInt(x)
y = parseInt(y)
process.stdout.write("\033["+(y+1)+";"+(x+1)+"H\033[41m \033[0m");
View sorted_colors.rb
ruby -r chunky_png -r base64 -e '
side = 20
colors = {# RR GG BB AA
red: [0xFF, 0x00, 0x00, 0xFF],
orange: [0xFF, 0x7F, 0x00, 0xFF],
yellow: [0xFF, 0xFF, 0x00, 0xFF],
green: [0x00, 0xFF, 0x00, 0xFF],
blue: [0x00, 0x00, 0xFF, 0xFF],
indigo: [0x4B, 0x00, 0x82, 0xFF],
violet: [0x94, 0x00, 0xD3, 0xFF],
View backticks_in_ruby.rb
# https://twitter.com/yburyug/status/939517726846005248
# It does execute it's arg in the shell
`echo hello` # => "hello\n"
# It doesn't work in your example b/c it is private
Object.new.` "echo world" rescue $! # => #<NoMethodError: private method ``' called for #<Object:0x007f8c900257c8>>
#`# fix the hilighting
View consider-2-rows-of-3-random-init.sh
ruby -e '
require "io/console"
print "\e[?25l"
at_exit { print "\e[H\e[2J\e[?25h" }
seed = 0
loop do
rule = Random.new(seed).rand(2**64)
nrows, ncols = $stdin.winsize
rows = [Array.new(nrows*2+ncols/2+2, 0), Array.new(nrows*2+ncols/2, 0)]
rows.each { |r| rand(5).times { r[rand r.size] = 1 } }