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 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
@we4tech
we4tech / data_leak_detector.rb
Created May 30, 2018
Find out data leak from the rspec example
View data_leak_detector.rb
RSpec.configure do |config|
def count_rows_from_all_tables
Hash[
ActiveRecord::Base.connection.tables.map do |tbl|
[tbl, ActiveRecord::Base.connection.execute("select count(*) from #{tbl}").values.last.first.to_i]
end
]
end
config.around :example do |example|
@we4tech
we4tech / rebase-reminder-circleci-job.yml
Created May 18, 2018
Git rebase reminder for CircleCI
View rebase-reminder-circleci-job.yml
rebase-reminder:
docker:
# specify the version you desire here
- image: circleci/ruby:2.4.1-node-browsers
environment:
RAILS_ENV: test
PGHOST: 127.0.0.1
PGUSER: root
PUBLIC_HOST: https://example.org
@we4tech
we4tech / profile_string_generation.rb
Created Mar 13, 2018
Find out ruby string generation
View profile_string_generation.rb
require 'pp'
def profile
old_strs = ObjectSpace.count_objects[:T_STRING]
old_objs = GC.stat[:total_allocated_objects]
yield.tap do
new_strs = ObjectSpace.count_objects[:T_STRING]
new_objs = GC.stat[:total_allocated_objects]
@we4tech
we4tech / parse_new_relic_insides_data.rb
Created Feb 9, 2018
New Relic Insides Data Parser
View parse_new_relic_insides_data.rb
#!/usr/bin/env ruby
#
# frozen_string_literal: true
require 'byebug'
require 'json'
require 'csv'
module NewRelicInsides
class Parser
@we4tech
we4tech / boot.rb
Created Feb 7, 2018
Add TracePoint to find certain classes from the rails environment
View boot.rb
# Add ruby tracepoint
EXCLUDED_CLASSES = %w(Sidekiq::Worker Delayed::Worker Unicorn::Worker Sidekiq::Worker Parallel::DeadWorker
Parallel::Worker Concurrent::RubyThreadPoolExecutor::Worker Twilio::REST::TaskRouter::Worker)
$__TRACE_WORKERS = []
trace = TracePoint.new(:class) do |tp|
class_name = tp.self.name
next if class_name.nil?
@we4tech
we4tech / es_result_transformer.js
Created Apr 9, 2014
ElasticSearch result transformer example
View es_result_transformer.js
var data = [],
now = new Date().getTime();
root.hits.hits.forEach(function(hit) {
var d = new Date(),
ts = hit.fields.expired_at_de * 1000;
d.setTime(ts);
var diffInHours = (now - ts) / 1000.0 / 60.0 / 60.0;
@we4tech
we4tech / fibonacci_series.kt
Created Sep 5, 2017
Fibonacci series upto n
View fibonacci_series.kt
fun findFibSeries(n: Int) {
val series = mutableListOf(0, 1)
(0..n).map { n ->
series.add(series.takeLast(2)
.reduce {sum, it -> sum + it})
}
series.forEach { println(it) }
}
@we4tech
we4tech / javascript_generator_fibonacci.js
Created Jul 28, 2017
Use ES6 generator to generate infinite fibonacci series
View javascript_generator_fibonacci.js
function *calcFib () {
let n = 0
let fib = function(v) {
return v <= 1 ? v : fib(v - 1) + fib(v - 2)
}
while (true) yield fib(n++)
}
You can’t perform that action at this time.