This file contains 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
- begin | |
- bitly = Bitly.new(BITLY_USERNAME, BITLY_API_KEY) | |
- url = bitly.shorten(fb_feud_link) | |
- short_url = url.short_url | |
- rescue | |
- short_url = fb_feud_link | |
- end | |
+ short_url = fb_feud_link | |
This file contains 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
>> hello = "Hello" | |
=> "Hello" | |
>> world = "World" | |
=> "World" | |
>> hello_world = hello + '\r\n' + world | |
=> "Hello\\r\\nWorld" | |
>> hello_world = "#{hello}\r\n#{world}" | |
=> "Hello\r\nWorld" |
This file contains 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
url = SUPERFEEDR_URL | |
private_resource = RestClient::Resource.new url, SUPERFEEDR_LOGIN, SUPERFEEDR_PASSWORD | |
private_resource.post "hub.topic" => @feed.url, "hub.callback" => SUPERFEEDR_CALLBACK, "hub.verify" => 'sync', "hub.mode" => 'subscribe' |
This file contains 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
url = SUPERFEEDR_URL | |
private_resource = RestClient::Resource.new url, SUPERFEEDR_LOGIN, SUPERFEEDR_PASSWORD | |
private_resource.post "hub.topic" => @feed.url, "hub.callback" => SUPERFEEDR_CALLBACK, "hub.verify" => 'sync', "hub.mode" => 'unsubscribe' |
This file contains 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 'net/http' | |
# example with a Flickr image | |
require 'flickraw' | |
FlickRaw.api_key=FLICKR_API_KEY | |
FlickRaw.shared_secret=FLICKR_SECRET | |
# grab the most interesting unrestricted image from Flickr | |
photos = flickr.photos.search :per_page => 1, :page => 1, :content_type => 1, :license => 7, :sort => 'interestingness-desc' |
This file contains 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
# user.rb | |
# this will not halt the chain | |
def before_save | |
self.some_attribute = false | |
true | |
end |
This file contains 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
# user.rb | |
# this will always halt the filter chain! | |
def before_save | |
self.some_attribute = false | |
end |
This file contains 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
# Development Caching | |
# to turn on: uncomment below, and set the values to true | |
# comment out the false variables below. | |
# | |
# require 'memcache' | |
# CACHE = Memcached::Rails.new '127.0.0.1:11211' | |
# config.cache_store = :mem_cache_store, Memcached::Rails.new | |
# CACHE_DEVELOPMENT = true | |
# config.action_controller.perform_caching = true | |
# config.cache_classes = true |
This file contains 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
# development.rb | |
# require 'memcache' | |
# CACHE = Memcached::Rails.new '127.0.0.1:11211' | |
# config.cache_store = :mem_cache_store, Memcached::Rails.new | |
# CACHE_DEVELOPMENT = true | |
# config.action_controller.perform_caching = true | |
# config.cache_classes = true | |
CACHE_DEVELOPMENT = false |
This file contains 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
# application_controller.rb | |
def cache_fetch(key, time_expire = 0) | |
if ENV["RAILS_ENV"] == 'development' && !CACHE_DEVELOPMENT | |
yield | |
else | |
# CACHE.fetch(key, time_expire){yield} #this is the old way | |
unless output = CACHE.get(key) | |
output = yield | |
CACHE.set(key, output, time_expire) | |
end |
OlderNewer