Skip to content

Instantly share code, notes, and snippets.

#This Ugly hack adds Json as one of the types hardcoded to use TEXT.
#
# The problem this solves is this
#
# class A
# include DataMapper::Resource
# property :id, Serial
# property :stuff, DataMapper::Types::Json
# end
# DataMapper.auto_migrate!
class RequireSSL
def initialize app,options={}
@app = app
end
def call_ env
request = ::Rack::Request.new env
unless secure? env
[302,{"Location"=> request.url.sub('http://','https://')},'']
else
@app.call env
#!/usr/bin/env ruby
args = ARGV.dup
snark_for_options = {
'-l' => "You can't do anything, you can't even spell sudo",
'-s' => "Don't even think of running as the uper suser.",
'-b' => "Run it in the background? Hah, fat chance.",
'-e' => "Edit which file? Oh wait, you can't"
}
indent = " "*4
additional_snark = args.map{|arg| indent + snark_for_options[arg].to_s if snark_for_options[arg]}.join "\n"
# I doubt this even works, I just was looking at Rack::Auth::Digest::MD5
# and realized that you can't use it with the Rack::Builder dsl because it
# needs things set after it has been initialized.
# This bothered me, so I blocked this out.
# Doing it this way rather than passing a self block allows it to
# continue to act like Rack::Auth::Basic does.
# My main annoyance was that the interfaces differ in ways that seem to
# make little sense to me.
module Rack::Auth::UsableDigestMD5
---
body_id: not_found
title: 404 File Not Found
filter:
- erb
- textile
---
h1. <%= @page.title%>
=begin
I was trying to setup some behavior where if
a new object's parent was not saved, I could
communicate the errors to the user using the standard model.errors stuff
and ran into a problem.
'before :save' does not run before :save, it runs before save_self
since save looks like this:
chainable do
def save
class SomethingAwesome
include Singleton
def method_missing method,*args
instance.send method,*args
end
alias :old_respond_to? :respond_to?
def respond_to? method
instance.respond_to?(method) || old_respond_to?(method)
end
end
# I want to be able to check the validity of the parent object
# before saving, and maybe modify it, but I can't use 'before :save'
# because those hooks only run if save_parents is true
#
# I would prefer to not use save_parents because it is part of
# the private api, but this seems to be the best solution
# I've yet to come across.
#
require 'rubygems'
gem 'dm-core','= 0.10.1'
# My monkey patch to couchrest to make it work transparently
# with couchdb 0.8, the version currently in debian and ubuntu.
#
#----making couchrest view 0.8 friendly----
#autoloading for monkey patching
CouchRest::Server
CouchRest::Database
module CouchRest
#http://groups.google.com/group/watir-general/browse_thread/thread/d5d420fd56147501
module FireWatir
class Firefox
# - gets all cookies from browser
def getAllCookies
jssh_command = "var comp = #{WINDOW_VAR}.Components; var cookieMgr =
comp.classes[\"@mozilla.org/cookiemanager;
1\"].getService(comp.interfaces.nsICookieManager);"