Skip to content

Instantly share code, notes, and snippets.

@AJFaraday
AJFaraday / gist:907ded93cade7d57988e
Created September 12, 2014 15:39
Just discovered this line in my cron tab...
# m h dom mon dow command
41 9 19 12 * cd /home/ajfaraday/NetworkEnsemble/ && ruby script/play.rb sequences/christmas/flashmob.csv
class Santa < Elf
ATTRIBUTES = ['Jolly','Old']
has_many :children
def christmas
list = children.where(:behaviour => 'nice')
2.times do
list.reject!{|x| x.naughty? }
Line 3:
9: comma
18: comma
29: comma
Line 4:
10: comma
31: comma
Line 7:
2: letter i missing a dot
9: open square brackets ( [ )
TOLERANCE = 50
def near_top_wall?
sensors.position.y >= (arena.height - TOLERANCE)
end
def near_bottom_wall?
sensors.position.y <= TOLERANCE
end
@AJFaraday
AJFaraday / gist:6b11a6f350de2b3c9297
Created July 15, 2015 12:39
migrations on inconsistent databases (work-around)
module ActiveRecord
class Migration
def self.rename_table_if_needed(old_name, new_name)
rename_table(old_name, new_name)
rescue => ex
puts "rename_table(#{old_name},#{new_name}) failed #{ex.message}"
end
@AJFaraday
AJFaraday / _form.html.erb
Created July 29, 2015 09:20
Indentation oddity in Rubymine (JS embedded in ERB)
<!-- Some form or other -->
<script type='application/javascript'>
// Expected indentation
<% if @validate %>
run_validation();
<% end %>
// rubymine standard indentation
@AJFaraday
AJFaraday / gist:38f6f04f4d756350c71d
Created August 5, 2015 18:34
error on sonic_pi install
ajfaraday@ajf-samsung:~/work/sonic-pi-v2.6.0/app/server/bin$ ./compile-extensions.rb
Clearing ./../rb-native/linux/2.2.1p85
Creating ./../rb-native/linux/2.2.1p85
Compiling native extension in /home/ajfaraday/work/sonic-pi-v2.6.0/app/server/vendor/rugged/ext/rugged
./compile-extensions.rb:63:in `chdir': No such file or directory @ dir_chdir - /home/ajfaraday/work/sonic-pi-v2.6.0/app/server/vendor/rugged/ext/rugged (Errno::ENOENT)
from ./compile-extensions.rb:63:in `block in <main>'
from ./compile-extensions.rb:56:in `each'
from ./compile-extensions.rb:56:in `<main>'
ajfaraday@wreck-it:~/work/zoo$ ruby script/01_eat.rb
Found Cow named Bessie
Bessie is munching some grass
Found Dog named Shep
/home/ajfaraday/work/zoo/lib/animal.rb:14:in `eat': Bad Dog! You are not allowed to eat Bessie (RuntimeError)
from script/01_eat.rb:7:in `<main>'
require 'libusb'
usb_context = LIBUSB::Context.new
device = usb_context.devices(
idVendor: 0x054c, idProduct: 0x0002
).first
handle = device.open
x = handle.control_transfer(
:bmRequestType => 0x21,
@AJFaraday
AJFaraday / Bieber wedding proposals
Created March 28, 2011 10:23
Bieber wedding proposals
require 'rubygems'
require 'twitter'
search = Twitter::Search.new
i = 0
search.containing("marry me").to("justinbieber").each do |r|
puts "#{r.from_user}: #{r.text}"
i += 1
end
puts i