Skip to content

Instantly share code, notes, and snippets.

@bbozo
bbozo / example_test.rb
Last active January 18, 2020 15:24
API calls mocking & validation
api_exchange << {
request_validator: method(:request_validator).curry[an_option_for_request_validator: true],
response: response_for_valid
}
rv = initiate_authorization
assert_trx_result rv, three_ds_1: TestCaseFaker.test_case
# .....
def request_validator options, request
@bbozo
bbozo / SE question.txt
Last active August 25, 2017 17:53
Best practices to handle amount & currency now that infinitely divisible non-ISO currencies are becoming a thing?
Classic wisdom for handling amount & currency would be to use a `char(3)` or `int` for currency and an `int` for amount, this is the norm in the financial sector since the 80s. You need to be aware which currency has which decimalization, and all good.
However, now we have an invasion of new de-facto currencies that don't necessarily have their ISO codes, so numeric ISO codes go out of the window (no more `int` for currencies) - we have NEO, litecoin, faircoin, ...
Next issue is the amount, at least with BTC we have "The Satoshi" which is [supposedly the smallest unit of BTC but not really](https://bitcoin.stackexchange.com/questions/122/will-we-ever-need-smaller-amounts-of-bitcoin-than-a-satoshi). But this is just 1 cryptocurrency out there.
At least in the Ruby community [the established "money" library](https://github.com/RubyMoney/money) uses an integer - "the cents" - as the minor unit of currency and now they set Satoshis as the cents for BTC.
However,
@bbozo
bbozo / functional.rb
Last active June 24, 2017 12:43
Functional Ruby naive implementation
require 'ramda'
R = Ramda
module Functional
extend ActiveSupport::Concern
def method_call
method(:call)
end
@bbozo
bbozo / setnx_instead_of_zadd.rb
Last active April 12, 2017 17:58
sidekiq-scheduler race condition proof-of-concept
# gem install concurrent-ruby redis pry connection_pool
require "redis"
require "pry"
require "connection_pool"
require "concurrent"
require "securerandom"
$cp = ConnectionPool.new { Redis.new }
REGISTERED_JOBS_THRESHOLD_IN_SECONDS = 60 * 60
@bbozo
bbozo / gist:46be23d801cd76b3ec09ad5bfbfbc6a4
Last active January 19, 2017 11:36
Docker support discussion about possibility of PCI DSS virtualization via Docker
[12:11] <bbozo> Hey guys :)
[12:11] <bbozo> I know you're listening on SO on the Docker tag
[12:11] <Ravensoul> So my docker stats is weird?
[12:12] <bbozo> but not sure if you're on the Security stack exchange
[12:12] <bbozo> Can somebody take a look? https://security.stackexchange.com/questions/148784/is-docker-a-pci-dss-compliant-form-of-virtualization
[12:12] <bbozo> regarding posibilites of use of Docker for security related isolation
[12:13] <Ravensoul> bbozo: right. What's pci-dss compliancy, I can answer that if you tell me
[12:14] <Ravensoul> antonios: have you tried removing containers?
[12:16] <Ravensoul> bbozo: as far as I can tell there are no requirements for "virtualization". What are you trying to do
[12:17] <bbozo> @Ravensoul, PCI DSS is a credit card security standard https://pcicompliance.stanford.edu/sites/default/files/pci_dss_v3-2.pdf - the interesting point is requirement 2.2.1
@bbozo
bbozo / test_helper.rb
Last active January 9, 2017 15:46
minitest-parallel_fork setup for ActiveRecord
Minitest.before_parallel_fork do
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
end
Minitest.after_parallel_fork do |i|
if defined?(ActiveRecord::Base)
db_config = Rails.application.config.database_configuration[Rails.env].clone
db_config['database'] += (i+1).to_s
ActiveRecord::Base.establish_connection(db_config)
From: /home/bbozo/dev/faraday/lib/faraday/adapter/http_gem.rb @ line 5 :
1: module Faraday
2: class Adapter
3: class HttpGem < Faraday::Adapter
4: require 'pry'
=> 5: binding.pry
6: dependency 'http'
7:
8: HTTP_EXCEPTIONS = [
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:56:in `block in autorun'
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:129:in `run'
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:152:in `__run'
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:152:in `map'
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:152:in `block in __run'
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:291:in `run'
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:318:in `with_info_handler'
from /home/travis/build/lostisland/faraday/vendor/bundle/ruby/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:331:in `on_signal'
from /home/travis/build/lo
@bbozo
bbozo / install.sh
Created January 26, 2016 09:24
Heroku deployment script
#!/bin/bash
set -e
# set -x # -> for debug
#rm -rf /tmp/heroku
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1) /'
@bbozo
bbozo / fakes3
Created August 19, 2015 11:15
fakes3 init.d script
#!/bin/sh
### BEGIN INIT INFO
# Provides: fakes3
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.