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
  • 15:54 (UTC +07:00)
View GitHub Profile
@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
@keymastervn
keymastervn / gist:41f1322ad405141f49762a6132a1243e
Created March 27, 2021 12:57
Dockerfile run fullstaq-ruby:2.6.6-jemalloc-buster
## Installing the NodeSource Node.js 10.x repo...
## Populating apt-get cache...
+ apt-get update
Hit:1 http://deb.debian.org/debian buster InRelease
Hit:2 http://security.debian.org/debian-security buster/updates InRelease
Hit:3 http://deb.debian.org/debian buster-updates InRelease
Ign:4 https://dl.bintray.com/fullstaq/fullstaq-ruby-apt debian-10 InRelease
@keymastervn
keymastervn / gist:207566b4d05063237292fd87cc39dc8c
Last active May 3, 2021 15:48
Heroku is simple, but I need to search a lot because only AWS and GCP involve me
$ heroku login
# remember heroku instance is wellplayed with platform below
$ bundle lock --add-platform x86_64-linux --add-platform ruby
# remember postgres is wellplayed too
$ rails new app --database=postgresql
Assume you push already
@keymastervn
keymastervn / Dockerfile
Created November 3, 2020 12:29
The flex Dockerfile for jemalloc ruby-2.6.6
#fullstaq-ruby enables malloc-trim and jemalloc which is said to save up to 50% memory consumption
#ARG RUBY_VERSION=2.6.6-jemalloc
#FROM quay.io/evl.ms/fullstaq-ruby:${RUBY_VERSION}-slim
FROM swipesense/ruby-jemalloc:2.6-buster-slim
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND noninteractive
# Specify JP mirror, other mirrors are less stable than JP's
RUN echo 'deb http://ftp.jp.debian.org/debian/ buster main contrib non-free' > /etc/apt/sources.list