Skip to content

Instantly share code, notes, and snippets.

# based on http://gist.github.com/339028
module Base
module Plugins
def plugins
@plugins ||= []
end
def activate( plugin_name )
plugin = Base::Plugins.const_get plugin_name.capitalize
@JoshCheek
JoshCheek / 1_quine.rb
Created March 27, 2010 19:47
4 ruby quines in 1, based off solutions at http://tinyurl.com/yhdrdnd , only the printf one is from my own brain
printf a="%1$s a=%2$s , '%1$s' , a.inspect" , 'printf' , a.inspect
# test suite for http://www.rubyproblems.com/problems/2010/04/geography_lesson
def run_test( input , x , y )
it "should return [#{x},#{y}] when given #{input.inspect}" do
LatLon.to_xy(input).should == [ x , y ]
end
end
describe 'LatLon.to_xy' do
@JoshCheek
JoshCheek / config.ru
Created June 15, 2010 04:15
First (test) Rack app: Generates random numbers.
# RESULT CAN BE SEEN AT http://furious-day-14.heroku.com/
#
#
# Sat down to watch this video about rack http://confreaks.net/videos/49-mwrc2009-in-a-world-of-middleware-who-needs-monolithic-applications
# About 17 min in at the moment, figured I'd verify what the guy was saying. Ended up with this simple script to generate random numbers.
# Figured I'd see if I could get it on heroku, looked up this blog I had read a few months ago http://blog.heroku.com/archives/2009/3/5/32_deploy_merb_sinatra_or_any_rack_app_to_heroku/
# Tried it all out, and it worked!
#
# Regarding the code, I don't think it would scale well. I'll need to spend some time thinking about the implications of this sort of environment.
# For example: validating urls, handling exceptions, giving help file, generating content all in one class gets some ugly coupling between methods.
@JoshCheek
JoshCheek / gist:443394
Created June 18, 2010 08:14
YUI RTE Image Upload For Rails
# A Rails back end for yui rich text editor's image uploader
# http://allmybrain.com/2009/07/01/example-image-upload-with-yui-rich-text-editor-270/
# In this example, I created a model to store the images, with paperclip, on Amazon s3
# If you aren't familiar with Paperclip, I think there is a Railscast about it
# ===== THE MIGRATION =====
class CreateUploadedImages < ActiveRecord::Migration
def self.up
create_table :uploaded_images do |t|
@JoshCheek
JoshCheek / Dialer.java
Created June 18, 2010 17:17
Example of how to use a Java interface as a type
// note that all the static keywords on the methods and interface are just b/c I'm implementing these as belonging to the Dialer class
// rather than as belonging to an instance of Dialer
// if you aren't nesting them like this (which you prbably aren't) then you won't need to do that
public class Dialer {
public abstract static interface Dialable { public abstract String dial(); }
public static class Phone implements Dialable {
private String number;
@JoshCheek
JoshCheek / gist:456813
Created June 29, 2010 05:06
Code snippets to help resolve an issue where my popup window can't find my YUI RTE editor from the opening page
// definition of the editor
YAHOO.widget.Logger.enableBrowserConsole();
var myEditor = new YAHOO.widget.Editor('wysiwyg', {
height: '300px' ,
width: '100%' ,
dompath: false ,
animate: true ,
handleSubmit: true ,
collapse: false ,
@JoshCheek
JoshCheek / gist:463507
Created July 4, 2010 15:02
how to render haml
require 'rubygems'
require 'haml'
@query = 'search term'
puts Haml::Engine.new(<<HAML).render binding
%p
results found for
%strong= @query
#!/usr/bin/env ruby
# A poor man's implementation of the tree app http://trac.macports.org/browser/trunk/dports/sysutils/tree/Portfile
# Written in part because I like the app and wanted that functionality on my school computer
# and in part because I was going through some videos about the command line, and wanted something interesting
# to put in my ~/bin dir
#
# AUTHOR: Josh Cheek
# 5 July 2010
# for http://groups.google.com/group/sinatrarb/browse_thread/thread/f076b033cf87efd3/c5dd8f47c87e798f
# an example of my spec_helper.rb, which put Warden into the middleware, which fixed the problem
require 'rack/test'
ENV['RACK_ENV'] = 'test'
ENV["RAILS_ENV"] ||= 'test' # don't know if we need this or not