Skip to content

Instantly share code, notes, and snippets.

View rmm5t's full-sized avatar
🌐
building itsy bitsy parts of the internet that grow

Ryan McGeary rmm5t

🌐
building itsy bitsy parts of the internet that grow
View GitHub Profile
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Hippie expand. Groovy vans with tie-dyes.
;; Change the default hippie-expand order and add yasnippet to the front.
(setq hippie-expand-try-functions-list
'(yas/hippie-try-expand
try-expand-dabbrev
try-expand-dabbrev-all-buffers
try-expand-dabbrev-from-kill
try-complete-file-name
@rmm5t
rmm5t / README.md
Created August 19, 2008 23:38
Locale override examples for the timeago jQuery plugin (http://timeago.yarp.com)

This gist is now deprecated

Please visit the locales directory inside the main timeago repository intead.

@rmm5t
rmm5t / OUTPUT.md
Last active February 19, 2021 21:18
How to properly introduce a new counter_cache to an existing Rails project.

Fast/efficient approach:

-- execute("UPDATE posts SET comments_count = (SELECT count(1) FROM comments WHERE comments.post_id = posts.id)")
   -> 1.3197s

Slow/naïve approach:

@rmm5t
rmm5t / bob.rb
Last active April 9, 2020 02:06
class Bob
def respond_to(input)
@input = input.strip
return "Fine. Be that way!" if silence?
return "Whoa, chill out!" if shouting?
return "Sure." if question?
"Whatever."
end
@rmm5t
rmm5t / benchmark_array_product.rb
Created June 30, 2019 14:23
Benchmark Array#product
require 'benchmark'
def test_nested_loop
1.upto(20) do |x|
1.upto(30) do |y|
x * y
end
end
end
@rmm5t
rmm5t / benchmark_lazy.rb
Last active June 23, 2019 18:58
Benchmark enumerator patterns
require 'benchmark'
array = (1..1000).to_a
n = 1000
Benchmark.bmbm do |x|
x.report("lazy") { n.times { array.lazy.select(&:even?).map { |i| i / 2 }.to_a } }
x.report("double-pass") { n.times { array.select(&:even?).map { |i| i / 2 } } }
x.report("nested conditional") do
n.times do
@rmm5t
rmm5t / benchmark_command_object_vs_poro.rb
Last active June 18, 2019 23:42
Benchmarking command object pattern vs PORO
require 'benchmark'
require 'active_support/all'
class CommandObject
def self.execute_with(arg)
new(arg).tap(&:run)
end
def initialize(arg)
@arg = arg
@rmm5t
rmm5t / benchmark_instance_var_vs_delegate.rb
Last active June 18, 2019 23:38
Benchmark instance variable vs delegation
require 'benchmark'
require 'active_support/all'
Source = Struct.new(:value, keyword_init: true)
class InstanceVarTest
attr_reader :source, :value
def initialize(source)
@source = source
@rmm5t
rmm5t / benchmark_style_multiple_comparison.rb
Last active June 18, 2019 20:36
Style/MultipleComparison benchmark
require 'benchmark'
def test_conditionals(n)
n == 1 || n == 2 || n == 3 || n == 4 || n == 5 || n == 6 || n == 7
end
def test_include(n)
[1, 2, 3, 4, 5, 6, 7].include?(n)
end