Skip to content

Instantly share code, notes, and snippets.

View petrblaho's full-sized avatar

Petr Blaho petrblaho

  • Brno, Czech Republic
View GitHub Profile
@petrblaho
petrblaho / RUBYISMS
Created December 14, 2009 07:49
Rubyisms
# original found at http://pastie.textmate.org/143799
#RUBYISMS
a = b.foo
if a.empty?
a = b.bar
else
a.reverse!
end
class Comment < ActiveRecord::Base
belongs_to :post
end
@petrblaho
petrblaho / rake_autocomplete_for_bash.rb
Created January 7, 2010 07:56
bash autocomplete for rake with cache
#!/usr/bin/env ruby
# Complete rake tasks script for bash
# Save it somewhere and then add
# complete -C path/to/script -o default rake
# to your ~/.bashrc
# Xavier Shay (http://rhnh.net), combining work from
# Francis Hwang ( http://fhwang.net/ ) - http://fhwang.net/rb/rake-complete.rb
# Nicholas Seckar <[email protected]> - http://www.webtypes.com/2006/03/31/rake-completion-script-that-handles-namespaces
# Saimon Moore <[email protected]>
@petrblaho
petrblaho / application.html.erb
Created January 8, 2010 08:37
jQuery in Rails application
<%= javascript_include_tag 'jquery', 'jquery-ui' %>
<% if protect_against_forgery? %>
<script type='text/javascript'>
//<![CDATA[
window._auth_token_name = "#{request_forgery_protection_token}";
window._auth_token = "#{form_authenticity_token}";
//]]>
</script>
<% end %>
@petrblaho
petrblaho / datasize.rake
Created February 10, 2010 06:57
database size rake task
# Run rake db:size to get a print of your database size in bytes.
# Run rake db:tables:size to get the sizes for individual tables
# Works for MySQL and PostgreSQL. Not tested elsewhere.
namespace :db do
desc 'Print data size for entire database'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase
@petrblaho
petrblaho / Gemfile
Created February 26, 2010 20:34 — forked from indirect/Gemfile
# include at least one source and the rails gem
source :gemcutter
gem "rails", "~> 2.3.5", :require => nil
gem "sqlite3-ruby", :require => "sqlite3"
# Devise 1.0.2 is not a valid gem plugin for Rails, so use git until 1.0.3
# gem "devise", :git => "git://github.com/plataformatec/devise.git", :ref => "v1.0"
group :development do
# bundler requires these gems in development
require 'rubygems'
# http://github.com/archiloque/rest-client
require 'rest_client'
# STARTED
# set game with hash_code 'game_hash123' as started
RestClient.post "http://localhost:3000/games/game_hash123/started", { '_method' => 'put', 'user_credentials' => 'xH31MpM8xSff3em8LwGJ' }, :content_type => :json, :accept => :json
require 'cgi'
def html2text html
text = html.
gsub(/(&nbsp;|\n|\s)+/im, ' ').squeeze(' ').strip.
gsub(/<([^\s]+)[^>]*(src|href)=\s*(.?)([^>\s]*)\3[^>]*>\4<\/\1>/i,
'\4')
links = []
linkregex = /<[^>]*(src|href)=\s*(.?)([^>\s]*)\2[^>]*>\s*/i
@petrblaho
petrblaho / gist:1016755
Created June 9, 2011 13:45 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
Failures:
1) ThemeAsset attaching a file file is a picture should process picture
Failure/Error: @asset.source = FixturedAsset.open('5k.png')
NameError:
uninitialized constant Magick
# ./lib/locomotive/carrierwave/asset.rb:56:in `set_width_and_height'
# ./spec/models/theme_asset_spec.rb:17
2) ThemeAsset attaching a file file is a picture should get width and height from the image