Skip to content

Instantly share code, notes, and snippets.

View mjfreshyfresh's full-sized avatar

MJ mjfreshyfresh

  • Extreme Networks
  • Oregon
View GitHub Profile
# With classy style sinatra you'll want to set raise_errors so the error block
# executes, hoptoad knows and the user gets a 500 page
configure do
set :raise_errors, false
end
mysql> desc menu_items;
+-------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| uri | varchar(250) | YES | MUL | NULL | |
| plan | varchar(250) | YES | MUL | NULL | |
| type | varchar(50) | YES | MUL | NULL | |
| title | text | YES | | NULL | |
| date_served | date | YES | | NULL | |
def self.create_from_xml_node(xml, plan)
begin
title_parts = xml.search('title').first.content.split(':')
title_parts = xml.search('title').first.content.split(' - ') if title_parts.nil? || title_parts.length < 2
summary_html = xml.search('summary').first.content
params = {}
params[:plan] = plan
params[:uri] = xml.search('id').first.content
params[:type] = title_parts[0]
# before filter
before do
p = request.env['PATH_INFO']
@request_url = p[1..p.length] unless p.nil?
end
# app_helper
def callback_attribute
if defined?(@request_url) && !@request_url.nil?
"callbackurl='#{link_to_app(@request_url)}?_method=GET'"
if env["REQUEST_METHOD"] == "POST"
req = Request.new(env)
method = req.params[METHOD_OVERRIDE_PARAM_KEY] || env[HTTP_METHOD_OVERRIDE_HEADER]
method = method.to_s.upcase
if HTTP_METHODS.include?(method)
env["rack.methodoverride.original_method"] = env["REQUEST_METHOD"]
env["REQUEST_METHOD"] = method
end
end
@mjfreshyfresh
mjfreshyfresh / gist:208715
Created October 12, 2009 20:44
I've got this in the new match app, which I think is a much better way to get at absolute image URLs, which are needed for FB tab content.
alias :url_for :link_to_app
def url_for_img(filename)
url_for "/img/#{filename}", :skip_facebook => true
end
ENV['SAILS_ENV'] = 'mj_dev'
require 'spec'
require File.expand_path(File.dirname(__FILE__)) + '/../../config/boot.rb'
describe 'Rivalry' do
it "should instantiate a rivalry from two rivals" do
puts "run test"
rivals = [
rake rack_hoptoad:spec --trace
(in /home/deploy/junk/rack_hoptoad)
** Invoke rack_hoptoad:spec (first_time)
** Invoke rack_hoptoad:clobber_spec (first_time)
** Execute rack_hoptoad:clobber_spec
rm -r coverage
** Execute rack_hoptoad:spec
Rack::HoptoadNotifier
- yields a configuration object to the block when created (PENDING: TODO)
NOTE: Put in ~/.irbrc
---
:update_sources: true
:bulk_threshold: 1000
:sources:
- http://gems.rubyforge.org/
- http://gems.github.com
- http://gems.github.com
gem: --no-ri --no-rdoc
macbook$ ./script/console
Loading development environment (Rails 2.1.1)
>> a = Album.find(:first)
=> #<Album id: 1, artist_id: 1, producer_id: 1, title: "LIGHT YOUR FIRE ", audioformat_id: 3>
>>