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
(ns hackerfews.core | |
2 (:require [net.cgrand.enlive-html :as html])) | |
3 | |
4 (def url (java.net.URI. "http://news.ycombinator.com/")) | |
5 | |
6 (defn titles | |
7 [docx] (flatten (map :content (html/select docx [:td.title :a])))) | |
8 | |
9 (defn numbers-in-nodes | |
10 [docx selector] (let [x (flatten (map :content (html/select docx selector)))] |
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 ClearEyes | |
module ViewHelpers | |
def self.included(base) | |
base.send(:attr_accessor, :image, :options) | |
end | |
def r_image( pixel_ratio ) | |
insert_on = -File.extname(self.image).size-1 | |
image_tag(self.image.insert(insert_on, "@#{pixel_ratio}x"), self.options) | |
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 AttachedFile < ActiveRecord::Base | |
belongs_to :parent, :polymorphic => true | |
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 ThingsController < ApplicationController | |
respond_to :html, :json | |
# decent_exposure won't currently intuit a collection (plural resource) for you. The SLTD error is | |
# caused by a circular reference between an undeclared collection (which the singular resource attempts | |
# to scope from) and the singular resource. To fix this problem, just define the collection: | |
expose(:things) { Thing.all } | |
# or alternatively, something like: | |
# expose(:things) { current_user.things } | |
expose(:thing) |
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
def wait_conditionally_until | |
if page.driver.wait? | |
page.wait_until do | |
begin | |
yield | |
rescue Selenium::WebDriver::Error::WebDriverError => e | |
# do nothing - continue to wait for timeout | |
end | |
end | |
else |