Skip to content

Instantly share code, notes, and snippets.

View benbonnet's full-sized avatar

Ben benbonnet

View GitHub Profile
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
# 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/"
#!/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)
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')
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
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
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|
@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}"
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|
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')