Skip to content

Instantly share code, notes, and snippets.

nhm tanveer hossain khan (hasan) we4tech

Block or report user

Report or block we4tech

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
gem 'rack'
gem 'dry-container'
gem 'minitest'
gem 'mocha'
View create_admin_rabbitmq_user.sh
#!/bin/sh
API_USER="<USER>:<PASSWORD>"
API_URL="https://<SOME_SERVICE>.cloudamqp.com/api"
VHOST="<VHOST>"
__colored_echo()
{
printf "\033[$1m$2\033[0m\n"
}
@we4tech
we4tech / comparison-2.4.1.md
Last active Sep 14, 2018
Benchmark ruby eval VS RubyVM::InstructionSequence
View comparison-2.4.1.md

Ruby 2.4.1

eval-vs-iseq

Eval (global) | 0.120000 | 0.120000 | 0.140000 | 0.140000 | 0.150000 | 0.150000 | 0.150000 | 0.150000 | 0.140000 | 0.140000 | 0.190000 | 0.150000 | 0.150000 | 0.150000 | 0.120000 | 0.150000 | 0.130000 | 0.130000 | 0.140000 | 0.150000 | 0.160000 | 0.150000 | 0.150000 | 0.150000 | 0.160000 | 0.130000 | 0.150000 | 0.140000 | 0.130000 | 0.160000 | 0.140000 | 0.140000 | 0.150000 | 0.140000 | 0.160000 | 0.150000 | 0.140000 | 0.140000 | 0.150000 | 0.130000 | 0.140000 | 0.140000 | 0.120000 | 0.140000 | 0.140000 | 0.130000 | 0.160000 | 0.130000 | 0.140000 | 0.140000 | 0.130000 | 0.130000 | 0.140000 | 0.130000 | 0.140000 | 0.130000 | 0.130000 | 0.130000 | 0.140000 | 0.130000 | 0.140000 | 0.140000 | 0.130000 | 0.140000 | 0.140000 | 0.130000 | 0.160000 | 0.120000 | 0.130000 | 0.130000 | 0.140000 | 0.130000 | 0.140000 | 0.130000 | 0.130000 | 0.130000 | 0.130000 | 0.13

@we4tech
we4tech / dtrace_for_ruby_c_call.d
Created Aug 16, 2018
Ruby Dtrace probe script that fires whenever a cmethod is about to call
View dtrace_for_ruby_c_call.d
ruby*:::cmethod-entry
{
printf("%s(%d) called from %s#%s\nSource:%s:%d\n", execname, pid, copyinstr(arg0), copyinstr(arg1), copyinstr(arg2), arg3)
}
@we4tech
we4tech / chain_middelware_call.rb
Created Aug 7, 2018
How to chain middleware call in Ruby?
View chain_middelware_call.rb
# Create a middleware class
class Middleware
def call(*args)
puts "Args: #{args}"
yield
end
end
def call_in_chain(chain)
traverse_chain = lambda do
@we4tech
we4tech / Benchmark.txt
Last active Aug 2, 2018
Shows how to make a threaded call
View Benchmark.txt
## FYI: Not literally accurate. Because the API is coming from a non-constant setup. (A public API from httpbin)
user system total real
Sequential 10 calls
req:0: 200
req:1: 200
req:2: 200
req:3: 200
req:4: 200
req:5: 200
@we4tech
we4tech / host_application_routes.rb
Created Aug 2, 2018
Create a test mountable rails engine and mount through a parent rails routes
View host_application_routes.rb
mount RailsEngineTest::Engine => 'api/v3/'
@we4tech
we4tech / broadcaster.rb
Last active Aug 1, 2018
Rabbit Fanout Exchange Example
View broadcaster.rb
require 'bunny'
require 'irb'
STDOUT.sync = true
conn = Bunny.new("amqp://guest:guest@localhost:5672")
conn.start
ch = conn.create_channel
$x = ch.fanout('msgs')
View patch_active_record_search_path_to_not_set_already_set_search_path.rb
module ActiveRecord
module ConnectionAdapters
module PostgreSQL
module SchemaStatements
alias_method :old_schema_search_path=, :schema_search_path=
alias_method :old_schema_search_path, :schema_search_path
def schema_search_path=(schema_csv)
unless schema_search_path == schema_csv
self.old_schema_search_path = schema_csv
View method_with_metadata_and_advice.rb
require 'byebug'
module MethodMetadata
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def method_advice(data = {})
lineno = caller_locations(1, 1).first.lineno
You can’t perform that action at this time.