Skip to content

Instantly share code, notes, and snippets.

View monfresh's full-sized avatar

Moncef Belyamani monfresh

View GitHub Profile
@monfresh
monfresh / gist:5663043
Created May 28, 2013 14:13
Defaults file for Rails Apps Composer for a basic Rails API app that uses MongoDB and Mongoid
recipes:
- setup
- readme
- gems
- testing
- controllers
- routes
- extras
prefs:
@monfresh
monfresh / gist:5663004
Created May 28, 2013 14:07
README.rdoc generated by Rails Apps Composer
== Welcome to Rails
Rails is a web-application framework that includes everything needed to create
database-backed web applications according to the Model-View-Control pattern.
This pattern splits the view (also called the presentation) into "dumb"
templates that are primarily responsible for inserting pre-built data in between
HTML tags. The model contains the "smart" domain objects (such as Account,
Product, Person, Post) that holds all the business logic and knows how to
persist themselves to a database. The controller handles the incoming requests
@monfresh
monfresh / extract_tld_from_url.rb
Created May 14, 2013 01:39
Ruby script to extract the TLD from a URL. This can be useful for validating a URL.
urls = ["http://brigade.codeforamerica.org/index.html", "brigade.codeforamerica.org", "http://codeforamerica.org", "codeforamerica.org/index.html", "brigade.codeforamerica.org/index.html"]
urls.each do |url|
# clean up the URLs so they all start off with the same format
if url.include?("http://")
url.gsub!("http://","")
end
# we're only interested in the part that comes before the first slash,
# so we split the string into the part before the slash, and the part after the slash
a = url.split("/")
@monfresh
monfresh / swipe_to_delete_and_check_cell.rb
Created August 9, 2012 21:20
Calabash iOS step that verifies that all cells have been deleted after swiping
def check_cell(prefix)
if @final_count[0] == 1
final_cell = query "TableViewCell index:0"
if final_cell.first["class"] == "UITableViewCell"
sleep(STEP_PAUSE)
else
screenshot_and_raise "#{prefix} of the cells were deleted!"
end
else
screenshot_and_raise "#{prefix} of the cells were deleted!"
@monfresh
monfresh / swipe_a_cell.rb
Created August 8, 2012 19:49
Custom step definition for Calabash iOS to swipe a cell in any orientation
Then /^I swipe on cell number (\d+) in "([^\"]*)"$/ do |index, orientation|
index = index.to_i
screenshot_and_raise "Index should be positive (was: #{index})" if (index<=0)
if orientation == "landscape"
swipe("up", {:query => "tableViewCell index:#{index-1}"})
elsif orientation == "portrait"
swipe("right", {:query => "tableViewCell index:#{index-1}"})
end
sleep(STEP_PAUSE)
end
@monfresh
monfresh / swipe_to_delete.rb
Created August 8, 2012 19:17
Custom Calabash iOS step definition to swipe to delete all cells in a Table View
Then /^I swipe to delete all cells in "([^\"]*)"$/ do |orientation|
total_rows = query("tableView index:0",numberOfRowsInSection:0) #this returns an array
end_of_range = total_rows[0] - 1
(0..end_of_range).each do
scroll_to_row "tableView index:0", 0
sleep(STEP_PAUSE)
macro %Q[I swipe on cell number 1 in "#{orientation}"] #requires this custom step definition: https://gist.github.com/3298026
sleep(STEP_PAUSE)
touch "TableViewCellDeleteConfirmationControl"
end