Skip to content

Instantly share code, notes, and snippets.

View keymastervn's full-sized avatar
🥐
salted egg yolk croissant

Dat Le-Tien keymastervn

🥐
salted egg yolk croissant
  • Employment Hero
  • HCMC, Vietnam
  • 11:42 (UTC +07:00)
View GitHub Profile
@keymastervn
keymastervn / ruby_meta.md
Created January 18, 2022 08:24 — forked from jamesyang124/ruby_meta.md
Ruby meta programming

#!/bin/ruby --verion => 2.0.0-p353

Self

In Ruby, self is a special variable that always references the current object.

  • Inside class or module definition, self refer to the Class or Module object.
  • Inside instance method, self refer to future instance object.
  • Inside class method, self refer to the class.i
@keymastervn
keymastervn / haml_legacy_fe_codeowners.rb
Last active July 26, 2021 09:05
Get haml literal string with CODEOWNERS
require 'code_owners'
require 'open3'
require 'pp'
UNOWNED = 'UNOWNED'
# {:file=>"vendor/assets/stylesheets/token-input.css", :owner=>"UNOWNED", :line=>nil, :pattern=>nil}
@codeowners = CodeOwners.ownerships
def syscall(*cmd)
@keymastervn
keymastervn / bm__dir_with_cache.rb
Last active May 16, 2021 10:01
Testing if rubocop `smart_path` is efficient in large number of offenses
require 'benchmark/ips'
def dir_no_cache
Dir.pwd
end
def dir_cache
@dir_cache ||= Dir.pwd
end
@keymastervn
keymastervn / bm__psych_yaml.rb
Created April 30, 2021 07:35
Benchmark psych vs yaml
require 'benchmark/memory'
require 'memory_profiler'
require 'benchmark/ips'
require 'psych'
require 'yaml'
file = File.read('./devise.en.yml')
@keymastervn
keymastervn / autoreload.rb
Created April 26, 2021 10:33 — forked from mikiobraun/autoreload.rb
autoreloading of ruby files which have changed in the meantime
# This file extends the Kernel's require function and adds the
# AutoReload module which allows to reload files once they have changed
# on the disk.
#
# Basically, you just require your files as usual, and if you want to update
# the files, either call AutoReload.reload(file) or AutoReload.reload_all.
#
# Usage:
# irb -rautoload
#
@keymastervn
keymastervn / benchmark_send__string_symbol_interpolation.rb
Last active April 30, 2021 07:07
benchmark_send__string_symbol_interpolation
require 'benchmark/ips'
def very_good_content
1+2+3+4+5
end
Benchmark.ips do |x|
x.report("string") { send :very_good_content }
x.report("symbol") { send 'very_good_content' }
x.report("string.to_sym") { send 'very_good_content'.to_sym }
@keymastervn
keymastervn / derailed_filestack_large_mem_footprint.txt
Last active April 30, 2021 07:07
filestack_large_mem_footprint
➜ xxx git:(----) ✗ bundle exec derailed bundle:mem CUT_OFF=0.3
/Users/datle-eh/.rbenv/versions/2.6.6/lib/ruby/gems/2.6.0/gems/activesupport-4.2.11.3/lib/active_support/core_ext/object/duplicable.rb:111: warning: BigDecimal.new is deprecated; use BigDecimal() method instead.
TOP: 164.4844 MiB
filestack: 55.8359 MiB
filestack/models/filelink: 55.793 MiB (Also required by: filestack/models/filestack_av)
filestack/utils/utils: 53.9414 MiB (Also required by: filestack/models/filestack_av, filestack/mixins/filestack_common, and 3 others)
mimemagic: 50.7422 MiB (Also required by: filestack/utils/multipart_upload_utils, filestack/mixins/filestack_common)
typhoeus: 3.0938 MiB (Also required by: filestack/utils/multipart_upload_utils)
typhoeus/hydra: 2.6211 MiB
typhoeus/hydra/block_connection: 2.5039 MiB
@keymastervn
keymastervn / benchmark_mini_mime_vs_marcel.rb
Last active April 13, 2021 07:58 — forked from nvh0412/benchmark.rb
Benchmark mini_mime vs marcel
require 'memory_profiler'
require 'benchmark/ips'
puts "Memory stats for requiring mini_mime"
result = MemoryProfiler.report do
require 'mini_mime'
end
puts "Total allocated: #{result.total_allocated_memsize} bytes (#{result.total_allocated} objects)"
puts "Memory stats for requiring marcel"
require "benchmark/memory"
require "benchmark/ips"
def option_hash(options = {}); end
def double_splat(**options); end
Benchmark.memory do |x|
x.report("mem option_hash") { option_hash(foo: 1, bar: 2) }
x.report("mem double_splat") { double_splat(foo: 1, bar: 2) }
# x.compare!
# frozen_string_literal: true
# rubocop:disable
require 'json'
require 'pry'
require 'pry-byebug'
# NOTE: going to logdna and download the jsonl and parse