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
Then /^I should see the ([^"]*) "([^"]*)"$/ do |element_type, file_name| | |
case element_type | |
when /link/ | |
page.should have_xpath("//link[contains(@href, '#{file_name}')]") | |
when /img/ | |
page.should have_xpath("//img[contains(@src, '#{file_name}')]") | |
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
# model | |
class Attachment < ActiveRecord::Base | |
mount_uploader :document, DocumentUploader | |
# these methods fix the filename persistance issue | |
def read_uploader(column) | |
self[column] | |
end | |
def write_uploader(column, identifier) |
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
#!/bin/bash | |
for user in $(cut -f1 -d: /etc/passwd); do echo $user; crontab -u $user -l; done |
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
#!/bin/bash | |
# Include this file in your .zshrc or .bashrc, or just add this function directly to it | |
# | |
# Usage: | |
# > proxify | |
# # prompts you for your ssh password | |
# # OSX may prompt you to confirm the changes to your network settings | |
# | |
# Once complete, you will have an SSH tunnel established to your remote host |
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
# USAGE: | |
# given: | |
# <div class="price" data-amount="1">$1.00</div> | |
# <div class="price" data-amount="2">$2.00</div> | |
# > $('.price').get().sum (price) -> $(price).data('amount') | |
# > 3 | |
Array::sum = (fn = (x) -> x) -> | |
@reduce ((a, b) -> a + fn b), 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
# Array#flat_map | |
# works exactly like: Array.map(&b).flatten!(1) | |
[[1,2],[3,4]].flat_map {|i| i } #=> [1, 2, 3, 4] |
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
# credit: http://stackoverflow.com/questions/4514988/rails-is-there-away-to-get-the-date-object-that-is-the-closest-monday-to-today | |
# docs: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/date/rdoc/Date.html#method-c-commercial | |
# Find the next Monday | |
Date.commercial(Date.today.year, 1+Date.today.cweek, 1) | |
# Find the nearest Monday | |
Date.commercial(Date.today.year, Date.today.cwday.modulo(4)+Date.today.cweek, 1) | |
# Date of writing was: 2013-12-03 |
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
# encoding: utf-8 | |
class String | |
def titleize(options = {}) | |
exclusions = options[:exclude] | |
return ActiveSupport::Inflector.titleize(self) unless exclusions.present? | |
self.underscore.humanize.gsub(/\b(?<!['’`])(?!#{exclusions.join('|')})[a-z]/) { $&.capitalize } | |
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 PageObject | |
include Capybara::DSL | |
include RSpec::Matchers | |
include Rails.application.routes.url_helpers | |
attr_accessor :path, :object | |
def initialize(object = nil) | |
raise "#{self.class} must be initialized with a model instance" unless !is_singular_object_page? or object | |
@path = "#{path_name}_path" |
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 'open-uri' | |
require 'json' | |
language = 'en' | |
unless article = ARGV.shift | |
print 'What do you need to know? : ' | |
article = URI::encode gets.chomp | |
end |