Skip to content

Instantly share code, notes, and snippets.

View stellard's full-sized avatar
🇺🇦

Scott Ellard stellard

🇺🇦
View GitHub Profile
# mongo_template.rb
# fork of Ben Scofield's Rails MongoMapper Template (http://gist.github.com/181842)
#
# To use:
# rails project_name -m http://gist.github.com/gists/219223.txt
# remove unneeded defaults
run "rm public/index.html"
run "rm public/images/rails.png"
run "rm public/javascripts/controls.js"
@stellard
stellard / System Call Test
Created December 27, 2010 19:37
This test shows that system calls can still be made with no privileges given
require "test/unit"
require "rubygems"
require "shikashi"
class SystemCalls < Test::Unit::TestCase
def test_backtick_call_should_raise_error
priv = Shikashi::Privileges.new
assert_raise SecurityError do
Shikashi::Sandbox.new.run("`ls`", priv)
@stellard
stellard / Mongoid Embed Hash Query
Created January 4, 2011 10:43
This test shows how you cannot search on an embedded document's hash
require "test/unit"
require "rubygems"
require "mongoid"
Mongoid.configure do |config|
name = "embed_hash_test"
host = "localhost"
config.master = Mongo::Connection.new.db(name)
config.persist_in_safe_mode = false
end
require 'rubygems'
require 'rspec'
def split(original)
original.split("/").inject([]) do |result, element|
result + [(result.last||[]) + [element]]
end.reverse.map{ |variation| variation.join("/") }
end
@stellard
stellard / array_counter.rb
Created May 25, 2011 00:45
Counter of mixed base
class RolloverIndex
attr_accessor :max, :count
def initialize max, start = 0
self.max = max
self.count = start
end
def inc
if (self.count + 1) == max
@stellard
stellard / scott_trace.rb
Created March 23, 2012 09:46
Scott Trace
# -*- encoding : utf-8 -*-
class Object
def scott_trace
now = Time.now
$last_scott_trace ||= now
diff = now - $last_scott_trace
notify = diff > 1 ? "!!!!!!!!!!!!!!" : ""
puts "#{notify} RAM USAGE: #{`ps -o rss= -p #{$$}`.to_f / 1000.0} MB TIME:#{now - $last_scott_trace}, CALLER: #{CallChain.caller_info.inspect}"
$last_scott_trace = now
@stellard
stellard / music_converter.rb
Created April 5, 2012 22:59
Convert music files
#!/usr/bin/ruby
require 'rubygems'
dir = ARGV.first
unless dir
puts "must supply a directory" unless dir
puts "USAGE:"
puts "music_convert directory"
@stellard
stellard / pipeline_lookup_transform.rb
Created April 11, 2012 16:57
pipeline lookup transform
module ETL #:nodoc:
module Transform #:nodoc:
# Transform which looks up the value and replaces it with another previously seen in the pipline
class PipelineLookupTransform < ETL::Transform::Transform
class DuplicateKeyError < ETLError #:nodoc:
end
# The resolver to use if the foreign key is not found in the collection
attr_accessor :resolver
Apr 26, 2012 4:54:28 PM org.apache.catalina.core.StandardServer await
INFO: A valid shutdown command was received via the shutdown port. Stopping the Server instance.
Apr 26, 2012 4:54:28 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-8080"]
Apr 26, 2012 4:54:28 PM org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
@stellard
stellard / ensure_inclusion_of_spec.rb
Created May 26, 2012 20:59
ensure_inclusion_of_spec.rb
require 'rspec'
require 'rails'
require 'shoulda-matchers'
CORRECT_ARRAY = %w(one two three)
WRONG_ARRAY = %w(wrong array)
class Nothing