Skip to content

Instantly share code, notes, and snippets.

View kineticac's full-sized avatar

Arthur Chang kineticac

View GitHub Profile
- 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
>> hello = "Hello"
=> "Hello"
>> world = "World"
=> "World"
>> hello_world = hello + '\r\n' + world
=> "Hello\\r\\nWorld"
>> hello_world = "#{hello}\r\n#{world}"
=> "Hello\r\nWorld"
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'
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'
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'
# user.rb
# this will always halt the filter chain!
def before_save
self.some_attribute = false
end
# user.rb
# this will not halt the chain
def before_save
self.some_attribute = false
true
end
# 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
# 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
# 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