This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # more simple version of https://github.com/itkin/respond_to_parent.git without dirty hacks that works good in rails3 | |
| # usage: | |
| # in controller#create append render :layout => false | |
| # in create.html.erb | |
| # <%= eval_javascript_in_parent(<<EOF | |
| # $('#entries-list').prepend('#{escape_javascript(render @entry)}'); | |
| # EOF | |
| # ) %> | |
| # | |
| # most source from https://github.com/itkin/respond_to_parent/blob/master/lib/responds_to_parent.rb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'irb/completion' | |
| require 'pp' | |
| require 'rubygems' | |
| # Automatic Indentation | |
| IRB.conf[:AUTO_INDENT] = true | |
| # Remove the annoying irb(main):001:0 and replace with >> | |
| IRB.conf[:PROMPT_MODE] = :SIMPLE | |
| # Add all gems in the global gemset to the $LOAD_PATH so they can be used in rails3 console with bundler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Add all gems in the global gemset to the $LOAD_PATH so they can be used in rails3 console with bundler | |
| if defined?(::Bundler) | |
| $LOAD_PATH.concat Dir.glob("#{ENV['rvm_path']}/gems/#{ENV['rvm_ruby_string']}@global/gems/*/lib") | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| silence_warnings do | |
| ActionDispatch::Request::LOCALHOST = (ActionDispatch::Request::LOCALHOST + ['192.168.0.1']).freeze | |
| end | |
| ActionController::Base.module_eval do | |
| def show_detailed_exceptions? | |
| request.local? | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'bundler/capistrano' | |
| set :application, "APPNAME" | |
| set :domain, "mydomain.com" | |
| set :user, "deployer" | |
| set :password, "" | |
| set :runner, user | |
| default_run_options[:pty] = true # Must be set for the password prompt from git to work |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| javascript:(function(){ var css = '.entry-row.expanded {font-size: 130% !important;} .entry {padding-left: 30px;}';var sn = document.createElement("style"); sn.setAttribute("type", "text/css");sn.setAttribute("media", "screen"); sn.appendChild(document.createTextNode(css));document.getElementsByTagName("head")[0].appendChild(sn);})() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module MultiInsert | |
| # This method almost like sequels dataset.import() | |
| # | |
| # Inserts multiple records into the associated table. | |
| # | |
| # This method is called with a columns array and an array of value arrays: | |
| # | |
| # Model.mass_insert(['x', 'y'], [[1, 2], [3, 4]]) | |
| # | |
| def multi_insert(columns, values) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module InsertWithUpdate | |
| # INSERT INTO .. ON DUPLICATE KEY UPDATE .. | |
| def insert_with_update(attributes, update_sql) | |
| columns = [] | |
| values = [] | |
| attributes.each_pair do |attr, value| | |
| columns << connection.quote_column_name(attr) | |
| values << connection.quote(value) | |
| end | |
| connection.insert "INSERT INTO #{quoted_table_name} (#{columns.join(',')}) VALUES (#{values.join(',')}) ON DUPLICATE KEY UPDATE #{update_sql}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module StripAttributes | |
| def strip_attributes!(*attrs) | |
| attrs.map(&:to_s) | |
| before_validation do |r| | |
| attrs.each do |v| | |
| r[v].strip! if r[v] | |
| end | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class BitLy | |
| include HTTParty | |
| base_uri "http://api.bit.ly" | |
| default_params 'login' => 'bitlyapidemo', 'apiKey' => 'R_0da49e0a9118ff35f52f629d2d71bf07' | |
| format :json | |
| def self.shorten(url) | |
| r = get('/v3/shorten', :query => {'longUrl' => url} ) | |
| r['data']['url'] rescue nil | |
| end |