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
| # switch default editor for pry to sublime text | |
| Pry.config.editor = "sublime" | |
| # format prompt to be <Rails version>@<ruby version>(<object>)> | |
| Pry.config.prompt = proc do |obj, level, _| | |
| prompt = "\e[1;30m" | |
| prompt << "#{Rails.version} @ " if defined?(Rails) | |
| prompt << "#{RUBY_VERSION}" | |
| "#{prompt} (#{obj})>\e[0m" | |
| 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
| #!/usr/bin/env ruby | |
| # From my blog post at http://www.postal-code.com/binarycode/2009/06/06/better-range-intersection-in-ruby/ | |
| class Range | |
| def intersection(other) | |
| raise ArgumentError, 'value must be a Range' unless other.kind_of?(Range) | |
| my_min, my_max = first, exclude_end? ? max : last | |
| other_min, other_max = other.first, other.exclude_end? ? other.max : other.last |
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 the new tsvector column | |
| ALTER TABLE articles ADD COLUMN tsv tsvector; | |
| -- Create a function that will generate a tsvector from text data found in both the | |
| -- title and body columns, but give a higher relevancy rating 'A' to the title data | |
| CREATE FUNCTION articles_generate_tsvector() RETURNS trigger AS $$ | |
| begin | |
| new.tsv := | |
| setweight(to_tsvector('pg_catalog.english', coalesce(new.title,'')), 'A') || | |
| setweight(to_tsvector('pg_catalog.english', coalesce(new.body,'')), 'B'); |
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
| license: gpl-3.0 |
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
| /** | |
| * jQuery.support.cssProperty | |
| * To verify that a CSS property is supported | |
| * (or any of its browser-specific implementations) | |
| * | |
| * @param p css property name | |
| * @param rp optional, if set to true, the css property name will be returned | |
| * instead of a boolean support indicator | |
| * @return {mixed} | |
| * |
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
| =Navigating= | |
| visit('/projects') | |
| visit(post_comments_path(post)) | |
| =Clicking links and buttons= | |
| click_link('id-of-link') | |
| click_link('Link Text') | |
| click_button('Save') | |
| click('Link Text') # Click either a link or a button | |
| click('Button Value') |
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
| # Ways to execute a shell script in Ruby | |
| # Example Script - Joseph Pecoraro | |
| cmd = "echo 'hi'" # Sample string that can be used | |
| # 1. Kernel#` - commonly called backticks - `cmd` | |
| # This is like many other languages, including bash, PHP, and Perl | |
| # Synchronous (blocking) | |
| # Returns the output of the shell command | |
| # Docs: http://ruby-doc.org/core/classes/Kernel.html#M001111 |
NewerOlder