Skip to content

Instantly share code, notes, and snippets.

@siannopollo
siannopollo / aws_s3_upload_fix.rb
Created February 4, 2010 22:49
Fixes a timeout problem with the aws-s3 library
AWS::S3::Base.class_eval do
class << self
def request_with_rewind(verb, path, options = {}, body = nil, attempts = 0, &block)
body.rewind if body.respond_to?(:rewind)
request_without_rewind verb, path, options, body, attempts, &block
end
alias_method_chain :request, :rewind
end
end
class ReadonlyFormBuilder < ActionView::Helpers::FormBuilder
def calendar_date_select(method, options = {})
text_field method, options
end
def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
merge_class_options 'readonly furtive', options
options.update :readonly => true
super
end
@siannopollo
siannopollo / gist:320985
Created March 3, 2010 20:39
Apply styles to pages opened by Webrat (0.6.0)
Webrat::SaveAndOpenPage.module_eval do
def rewrite_css_and_image_references(response_html)
response_html.gsub(/("|')\/(stylesheets|images|javascripts)/) {"#{$1}../public/#{$2}"}
end
def saved_page_dir
File.expand_path('./tmp')
end
end
require 'rack/utils'
class UnknownHttpMethodMiddleware
def initialize(app)
@app = app
end
def call(env)
return [401, {}, ''] if %w(connect).include?(env["REQUEST_METHOD"].downcase)
@siannopollo
siannopollo / jasmine.rake
Created November 4, 2010 14:51
Better Jasmine rake task. Starts the server and opens it in the default browser.
begin
require 'jasmine'
load 'jasmine/tasks/jasmine.rake'
namespace :jasmine do
task :server_without_open => :server
desc 'Run specs via server'
task :server_with_open do
Rake::Task['jasmine:server_without_open'].invoke
@siannopollo
siannopollo / SwipeView.h
Created January 23, 2011 01:54
A UIVIew class to detect swipes, and forward the message on to a delegate which can react to the swipe
#import <UIKit/UIKit.h>
@protocol SwipeViewDelegate;
@interface SwipeView : UIView {
id <SwipeViewDelegate> swipeDelegate;
int touchBeganX, touchBeganY;
int touchMovedX, touchMovedY;
}
@siannopollo
siannopollo / jasmine_config.rb
Created February 2, 2011 02:18
Out-of-the-box Jasmine doesn't work with remote files (like loading a framework from google). This allows for it.
# This goes in spec/javascripts/support/jasmine_config.rb
Jasmine::Config.class_eval do
def src_files_with_remote_files
remote_files = simple_config['src_files'].select {|f| f =~ /^http:\/\//}
remote_files + src_files_without_remote_files
end
alias_method :src_files_without_remote_files, :src_files
alias_method :src_files, :src_files_with_remote_files
def js_files_with_remote_files(*args)
module MyCustomFilters
def full_urls(input)
input.gsub /(<\s*(a|img|video|audio)\s+[^>]*(href|src)\s*=\s*[\"'])(?!http:\/\/|https:\/\/|sftp:\/\/)([^\"'>]+)[\"'>]/ do
"#{$1}http://example.com#{$2}"
end
end
end
Liquid::Template.register_filter MyCustomFilters
@siannopollo
siannopollo / Test.h
Created May 26, 2011 00:21
Bootstrap a CoreData test class
#import <SenTestingKit/SenTestingKit.h>
#import <CoreData/CoreData.h>
@interface Test : SenTestCase {
NSManagedObjectModel *model;
NSPersistentStoreCoordinator *coordinator;
NSManagedObjectContext *context;
}
- (NSString *)applicationSupportDirectory;
@siannopollo
siannopollo / AVItoMOV.rb
Created July 13, 2011 03:38
Encode my AVI files to MOV using ffmpegX, ruby and AppleScript
Dir[ARGV.join(" ") + '/*.AVI'].each do |movie|
command = %{
tell application "ffmpegX"
activate
set contents of the fifth text field of front window to "#{movie}"
set contents of the second text field of front window to "#{movie.sub('AVI.ff.mov', 'mov').sub('AVI', 'mov')}"
tell application "System Events"
tell process "ffmpegX" to keystroke "\r"
end tell
end tell