Skip to content

Instantly share code, notes, and snippets.

View metavida's full-sized avatar

Marcos Wright-Kuhns metavida

View GitHub Profile
@metavida
metavida / Trac -> Redmine Textmate Command.rb
Created October 6, 2008 15:44
A Textmate Command that helps in the conversion of wiki documents from Trac to Redmine.
#!/usr/bin/env ruby
# In it's current state, this script is not meant as a catch-all converter
# but should give you a good start.
# Requirements:
# * Textmate <http://macromates.com/>
# Know issues:
# * Changes all [] => [[]] - even inside code blocks.
@metavida
metavida / sample.html
Created December 16, 2008 12:15
A few code samples from the StatCounter blog: http://blog.statcounter.com/2008/12/using-html-to-format-a-statcounter/ with alternative markup using CSS
<!-- Big Purple -->
<!-- The way StatCounter suggested -->
<div style="font-size:32px;">
<font face="Verdana" color="#800080"><b>
<!-- Start of StatCounter Code -->
<script type="text/javascript">
var sc_project=4296912; ...
...</a></div></noscript>
<!-- End of StatCounter Code -->
</b></font></div>
@metavida
metavida / gist:85595
Created March 25, 2009 17:34
How to retrieve a User record via the Haiku LMS API, using Ruby.
require 'rubygems'
require 'oauth'
require 'xmlsimple'
# Create an OAuth Consumer with the appropriate API key and secret.
@consumer = OAuth::Consumer.new("api_key_EUNzNgVkrpFUFg", "api_secret_KBq6hTvjjvqAWOPz6c4WnQHN6jvkU8", { :site=>"https://my-domain.haikulearning.com" })
# Create an OAuth Access Token using your personal key and secret.
@access_token = OAuth::AccessToken.new(@consumer, "token_959b3659b65ddbb6f8552c3401", "secret_40ec1d3617e7f58811c2f1e4416dcf2f7")
@metavida
metavida / gist:87846
Created March 30, 2009 15:54
How to create a User record via the Haiku LMS API, using Ruby.
require 'rubygems'
require 'oauth'
require 'xmlsimple'
# Create an OAuth Consumer with the appropriate API key and secret.
@consumer = OAuth::Consumer.new("api_key_EUNzNgVkrpFUFg", "api_secret_KBq6hTvjjvqAWOPz6c4WnQHN6jvkU8", { :site=>"https://my-domain.haikulearning.com" })
# Create an OAuth Access Token using your personal key and secret.
@access_token = OAuth::AccessToken.new(@consumer, "token_959b3659b65ddbb6f8552c3401", "secret_40ec1d3617e7f58811c2f1e4416dcf2f7")
@metavida
metavida / gist:88282
Created March 31, 2009 17:22
How to update a User record via the Haiku LMS API, using Ruby.
require 'rubygems'
require 'oauth'
require 'xmlsimple'
# Create an OAuth Consumer with the appropriate API key and secret.
@consumer = OAuth::Consumer.new("api_key_EUNzNgVkrpFUFg", "api_secret_KBq6hTvjjvqAWOPz6c4WnQHN6jvkU8", { :site=>"https://my-domain.haikulearning.com" })
# Create an OAuth Access Token using your personal key and secret.
@access_token = OAuth::AccessToken.new(@consumer, "token_959b3659b65ddbb6f8552c3401", "secret_40ec1d3617e7f58811c2f1e4416dcf2f7")
@metavida
metavida / gist:88303
Created March 31, 2009 17:55
How to delete a User record via the Haiku LMS API, using Ruby.
require 'rubygems'
require 'oauth'
require 'xmlsimple'
# Create an OAuth Consumer with the appropriate API key and secret.
@consumer = OAuth::Consumer.new("api_key_EUNzNgVkrpFUFg", "api_secret_KBq6hTvjjvqAWOPz6c4WnQHN6jvkU8", { :site=>"https://my-domain.haikulearning.com" })
# Create an OAuth Access Token using your personal key and secret.
@access_token = OAuth::AccessToken.new(@consumer, "token_959b3659b65ddbb6f8552c3401", "secret_40ec1d3617e7f58811c2f1e4416dcf2f7")
@metavida
metavida / flickr-gem.patch
Created May 27, 2009 13:42
A simple patch for the flickr 1.0.2 gem based on http://www.flickr.com/services/api/request.rest.html
--- flickr-1.0.2/flickr.rb
+++ flickr-1.0.3/flickr.rb
@@ -56,7 +56,7 @@
# Replace this API key with your own (see http://www.flickr.com/services/api/misc.api_keys.html)
def initialize(api_key=nil, email=nil, password=nil)
@api_key = api_key
- @host = 'http://flickr.com'
+ @host = 'http://api.flickr.com'
@api = '/services/rest'
login(email, password) if email and password
@metavida
metavida / mongrel_upload_progress.patch
Created August 13, 2009 18:50
A simple patch of the mongrel_upload_progress gem that allows us to use regular expressions in the :path_info parameter.
--- lib/mongrel_upload_progress/init.rb
+++ lib/mongrel_upload_progress/init.rb
@@ -32,8 +32,8 @@
private
def upload_notify(action, params, *args)
- return unless @path_info.include?(params['PATH_INFO']) &&
- params[Mongrel::Const::REQUEST_METHOD] == 'POST' &&
+ return unless params[Mongrel::Const::REQUEST_METHOD] == 'POST' &&
+ @path_info.detect { |r| r.is_a?(Regexp) ? r =~ params['PATH_INFO'] : r == params['PATH_INFO'] } &&
@metavida
metavida / quine.rb
Created March 25, 2010 13:07
My very first ruby quine. Escaping in multi-line quines is a pain!
quine = <<QUINE
puts "quine = <<QUINE\\n" + quine.gsub('\\\\', '\\\\\\\\\\\\') + "QUINE\\n" + quine
QUINE
puts "quine = <<QUINE\n" + quine.gsub('\\', '\\\\\\') + "QUINE\n" + quine
@metavida
metavida / dispatcher.rb.patch
Created April 21, 2010 14:24
A patch for a Mongrel + Rails 1.2.6 bug, described in detail here: http://billkirtley.wordpress.com/2009/03/03/failsafe-handling-with-rails/
--- a/rails-1.2.6/lib/dispatcher.rb
+++ b/rails-1.2.6/lib/dispatcher.rb
@@ -41,7 +41,7 @@
controller.process(request, response).out(output)
end
rescue Exception => exception # errors from CGI dispatch
- failsafe_response(output, '500 Internal Server Error', exception) do
+ failsafe_response(output, '500 Internal Server Error', exception, response) do
controller ||= (ApplicationController rescue ActionController::Base)
controller.process_with_exception(request, response, exception).out(output)