Skip to content

Instantly share code, notes, and snippets.

View rab's full-sized avatar
👨‍💻
Home Office is a mess (as usual)

Rob Biedenharn rab

👨‍💻
Home Office is a mess (as usual)
View GitHub Profile
@rab
rab / test_new_fk_to_old_table.rb
Last active October 4, 2017 23:56
New bigint(20) cannot be FK reference to int(11)
# frozen_string_literal: true
# https://gist.github.com/rab/9b63001d5f926468afdfa00248cf648e
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
# frozen_string_literal: true
def get_input(prompt = '--> ')
puts ''
puts 'Please enter a number, odd or even.'
print prompt
# if the end-of-input was reached and gets returned a nil
# or the word 'exit' or 'quit' appears (ignoring case) in the input
if (input = gets).nil? || /exit|quit/i =~ input
nil # just return a nil
else
@rab
rab / Command producing the output
Created August 7, 2015 18:37
Array to Hash of counts
( time ruby ./count_bm.rb ; \
time ruby ./count_bm.rb 10000 10000 ; \
time ruby ./count_bm.rb 1000 100000 ; \
time ruby ./count_bm.rb 100000 10 \
) | tee count_bm.txt
module Beer
class Song
VERSE_TEMPLATE = "%d bottles of beer on the wall, %d bottles of beer.\n" +
"Take one down and pass it around, %d bottle%s of beer on the wall.\n"
PENULTIMATE_VERSE = "1 bottle of beer on the wall, 1 bottle of beer.\n" +
"Take it down and pass it around, no more bottles of beer on the wall.\n"
FINAL_VERSE = "No more bottles of beer on the wall, no more bottles of beer.\n" +
"Go to the store and buy some more, 99 bottles of beer on the wall.\n"
def verses(starting, ending=0)
@rab
rab / Gemfile
Created May 21, 2013 23:43 — forked from jimweirich/Gemfile
source 'https://rubygems.org'
gem 'celluloid'
gem 'celluloid-io'
@rab
rab / Ruby 2.0 Module#prepend
Created February 12, 2013 19:29
Experiments with where Module#prepend locates the module in the ancestors chain.
[ruby-2.0.0dev] code/ruby $ irb
irb2.0.0> module Bar; def who; puts 'bar'; end; end
#2.0.0 => nil
irb2.0.0> class Baz; def who; puts 'baz'; end; end
#2.0.0 => nil
irb2.0.0> class Foo < Baz; def who; puts 'foo'; end; end
#2.0.0 => nil
irb2.0.0> Foo.ancestors
#2.0.0 => [Foo, Baz, Object, Kernel, BasicObject]

Pi+RoR+Heroku Demo

Background

Over the course of the past two school years, my colleague Rob Biedenharn and I have been working with Tom Brinkmann's students at Little Miami High School, attempting to teach them Web development using Ruby on Rails to aid in their participation in Business Professionals of America competitions and to provide them with skills very much in demand locally.

We provided the students all the usual links to facilitate self-guided learning on Windows PCs but it quickly became evident that we were facing two challenges:

@rab
rab / CycleRGB.ino
Created January 20, 2013 03:13
Arduino Digispark Sketch for cycling the RGB Shield
const int ledRed = 0;
const int ledGreen = 1;
const int ledBlue = 2;
const unsigned long delayTime = 20;
// Base the cycle on the graph ( http://upload.wikimedia.org/wikipedia/commons/5/5d/HSV-RGB-comparison.svg )
// at http://en.wikipedia.org/wiki/HSL_and_HSV#From_HSV
int maxVal = 127;
@rab
rab / RobGreg.rb
Created November 21, 2012 01:13 — forked from st23am/robot3.rb
BaselineBot
require 'rrobots'
class RobGreg
include Robot
attr_reader :events
def near_a_wall?
x <= size || y <= size || x >= battlefield_width - size || y >= battlefield_height - size
end
@rab
rab / Bot.scala
Created November 14, 2012 01:02 — forked from geofflane/Bot.scala
Scalatron Bot
import util.Random
// rab - Rob Biedenharn
// based on Geoff Lane's Bot
// Wed Nov 14 17:44:48 EST 2012
/**
* This bot builds a 'direction value map' that assigns an attractiveness score to
* each of the eight available 45-degree directions. Additional behaviors:
* - aggressive missiles: approach an enemy master, then explode