Skip to content

Instantly share code, notes, and snippets.

View mohnish's full-sized avatar

Mohnish Thallavajhula mohnish

View GitHub Profile
@mohnish
mohnish / benchmark.rb
Last active February 27, 2016 00:59
base benchmark file
require 'benchmark/ips'
Benchmark.ips do |x|
x.config(time: 5, warmup: 2)
x.report('foo') do |times|
end
x.report('bar') do |times|
@mohnish
mohnish / merge_vs_merge_bang_vs_square_accessor.rb
Last active February 26, 2016 20:16
benchmark merge_vs_square_accessor
require 'benchmark/ips'
foo = { foo_1: 'one', foo_2: 'two' }
bar = { bar_1: 'one', bar_2: 'two' }
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
x.report('merge!') do |times|
foo = { foo_1: 'one', foo_2: 'two' }
require 'active_record'
# Temporary switch to blank rake app, extract required tasks and import them to
# current rake task. Skip seed loader here, as we do not need it for tests.
# More info on AR tasks import: @see https://gist.github.com/drogus/6087979
def import_active_record_tasks(default_rake_app)
Rake.application = Rake::Application.new
Rake.application.rake_require('active_record/railties/databases')
# gem install json
# gem install oj
# gem install yajl-ruby
require 'benchmark'
require 'json'
require 'oj'
require 'yajl'
n = 100000
@mohnish
mohnish / jquery.waituntilexists.js
Created December 8, 2015 02:32 — forked from buu700/jquery.waituntilexists.js
jQuery plugin which runs handler function once specified element is inserted into the DOM
(function ($) {
/**
* @function
* @property {object} jQuery plugin which runs handler function once specified element is inserted into the DOM
* @param {function} handler A function to execute at the time when the element is inserted
* @param {bool} shouldRunHandlerOnce Optional: if true, handler is unbound after its first invocation
* @example $(selector).waitUntilExists(function);
*/
@mohnish
mohnish / benchmark_find_in_batches.rb
Last active June 10, 2016 22:13
benchmark for find in batches
require 'benchmark/ips'
Benchmark.ips do |x|
x.config(:time => 5, :warmup => 2)
x.report("select in batches and lookup using the id") do
User.find_in_batches(:conditions => ["updated_at > ?", 8.weeks.ago.to_s(:db)], :select => :id) do |users|
users.map { |user| User.find(user.id, :include => [:user_metric]).id }
end
end
@mohnish
mohnish / what-forces-layout.md
Created October 19, 2015 23:56 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@mohnish
mohnish / .ctags
Last active October 8, 2015 20:44
--recurse=yes
--tag-relative=yes
--exclude=*.git*
--exclude=*.pyc
--exclude=*.pyo
--exclude=.DS_Store
--exclude=*.md
--exclude=*.mkd
.nav-tab {
...
// instead of putting it on
border-right: 1px solid #424242;
&:last-child {
border-right: 0; // and then taking it off
}
// use CSS not() to only apply to the elements you want
&:not(:last-child) {
border-right: 1px solid #424242;