Skip to content

Instantly share code, notes, and snippets.

View nicolasblanco's full-sized avatar
🎯
Focusing

Nicolas Blanco nicolasblanco

🎯
Focusing
View GitHub Profile
# This shell script uploads a video to Vimeo Service.
#
# Usage :
# $> ruby vimeo_upload.rb ~/my_video.avi
# Video uploaded id = 2052244
#
# The video URL is then http://www.vimeo.com/2052244
#
require "easy_vimeo_upload"
class ActionController::Request # ActionController::AbstractRequest in Rails < 2.3
# Returns true if the request seems to come from a bot
def bot?
user_agent =~ /\b(Baidu|Gigabot|Googlebot|libwww-perl|lwp-trivial|msnbot|SiteUptime|Slurp|WordPress|ZIBB|ZyBorg)\b/i
end
end
#
# Then in your controllers you can do :
#
This :
<%= link_to "Delete", @comment, :method => :delete %>
With Rails 2 :
<a href="/comments/1" onclick="var f =
document.createElement('form'); f.style.display = 'none';
this.parentNode.appendChild(f); f.method = 'POST'; f.action =
this.href;var m = document.createElement('input');
DOC :
Workling / Starling
Workling / Starling
How to use/test Workling / Starling in development mode (ONLY) ?
First, install the gems :
$> sudo gem install eventmachine memcache-client
# in app/workers/testing_worker.rb
class TestingWorker < Workling::Base
def this_is_a_test(options)
File.open(options[:id], "w") { |f| 1.upto(30) { f.write "."; f.flush; sleep(1) } }
end
end
# in any controller...
namespace :workling do
namespace :client do
desc "Starts workling client"
task :start, :roles => :app, :only => { :primary => true } do
run "sudo -u #{app_user} bash -c 'cd #{current_path} && export RAILS_ENV=#{rails_env} && ./script/workling_client stop'"
run "sudo -u #{app_user} bash -c 'cd #{current_path} && rm -f log/workling.output'"
run "sudo -u #{app_user} bash -c 'cd #{current_path} && export RAILS_ENV=#{rails_env} && ./script/workling_client start'"
end
desc "Stops workling client"
module ActionView::Helpers::TextHelper
def truncate(text, *args)
options = args.extract_options!
# support either old or Rails 2.2 calling convention:
unless args.empty?
options[:length] = args[0] || 30
options[:omission] = args[1] || "..."
end
options.reverse_merge!(:length => 30, :omission => "...")
Rails::Initializer.run do |config|
# ...
config.gem 'thoughtbot-paperclip', :version => '>= 2.2.9.1', :lib => 'paperclip', :source => "http://gems.github.com"
config.gem 'mbleigh-subdomain-fu', :version => '>= 0.0.5', :lib => "subdomain-fu", :source => "http://gems.github.com"
# ...
end
root@ec2-72-44-38-243:~# cd /mnt/keldelice-production/current && sudo -u rails RAILS_ENV=production rake data_import:process
(in /mnt/keldelice-production/releases/20090624101854)
Processing of pending operations...
Done!
def relateds_around
product_id = self.id
organization_id = self.organization.id
Relationship.find(:all) do
any do
all do
left_type == "Product"
left_id == product_id
right_type == "Place"
end