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
def stuff | |
current_site = Site.find params[:id] | |
session[:site] = current_site | |
Site.update current_site, :default => 1 | |
back_sites = Site.find_by_sql("SELECT sites.* FROM sites WHERE id != #{current_site.id} AND user_id = #{@user.id}") | |
back_sites.each do |s| | |
Site.update s, :default => 0 | |
end | |
render :nothing => :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
# from http://nullstyle.com/2008/08/16/hacking-a-gist-api-with-mechanize/ | |
class Gistit < WWW::Mechanize | |
GIST_EMAIL = "foo" | |
GIST_PASSWORD = "bar" | |
GIST_URL = "http://gist.github.com/gists" | |
LOGIN_URL = "https://gist.github.com/session" | |
LOGIN_SUCCESS_URL = "http://gist.github.com/" |
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
#!/usr/local/bin/ruby -w | |
require ‘RMagick’ | |
include Magick | |
img = Magick::Image.read(’/home/anmol/jack.jpg’).first # path of Orignal image that has to be worked upon | |
puts img.inspect | |
def try(x,y,width,height) |
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 'RMagick' | |
clown = Magick::ImageList.new("clown.jpg") | |
face = clown.crop(50, 15, 150, 165) | |
white_bg = Magick::Image.new(clown.columns, clown.rows) | |
clown = white_bg.composite(face, 50, 15, | |
Magick::OverCompositeOp) | |
clown.write('crop.jpg') |
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 = URI.parse("http://www.blogger.com/feeds/#{article.blog_id}/posts/default") | |
http = Net::HTTP.new(url.host, url.port) | |
resp = http.start do |h| | |
req = Net::HTTP::Post.new(url.path, { "Authorization" => "GoogleLogin auth=#{auth}","Content-Type" => "application/atom+xml" }) | |
req.body = entry.to_xml | |
h.request(req) | |
end | |
if resp.is_a? Net::HTTPCreated | |
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
require 'mime/types' | |
api = Api.find(:first, :conditions => {:user_id => 2, :api_type_id => 11}) | |
#file = "#{RAILS_ROOT}/public/404.html" # WRONG | |
#file = "#{RAILS_ROOT}/public/assets/0000/0000/20090601cover_schlemiels.jpg" # WRONG | |
#file = "/Users/benjaminbonnet/Desktop/today.txt" # OK | |
#file = "/Users/benjaminbonnet/Desktop/Owasp-rails-security.pdf" # Content-Type application/pdf is not a valid input type. | |
#file = "/Users/benjaminbonnet/Desktop/proxylist_us_may_22_16_08_44_d.csv" | |
#file = "/Users/benjaminbonnet/Desktop/Hello_doc.doc" # OK |
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
if params[:frob] | |
endpoint = "" | |
frob = params[:frob].to_s | |
api = "xxxxx" | |
secret = "xxxxx" | |
method = "vimeo.auth.getToken" | |
sign = Digest::MD5.hexdigest(secret + 'api_key' + api + 'frob' + frob + 'method' + method) | |
endpoint += "?method=#{method}&api_key=#{api}&frob=#{frob}&api_sig=#{sign}" | |
@http = Net::HTTP.new('vimeo.com') | |
@http.start() do |http| |
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
@keyword = params[:search][:keyword] | |
keyword = CGI::escape(@keyword) | |
method = "vimeo.videos.search" | |
api_key = "xxxxx" | |
secret = "xxxxx" | |
query = "ruby" | |
sig_base = "#{secret}api_key#{api_key}fullResponse1method#{method}query#{@keyword}" ## LE MOT CLE DANS LA SIGNATURE NE DOIT PAS ETRE PASSÉ EN CGI. | |
api_sig = Digest::MD5.hexdigest(sig_base) | |
@feed_url = "http://vimeo.com/api/rest?api_key=#{api_key}&fullResponse=1&method=#{method}&query=#{keyword}&api_sig=#{api_sig}" |
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
video_id = @id | |
method = "vimeo.videos.getInfo" | |
api_key = "xxxxx" | |
secret = "xxxxx" | |
sig_base = "#{secret}api_key#{api_key}method#{method}video_id#{video_id}" | |
api_sig = Digest::MD5.hexdigest(sig_base) | |
video_url = "http://vimeo.com/api/rest?api_key=#{api_key}&method=#{method}&video_id=#{video_id}&api_sig=#{api_sig}" | |
@doc = Hpricot.parse(open(video_url)) | |
puts @doc | |
@doc.search('video').collect do |e| |
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
def lastfm_login | |
if params[:token] | |
endpoint = "" | |
token = params[:token].to_s | |
api = "xxxxx" | |
secret = "xxxxx" | |
method = "auth.getSession" | |
sign = Digest::MD5.hexdigest('api_key' + api + 'method' + method + 'token' + token + secret) | |
endpoint += "?method=#{method}&token=#{token}&api_key=#{api}&api_sig=#{sign}" | |
@http = Net::HTTP.new('ws.audioscrobbler.com') |
OlderNewer