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
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.
Change:
>> PrawnRails::Renderer.call(template)
To:
>> PrawnRails::Renderer.call(template, source)
@keithrbennett
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
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 https://gist.github.com/keithrbennett/a279c4ae0166cdb004131057fdb13d4c.
require "rack"
require "thin"
require 'awesome_print'
Rack::Handler::Thin.run(->(env) do
View rack_of_lambdas_method_returning_lambda.rb
# Like the previous gist (https://gist.github.com/keithrbennett/b178fe4b9910bfcc4ed6d76dc5411feb)
# but illustrates a use case more similar to the class based approach
# illustrated in https://thoughtbot.com/upcase/videos/rack.
# In this code, a method is called to return a lambda that calls the passed inner app.
# This code is stored at https://gist.github.com/keithrbennett/08aa675f04353b7c3a9faef2c53cddc8.
require "rack"
require "thin"
@keithrbennett
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 https://gist.github.com/keithrbennett/b178fe4b9910bfcc4ed6d76dc5411feb.
# See another approach at https://gist.github.com/keithrbennett/08aa675f04353b7c3a9faef2c53cddc8.
require "rack"
require "thin"
# Using a StringIO in case strings will be frozen.
BODY = StringIO.new
@keithrbennett
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 https://github.com/keithrbennett/mac-cl-remind/blob/master/remind.
@keithrbennett
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 https://gist.github.com/keithrbennett/fcf8d1511a430dd2cbc3bafdfe81ba59.
# 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
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:
# https://gist.github.com/keithrbennett/927c989cc301c63d35a8ceec9f3f9404
# and the presentation slides PDF is at:
# https://speakerdeck.com/keithrbennett/ruby-lambdas
@keithrbennett
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
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).chars.map { |c| (c.ord + 16).chr }.join; end
=> :fmt
2.5.1 :023 > def val(s); s.chars.map { |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.