Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'sinatra'
get '/' do
"Hello from Sinatra running on Java!"
end
require 'rbconfig'
$stdout.sync = true
def hello(source, expect_input)
puts "[child] Hello from #{source}"
if expect_input
puts "[child] Standard input contains: \"#{$stdin.readline.chomp}\""
else
puts "[child] No stdin, or stdin is same as parent's"
# Demonstration of a handful of the metaprogramming features of Ruby.
#
# This code uses the same class/module configuration as Rails' standard
# acts_as plugins. I was looking for a way to extend the behavior of an
# ActiveRecord model in practice, and this came out of that exploration.
#
# Each "method" of extending the target class is tested and evaluated
# for functionality and a report is printed.
#
# Each method is tested as a class method and an instance method,

Installing Panda on your local machine or server

This guide is an alternative to using the prebuilt AMI which includes all the software required to run Panda.

Please note that this guide been mainly tested on OSX and Ubuntu. Please post modifications to the mailing list if you try another platform.

Before starting, your system must have a working Ruby (1.8.x) installation along with Rubygems (>= 1.3.1) and MySQL running happily.

Install dependencies

# download, from_repo, and commit_state methods swiped from
# http://github.com/Sutto/rails-template/blob/07b044072f3fb0b40aea27b713ca61515250f5ec/rails_template.rb
require 'open-uri'
def download(from, to = from.split("/").last)
#run "curl -s -L #{from} > #{to}"
file to, open(from).read
rescue
puts "Can't get #{from} - Internet down?"
class AddAttachmentsDataToWrapper < ActiveRecord::Migration
def self.up
add_column :wrappers, :data_file_name, :string
add_column :wrappers, :data_content_type, :string
add_column :wrappers, :data_file_size, :integer
add_column :wrappers, :data_updated_at, :datetime
end
def self.down
remove_column :wrappers, :data_file_name
def transform_hash(original, options={}, &block)
original.inject({}){|result, (key,value)|
value = if (options[:deep] && Hash === value)
transform_hash(value, options, &block)
else
value
end
block.call(result,key,value)
result
}
@stonegao
stonegao / gist:246120
Created December 1, 2009 06:56 — forked from pat/gist:246100
# I want to check if Sphinx is installed on machines to auto-determine the
# version. This can be done via the following line of code:
`indexer`[/^Sphinx (\d\.\d\.\d)/, 1]
# But, if indexer doesn't exist, then we get an error sent to the shell by Ruby
# (though it's not caught by $stdout/$stderr, so I assume it's core Ruby being
# inconsistent).
#
# I don't want the error - I have code in place to let the user know that
module Rack
class MemoryBloat
def initialize(app, logger)
@app = app
@logger = logger
end
def call(env)
memory_usage_before = memory_usage
result = @app.call(env)