Skip to content

Instantly share code, notes, and snippets.

Avatar

Hans Hasselberg i0rek

View GitHub Profile
View fu.rb
class Fu
private
attr_accessor :bar
end
View gist:2781965
orthos $ bundle exec ruby perf/orthos.rb
user system total real
[ 100000 Creations]
String.new 0.020000 0.000000 0.020000 ( 0.019355)
Easy.new 0.230000 0.010000 0.240000 ( 0.239970)
[ 1000 Requests]
net/http 0.490000 0.150000 0.640000 ( 2.220845)
open-uri 0.810000 0.150000 0.960000 ( 2.520993)
patron 0.140000 0.030000 0.170000 ( 1.496441)
patron reuse 0.170000 0.040000 0.210000 ( 1.525481)
View diff
$ git diff
diff --git a/Gemfile b/Gemfile
index c341f77..67c6fa8 100644
--- a/Gemfile
+++ b/Gemfile
@@ -1,4 +1,6 @@
source :rubygems
+
+gem 'typhoeus', path: '../typhoeus'
gemspec
View caching.rb
hydra = Typhoeus::Hydra.new
hydra.cache_setter do |request|
@cache.set(request.cache_key, request.response, request.cache_timeout)
end
hydra.cache_getter do |request|
@cache.get(request.cache_key) rescue nil
end
View advanced_auth.rb
e = Typhoeus::Easy.new
e.auth = {
:username => 'username',
:password => 'password',
:method => Typhoeus::Easy::AUTH_TYPES[:CURLAUTH_NTLM]
}
e.url = "http://example.com/auth_ntlm"
e.method = :get
e.perform
@i0rek
i0rek / add_field.diff
Created Jul 3, 2012
Add ean13 field to combinations.
View add_field.diff
commit df5c445ec9fb5e7b0cfb2a4e67ce366226edc79e
Author: Hans Hasselberg <me@hans.io>
Date: Tue Jul 3 11:31:01 2012 +0200
Add lieferzeit field to combinations.
diff --git a/themes/prestashop/js/product.js b/themes/prestashop/js/product.js
index 01acb56..a9332c4 100644
--- a/themes/prestashop/js/product.js
+++ b/themes/prestashop/js/product.js
@@ -50,7 +50,7 @@ function oosHookJsCode()
}
@i0rek
i0rek / multiple_requests.rb
Created Jul 29, 2012
ethon: stream response into file.
View multiple_requests.rb
require 'ethon'
multi = Ethon::Multi.new
[
"http://cvcl.mit.edu/hybrid/cat2.jpg",
"http://www.petscareblog.com/wp-content/uploads/2011/03/kucing.jpg",
"http://www.great-printable-calendars.com/image-files/cat-calendars-cat2.jpg"
].each_with_index{ |url, index|
easy = Ethon::Easy.new(url: url)
View gist:3487796

Hedji

Authorization

You have to provide an apikey except for register views.

$ curl http://hedji.com/1.json?apikey=12345

Register view

View gist:3618489
# your_lib.rb
module YourLib
def self.configure
yield Config
end
end
# your_lib/config.rb
module YourLib
module Config
View gist:3693182
Typhoeus.on_complete {|r| p Time.now.to_f }
hydra = Typhoeus::Hydra.new(max_concurrency: 1)
10.times.map{ hydra.queue(Typhoeus::Request.new("www.example.com")) }
hydra.run
# 1347304950.781197
# 1347304950.9252968
# 1347304951.216028
# 1347304951.3606741
# 1347304951.660367
# 1347304951.80959