./binary_name # run default task
./binary_name greeting # run greeting task
./binary_name -T # list tasks
./binary_name -h # helpOr put on PATH and use binary_name …
./binary_name # run default task
./binary_name greeting # run greeting task
./binary_name -T # list tasks
./binary_name -h # helpOr put on PATH and use binary_name …
| #!/usr/bin/env ruby | |
| require 'time' | |
| require 'bundler/inline' | |
| gemfile do | |
| source 'https://rubygems.org' | |
| gem 'faraday' |
| /random.* |
| /*.gem | |
| /Gemfile.lock | |
| /data/ |
| #!/usr/bin/env ruby | |
| require 'logger' | |
| require_relative 'graphite' | |
| # https://hackaday.io/project/5301-reverse-engineering-a-low-cost-usb-co-monitor | |
| class CO2Reader | |
| MAGIC_BYTES = 'Htemp99e'.bytes.map{ |b| ((b >> 4) | (b << 4)) & 0xff } | |
| MAGIC_ORDER = [2, 4, 0, 7, 1, 6, 5, 3] |
| def (Rails.logger).red(*args) | |
| s = "\e[31m" | |
| if match = caller.first.match(/^(.*):(\d+)(?:$|:in `)/) | |
| path = match[1] | |
| line_number = match[2].to_i | |
| code = begin | |
| File.open(path) do |f| | |
| (line_number - 1).times { f.gets } | |
| f.gets[/red\s*(.*)\s*/, 1] | |
| end |
| require 'benchmark' | |
| def sh_command_v(name) | |
| path = `sh -c 'command -v #{name}'`.strip | |
| path unless path.empty? | |
| end | |
| def sh_which(name) | |
| path = `which #{name}`.strip | |
| path unless path.empty? |
| # started with http://www.postal-code.com/binarycode/2009/06/06/better-range-intersection-in-ruby/ | |
| # added handling of exclude_end | |
| # fixed slowness with ruby 1.8 as even `0...10000000 & 5000000...15000000` took few seconds to run | |
| class Range | |
| def intersection(other) | |
| raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range) | |
| intersection_begin = case | |
| when self.include?(other.begin) |