Prettifies JSON on the command line.
Copy into anywhere on $PATH
and chmod +x
the file. Remove the .rb
if you like.
# Generates combinations of letters or numbers, or anything really. The combinations | |
# include repeating values, unlike Ruby's regular Array#permutation method. | |
# | |
# Usage: | |
# generate('a'..'c', 3) do |seq| | |
# puts seq.inspect #=> [a,a,a], [a,a,b], [a,a,c], [a,b,a]... | |
# end | |
def generate(range, comb_len) | |
range = range.to_a | |
range_len = range.length |
# In your .gitconfig add this alias: | |
# [alias] | |
# sred = "!source ~/.git_sred_log && sred_log" | |
# Assumes input date is formatted as YYYY-MM-DD, | |
# passes additional arguments to git-log. | |
sred_log() { | |
sred_date="${1:-$(date +"%Y-%m-%d")}" | |
shift |
# This algorithm takes a *sorted* list of integers, probably record | |
# IDs and compresses them into a series of ranges. It also includes a | |
# verification check that no values were lost. | |
def compress(ary) | |
range_start = ary.first | |
compressed = [] | |
ary.each_with_index do |value, index| | |
# TODO: This could skip indices that have already been considered. |
#!/usr/bin/env bash | |
SCRIPT="script/myapp-${1}.sh" | |
shift | |
exec ${SCRIPT} ${@} |
class TanksForAllTheFish < RTanque::Bot::Brain | |
NAME = 'Tanks For All the Fish' | |
MAX_RANGE = 400.0 | |
include RTanque::Bot::BrainHelper | |
def tick! | |
if targets_nearby? | |
# command.speed = 2.0 | |
# command.heading = Random.rand(-1.0..1.0) |
class World | |
def initialize(cells) | |
@cells = cells | |
@row_count = cells.length | |
@col_count = cells[0].length | |
end | |
def living_neighbours(col, row) | |
[ | |
cell(col, row - 1), # NORTH |
class RubyProcess | |
WAIT_HELPER = <<-EOS | |
# Top-level method to signal the parent process | |
# and wait for an interrupt. | |
def wait_for(seconds) | |
# Signal parent we are ready. | |
Process.kill('USR1', Process.ppid) | |
# Wait for interrupt. | |
sleep(seconds) |
# If you want to check whether a string matches a regular expression, | |
# but not return the match data, you can just use === the case equality operator. | |
# Bad | |
!! ('foobar' =~ /bar/) #=> true | |
!! ('foo' =~ /bar/) #=> false | |
# Good | |
/bar/ === 'foobar' #=> true | |
/bar/ === 'foo' #=> false |
require 'io/console' | |
class PressAnyKey | |
MESSAGE = 'Press any key to continue...' | |
def initialize(console: nil, message: MESSAGE) | |
console ||= File.open('/dev/tty', 'w+') | |
console.puts message | |
console.raw { |io| io.readchar rescue nil } | |
rescue | |
warn "Couldn't connect to console!" |