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
import pretend | |
from zeep import Client | |
from zeep.transports import Transport | |
client = Client('http://api.affiliatewindow.com/v6/AffiliateService?wsdl') | |
response = pretend.stub( | |
status_code=200, | |
headers=[], | |
content=""" | |
<?xml version="1.0" encoding="UTF-8"?> | |
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://api.affiliatewindow.com/"><SOAP-ENV:Body><ns1:getTransactionListResponse><ns1:getTransactionListReturn><ns1:Transaction><ns1:iId>00000000</ns1:iId><ns1:sStatus>confirmed</ns1:sStatus><ns1:sType>normal</ns1:sType><ns1:sIp>x.x.x.x</ns1:sIp><ns1:bPaid>false</ns1:bPaid><ns1:iPaymentId>0</ns1:iPaymentId><ns1:iMerchantId>1111</ns1:iMerchantId><ns1:mSaleAmount><ns1:dAmount>0.00</ns1:dAmount><ns1:sCurrency>GBP</ns1:sCurrency></ns1:mSaleAmount><ns1:mCommissionAmount><ns1:dAmount>0.00</ns1:dAmount><ns1:sCurrency>GBP</ns1:sCurrency></ns1:mCommissionAmount><ns1:dClickDate>2017-01-01T00:00:00+00:00</ns1:dClickDate><ns1:dTransactionDate>2017-01-01T00:00:00+00:00</ns1 |
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 linearRampToZeroOverTime( value, seconds ) | |
value = value.to_f | |
update_ticks = 60 | |
step_delta = value / seconds.to_f | |
tick_delta = step_delta / update_ticks.to_f | |
( 1..seconds ).each do | sec | | |
( 1..update_ticks ).each do | tick | | |
last_value = value | |
value = value - tick_delta | |
percentage_of_change = value / last_value |
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
# this scrubs emoji sequences from a string - i think it covers all of them | |
def strip_emoji ( str ) | |
str = str.force_encoding('utf-8').encode | |
clean_text = "" | |
# emoticons 1F601 - 1F64F | |
regex = /[\u{1f600}-\u{1f64f}]/ | |
clean_text = str.gsub regex, '' |
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 'amqp' | |
require 'em-http-request' | |
EM.run do | |
connection = AMQP.connect(:host => '127.0.0.1') | |
channel = AMQP::Channel.new(connection) | |
queue = channel.queue("em.load.test", :auto_delete => true) | |
exchange = channel.default_exchange | |
def handle_message(header, payload, *args) |
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 'em-synchrony/em-mongo' | |
require 'mongoid' | |
mongoid_conn = Mongo::Connection.new 'localhost', 27017, :pool_size => 10 | |
Mongoid.configure do |config| | |
begin | |
config.master = mongoid_conn.db('dbname') | |
rescue Exception=>err | |
abort "An error occurred while creating the mongoid connection pool: #{err}" | |
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
config['mongo'] = EM::Synchrony::ConnectionPool.new(size:10) do | |
begin | |
conn = EM::Mongo::Connection.new('localhost', 27017, 1, {:reconnect_in => 1}) | |
conn.db('mongo_db_name') | |
rescue Exception=>err | |
abort "An error occurred while creating the mongodb connection pool: #{err}" | |
end | |
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
class RackRoutes < Goliath::API | |
get '/item/:value/description' do | |
if params[:value].match /^[a-zA-Z][\w\-]+$/ | |
...do awesome stuff with a parameter that is alpha-based... | |
elsif params[:value].match /\d+/ | |
...do awesome stuff with a parameter that is numeric-based... | |
else | |
run Proc.new { |env| [404, {}, "" ] } | |
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
0. gem install goliath (should be v0.9.4 as of writing this) | |
1. gem install mongoid (should be v2.3.3 as of writing this) | |
2. create and save test.rb file (see below) | |
3. % ruby test.rb -sv | |
4. % ab -n500 -c10 http://localhost:9000/status | |
5. note the req/s results (somewhere around 80-90 req/s on my machine) | |
6. edit the test.rb file, remove the 'require mongoid' line | |
7. repeat steps 3 and 4. | |
8. note the req/s results (somewhere aaround 550 req/s on my machine) |