Skip to content

Instantly share code, notes, and snippets.

@rwjblue
rwjblue / pconsole.sh
Created February 20, 2012 18:38 — forked from rondale-sc/pconsole.sh
pconsole bash/zsh alias
pconsole () {
if [[ -e ./config/environment.rb ]];
then
rails_env="development"
if [[ "$1z" != "z" ]]; then rails_env=$1; fi;
RAILS_ENV=$rails_env pry -r ./config/environment.rb -r rails/console/app -r rails/console/helpers;
else pry;
fi
}
@rwjblue
rwjblue / print_folder_tk.rb
Created June 26, 2012 18:09 — forked from pwelch/print_folder_tk.rb
Ruby/Tk script with GUI to print a folder using a system call to lp (CUPS). (Requires cups gem)
#!/usr/bin/env ruby
require 'tk'
require 'tkextlib/tile'
require 'tkextlib/bwidget'
require 'cups'
$dirname = TkVariable.new
root = TkRoot.new {title "Print Folder"}
@rwjblue
rwjblue / hour_intervals_from_times.rb
Created August 25, 2012 01:22 — forked from rondale-sc/hour_intervals_from_times.rb
Calculate percentage of interval covered within a given hour.
def hour_intervals(start_time, stop_time)
results = Hash.new {|h,k| h[k] = Hash.new(0)}
(start_time.to_i..stop_time.to_i).step(60).collect do |minute|
minute_time = Time.at(minute)
interval = case minute_time.min
when (0..14) then 0
when (15..29) then 15
when (30..44) then 30
when (45..59) then 45
set project_directory to do shell script "find ~/ ~/Source ~/Source/ruby ~/Source/ruby/webapps -maxdepth 1 -type d -name " & q & " | head -1"
on pathexists(path)
try
path as alias
return true
on error
return false
end try
end pathexists
class TestConnection
def repeat_test
while true do
if packet_loss > 0
`say 'link down'`
end
end
end
def packet_loss
@rwjblue
rwjblue / foo.diff
Created February 6, 2013 19:36 — forked from jonleighton/foo.diff
diff --git a/lib/spring/application.rb b/lib/spring/application.rb
index 6e241a8..69ef383 100644
--- a/lib/spring/application.rb
+++ b/lib/spring/application.rb
@@ -22,9 +22,6 @@ module Spring
@stdout = IO.new(STDOUT.fileno)
@stderr = IO.new(STDERR.fileno)
- @stdin = File.open('/dev/null', 'r')
-
require 'routes' # from routes.rb file below
class CreateRouteTests
def initialize(routes_file)
self.routes = ROUTES
end
def routes
@routes ||= ROUTES
end
def visible?(klass, name)
(klass.public_instance_methods + klass.public_class_methods).any? { |m| m.to_s == name }
end
private :visible?
@rwjblue
rwjblue / example.rb
Last active December 17, 2015 20:29
require 'rspec/autorun'
class Person
attr_accessor :first_name, :last_name, :gender
def full_name
"#{first_name} #{last_name}"
end
def self.average_age
var Component = Ember.Component.extend({
classNameBindings: [":title", "isFeatured::singlestat"],
valueListenerShouldGenerate: false,
isFeatured: false,
init: function() {
var statPoint = this,
statId = statPoint.get("stat.id");
this.statDidChange();