Skip to content

Instantly share code, notes, and snippets.

View mwlang's full-sized avatar

Michael Lang mwlang

View GitHub Profile
@mwlang
mwlang / quant_period.cr
Created September 29, 2021 22:17
A bounded deque that holds at most N items and tracks min and max as values are shifted and shoveled.
class QuantPeriod(T)
property max_size : Int32
property max : T = T.new(0)
property min : T = T.new(0)
def initialize(@max_size : Int32)
raise "max_size (#{@max_size}) must be > 1" if @max_size < 1
@deque = Deque(T).new(@max_size)
end
@mwlang
mwlang / _about.md
Last active July 27, 2021 19:25
A Ruby Thor script that will parse a Google Logging URL and render to console with `pull` or to a log file and opened in editor with `open`.

A Ruby Thor script that will parse a Google Logging URL and render to console with pull or to a log file and opened in editor with open.

The default editor when ENV "EDITOR" is not set is VS CODE, so code or ENV["EDITOR"] should be in your ENV $PATH -- open doesn't work with VIM as-is since the script already has the console that vim will want to use.

Example use:

ruby logs.rb open "https://console.cloud.google.com/logs/viewer?advancedFilter=resource.type%3D%22k8s_container%22%0Aresource.labels.project_id%3D%22devops-foo%0Aresource.labels.location%3D%22us-central1%22%0Aresource.labels.cluster_name%3D%22ci-gke-cluster%22%0Aresource.labels.namespace_name%3D%22foobar%22%0Aresource.labels.pod_name%3D%22qa-9999-smzc5%22%0A&amp;interval=NO_LIMIT&amp;project=devops-foo"
@mwlang
mwlang / delegating.rb
Created April 22, 2021 19:29
Tracer exploration
# This Tracer module is an overly simplified demonstration of what is currently implemented
# in our MethodTracer module. It shows the alternative implementation that completely eliminates
# the string evaluated code.
#
# This implementation also shows how to handle keyword arguments across Ruby versions
# Whether to trace with and without scope is not presented here, but it's fairly straightforward
# to conditionally handle options passed accordingly.
module Tracer
module_function
@mwlang
mwlang / _output.txt
Last active April 8, 2021 13:29
Example of how to handle varying method argument signatures across Rubies 2.2 - 3.0 and jRuby using ruby2_keywords. Run using Ruby's warn flag like so:
>> ruby -w delegating.rb
Foo says...
["hello", "world"]
========================================
Bar says...
["yo", "world"]
{}
****************************************
Foobar says...
"howdy"
FOO
====================
Hello
World
********************************************************************************
Traced!
Traced!
Hello
World
response # => #<HTTP::Client::Response:0x10fcb6b40
@body=nil,
@body_io=
#<HTTP::FixedLengthContent:0x10fcb23f0
@closed=false,
@continue_sent=false,
@decoder=nil,
@encoder=nil,
@encoding=IO::EncodingOptions(@invalid=:skip, @name="UTF-8"),
@expects_continue=false,
Gems included by the bundle:
* binding_of_caller (0.8.0)
* coderay (1.1.3)
* debug_inspector (0.0.3)
* ffi (1.13.1)
* formatador (0.2.5)
* guard (2.16.2)
* guard-compat (1.2.1)
* guard-minitest (2.4.6)
* hometown (0.2.5)
@mwlang
mwlang / _README.md
Last active February 12, 2020 18:44
Easy git branch checkout by Jira ticket
  1. Save jira-co.rb to a folder on your $PATH (for example ~/bin).
  2. chmod +x jira-co.rb to make it executable.
  3. Add git alias to your ~/.gitconfig like so:
[alias]
  co-jira = !sh -c 'jira-co.rb $1' -
  1. Switch to your repo's folder and use it!
&gt;&gt; git co-jira ruby-2379
@mwlang
mwlang / jira-co.rb
Created February 12, 2020 18:38
Save jira-co.rb to a folder on your $PATH (for example ~/bin). Add git alias to your ~/.gitconfig
#!/usr/bin/env ruby
pattern = ARGV[0]
if pattern.to_s == ""
puts "Must supply a pattern for the branch. i.e. RUBY-2379"
exit 1
end
branches = `git branch -a | grep "remotes" | grep -i #{pattern}`.split("\n").map(&:strip)
@mwlang
mwlang / warnings.txt
Created December 9, 2019 16:18
A few examples of new warnings I'm seeing from >= Ruby 2.6 while running rake test
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/command.rb:33: warning: instance variable @match not initialized
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/command.rb:33: warning: instance variable @match not initialized
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/command.rb:39: warning: instance variable @description not initialized
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/command.rb:39: warning: instance variable @description not initialized
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/command.rb:33: warning: instance variable @match not initialized
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/commands/shell_command.rb:3: warning: ambiguous first argument; put parentheses or a space even after `/' operator
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/command.rb:33: warning: instance variable @match not initialized
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/command.rb:33: warning: instance variable @match not initialized
~/.rvm/gems/ruby-2.6.3/gems/pry-0.9.12.6/lib/pry/c