Skip to content

Instantly share code, notes, and snippets.

View we4tech's full-sized avatar

Hossain Khan we4tech

View GitHub Profile
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 14:17
Find out data leak from the rspec example
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 16:32
Git rebase reminder for CircleCI
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 March 13, 2018 14:35
Find out ruby string generation
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 / boot.rb
Created February 7, 2018 20:51
Add TracePoint to find certain classes from the rails environment
# 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 / fibonacci_series.kt
Created September 5, 2017 03:32
Fibonacci series upto n
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 July 28, 2017 21:32
Use ES6 generator to generate infinite fibonacci series
function *calcFib () {
let n = 0
let fib = function(v) {
return v <= 1 ? v : fib(v - 1) + fib(v - 2)
}
while (true) yield fib(n++)
}
@we4tech
we4tech / tunnel
Created August 13, 2016 01:14
Tunnel for PayPal IPN
#!/usr/bin/env bash
ssh -v -nNT -R 9999:localhost:3000 ubuntu@staging.source4style.com
@we4tech
we4tech / nice-shadow.scss
Created July 29, 2016 15:35
Collection of Nice Shadow effects
.shadow1 {
box-shadow: 0 0 20px 1px rgba(114,114,189,0.1);
}
@we4tech
we4tech / country_field.js.jsx.coffee
Created March 30, 2016 01:57
An Example of How to Use React from AngularJS
window.UIControls.CountryField = React.createClass
mixins: [CountriesMixin]
getInitialState: -> {code: @props.data}
changeCountry: (evt) ->
code = evt.currentTarget.value
@setState(code: code)
@props.onChange(code) if @props.onChange?