Skip to content

Instantly share code, notes, and snippets.

@danlucraft
danlucraft / enter_the_matrix.rb
Created April 21, 2011 22:33
Bot for playing rdrc2 Enter the Matrix game
require 'pp'
require 'rubygems'
require 'mechanize'
class MatrixInterface
CREDS = File.read("creds.txt").split(",")
def initialize
login_page = agent.get("http://reddirtrubyconf.com/login")
require 'jruby/profiler'
profile_data = JRuby::Profiler.profile do
# code to be profiled....
end
my_output_stream = java.io.ByteArrayOutputStream.new
print_stream = java.io.PrintStream.new(my_output_stream)
profile_printer = JRuby::Profiler::GraphProfilePrinter.new(profile_data)
@danlucraft
danlucraft / sync.rb
Created January 27, 2011 09:30
handy script for rsyncing between machines
require 'rubygems'
require 'fsevents'
require 'fileutils'
STDOUT.sync = true
project = ARGV[0] || 'skweb'
options = {
:directory_to_watch => "/Users/danlucraft/Songkick/#{project}",
/Users/danlucraft/Redcar/redcar/plugins/project/lib/project/find_recent_dialog.rb:11:in `selected': undefined local variable or method `path' for #<Redcar::Project::FindRecentDialog:0xc723e8> (NameError)
from /Users/danlucraft/Redcar/redcar/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb:188:in `selected'
from /Users/danlucraft/Redcar/redcar/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb:194:in `key_pressed'
from /Users/danlucraft/Redcar/redcar/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb:95:in `keyPressed'
from /Users/danlucraft/Redcar/redcar/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb:124:in `open'
from /Users/danlucraft/Redcar/redcar/plugins/application_swt/lib/application_swt/dialogs/filter_list_dialog_controller.rb:75:in `to_proc'
from /Users/danlucraft/Redcar/redcar/plugins/core/lib/core/observable.rb:1
# The Great Computer Language Shootout
# http://shootout.alioth.debian.org/
#
# contributed by Gabriele Renzi
class PiDigitSpigot
def initialize()
@z = Transformation.new 1,0,0,1
@x = Transformation.new 0,0,0,0
{
"commands" : [
{
"name": "Up / of1-dev-dan",
"command": "rsync -rulz --delete --exclude=\".git\" --delete-excluded . of1-dev-dan:/home/dan/development/skweb",
"description": "Rsyncs up",
"type": "task/rsync"
},
{
"name": "Down / of1-dev-dan",
@danlucraft
danlucraft / gist:655190
Created October 30, 2010 10:48
Handy class for determining if data is binary.
class ProjectSearch
# This class discriminates between binary and textual data.
class BinaryDataDetector
# Is the data binary?
#
# @param [String] data
def self.binary?(data)
not textual?(data)
end
>> 60*60*24
=> 86400
>> 1.day
=> 1 day
>> 1.day.class
=> Fixnum
@danlucraft
danlucraft / highlight_api.rb
Created October 24, 2010 09:22
Let's try and figure out what a highlighting API could look like
class EditView
def highlight(offset, length, colour)
end
def clear_all_highlights
end
def clear_highlights_on_line(line_num)
end
end
Feature: Predictive macros
As a user
I want Redcar to read my mind
So I don't have to type stuff
Background:
When I open a new edit tab
Scenario: Repeat simple command sequence that is fully repeated
When I type "abab"