Skip to content

Instantly share code, notes, and snippets.

Keith Bennett keithrbennett

Block or report user

Report or block keithrbennett

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
keithrbennett / spec.out
Last active Oct 21, 2019
Output of 1092 Diaperbase tests: rspec --tag focus spec/system/admin/barcode_items_system_spec.rb
View spec.out
Iteration # 0, start time: 2019-10-21 01:39:25 +0700
DEPRECATION WARNING: Single arity template handlers are deprecated. Template handlers must
now accept two parameters, the view object and the source for the view object.
>>, source)
keithrbennett / organize-av-files
Last active Oct 11, 2019
Helps separate your audio and video files into saves and deletes using Ruby and MPlayer.
View organize-av-files
#!/usr/bin/env ruby
# organize-av-files - Organizes files playable by mplayer
# into 'saves', 'deletes', and 'undecideds' subdirectories
# of the current working directory.
# Be careful, if you specify files to process in multiple directories,
# they will all be moved to the same subdirectories, so they will no
# longer be organized by directory, and if there are multiple files
# of the same name, some may be lost if overwritten.
keithrbennett / rack_show_env.rb
Created Jul 5, 2019
Illustrates one way to output the 'env' hash that Rack produces in a very human readable format.
View rack_show_env.rb
# Illustrates one way to output the 'env' hash that Rack produces in
# a very human readable format.
# Stored at
require "rack"
require "thin"
require 'awesome_print'>(env) do
View rack_of_lambdas_method_returning_lambda.rb
# Like the previous gist (
# but illustrates a use case more similar to the class based approach
# illustrated in
# In this code, a method is called to return a lambda that calls the passed inner app.
# This code is stored at
require "rack"
require "thin"
keithrbennett / rack_of_lambdas.rb
Last active Jul 5, 2019
Illustrates the outer middleware in a Rack script can be a lambda.
View rack_of_lambdas.rb
# Illustrates that a Rack outer app can be a lambda.
# This code is stored at
# See another approach at
require "rack"
require "thin"
# Using a StringIO in case strings will be frozen.
keithrbennett / remind
Last active Jun 24, 2019
For the Mac command line, notifies as stdout, voice, and Mac notification after user specified delay
View remind
This file has moved to a git repo, at
keithrbennett / vol.rb
Last active May 11, 2019
Controls and displays volume settings on the Mac command line.
View vol.rb
#!/usr/bin/env ruby
# This file's home is at
# With a numeric argument from 0 to 100,
# sets volume to that %, and outputs new volume settings.
# Without any argument, outputs volume settings.
# Author: Keith Bennett (keithrbennett on Github)
keithrbennett / ruby-lambda-presentation.txt
Last active Apr 9, 2019
Text and code for Functional Programming in Ruby presentation.
View ruby-lambda-presentation.txt
Source Code for Ruby Lambdas Presentation
# This is the source code included in the Ruby Lambdas presentation
# given at Ruby Tuesday, Penang, Malaysia, 9 April 2019.
# This file is available at:
# and the presentation slides PDF is at:
keithrbennett / special_prune.rb
Last active Oct 9, 2018
A solution to including duplicates of some classes but not others
View special_prune.rb
#!/usr/bin/env ruby
# A solution to the problem where one wants to create a new array
# that includes all instances of A and B but only the first instances
# of C & D.
require 'set'
class A; end
class B; end
keithrbennett / alpha_counter.txt
Created Sep 30, 2018
Illustrates using built-in Ruby counter to present numbers as upper case strings including 'A' - 'Z'.
View alpha_counter.txt
2.5.1 :022 > def fmt(n); n.to_s(26) { |c| (c.ord + 16).chr }.join; end
=> :fmt
2.5.1 :023 > def val(s); { |c| (c.ord - 16).chr }.join.to_i(26); end
=> :val
2.5.1 :024 > n = (26 * 26) + (2 * 26) + 3 # 'ABC'
=> 731
2.5.1 :025 > fmt n
=> "ABC"
2.5.1 :026 > val 'ABC'
=> 731
You can’t perform that action at this time.