Skip to content

Instantly share code, notes, and snippets.

View yaauie's full-sized avatar

Ry Biesemeyer yaauie

View GitHub Profile
#!/usr/bin/env ruby
# Given STDIN of unix timestamps (one or more per line),
# analyze the weekly distribution at hourly granularity.
day_counts_by_hour = []
$stdin.each_line do |line|
next if line.chomp.empty?
# encoding: utf-8
require 'pry'
module Kernel
alias_method :raise_without_pry, :raise
def raise_with_pry(*a, &b)
# `exit true` to continue *without* raising.
binding.pry || raise_without_pry(*a, &b)
end
alias_method :raise, :raise_with_pry
# quick and dirty back-port of Ruby 2.1's Exception#cause
class Exception
def self.new(*args)
allocate.tap do |exception|
exception.send(:initialize, *args)
exception.cause = $!
end
end
# @return [Exception, nil]
(cd $(bundle show yajl-ruby)/ext/yajl; sed -i '.bak' 's/inline void/static void/g' yajl_ext.h yajl_ext.c; make clean all)
#!/usr/bin/ruby
# encoding: utf-8
module Where
extend self
def where(cmd)
return enum_for(:where, cmd) unless block_given?
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
@yaauie
yaauie / kafka-lag-top.rb
Created February 8, 2016 20:02
a top-like version of https://gist.github.com/yaauie/40a9176f354f0100db47 put this in the bin of the kafka tarball you downloaded from https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.2.1/kafka_2.10-0.8.2.1.tgz and invoke it with the path to the zookeeper node as its only argument.
#!/usr/bin/env ruby
require 'shellwords'
require 'time'
END {
zookeeper = ARGV.shift || fail("Usage #{$0} <zookeeper>")
$stderr.puts("Getting stats via #{zookeeper}")
one_five_fifteen = []
@yaauie
yaauie / Iso8601.g4
Created May 29, 2016 18:53
ISO-8601 Grammar
grammar Iso8601;
temporal : year (HYPHEN subyear)? offset? EOF
;
subyear : month (HYPHEN submonth)?
| W_LITERAL week (HYPHEN subweek)?
| Q_LITERAL quarter (HYPHEN subquarter)?
| oday (T_LITERAL subday)?
;
@yaauie
yaauie / jsonpp
Last active August 12, 2016 01:22
order-preserving jsonpp
#!/usr/bin/env ruby
# encoding: utf-8
require 'json'
begin
$stdout.puts(JSON.pretty_generate(JSON.load($stdin.read)))
rescue JSON::ParserError => e
$stderr.puts(e.message)
exit 1
package com.yaauie.guava-utils;
import com.google.common.collect.ImmutableBiMap;
import com.google.common.collect.ImmutableCollection;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSortedMap;
import com.google.common.collect.ImmutableSortedSet;
@yaauie
yaauie / README.md
Last active February 9, 2017 20:50
A simple command-line tool for creating randomised pairings, written in Ruby.

Rando-Pair

It creates randomised pairings from the given inputs.

Examples:

Simple:

╭─{ yaauie@durin:~ }
╰─● rando-pair Alice Bob Charlie Donald Evelyn Frank Gertrude