Skip to content

Instantly share code, notes, and snippets.

Avatar

Ry Biesemeyer yaauie

View GitHub Profile
@yaauie
yaauie / README.md
Last active Feb 9, 2017
A simple command-line tool for creating randomised pairings, written in Ruby.
View README.md

Rando-Pair

It creates randomised pairings from the given inputs.

Examples:

Simple:

╭─{ yaauie@durin:~ }
╰─● rando-pair Alice Bob Charlie Donald Evelyn Frank Gertrude
View immutable-collectors.java
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 / jsonpp
Last active Aug 12, 2016
order-preserving jsonpp
View 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
@yaauie
yaauie / Iso8601.g4
Created May 29, 2016
ISO-8601 Grammar
View Iso8601.g4
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 / kafka-lag-top.rb
Created Feb 8, 2016
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.
View kafka-lag-top.rb
#!/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 = []
View where.rb
#!/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|
View yajl-clang-fixer.sh
(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)
View exception.cause.rb
# 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]
View pry-kernel.raise.rb
# 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
View hourly-week-distribution
#!/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?
You can’t perform that action at this time.