Skip to content

Instantly share code, notes, and snippets.

View frullah's full-sized avatar
🎯
Focusing

Fajarullah frullah

🎯
Focusing
View GitHub Profile
@frullah
frullah / active_admin.js
Last active October 27, 2021 06:44
using Rails activeadmin with Vite bundler
// required dependencies
// - jquery
// - jquery-ui
// - @activeadmin/activeadmin
import jQuery from 'jquery'
window.jQuery = jQuery
window.$ = jQuery
@frullah
frullah / vite-stimulus-loading.js
Last active October 24, 2021 10:07
vite stimulus lazy loader
// this code is used for lazy loading stimulus controller with Vite
// Vite lazy import only works with relative path
// so place this code in stimulus controllers folder
// reference: https://github.com/vitejs/vite/issues/1931#issuecomment-868310388
// this code is originally from https://github.com/hotwired/stimulus-rails/blob/49cfc34beb92ad56140a78db6be4c7733207be30/app/assets/javascripts/stimulus-loading.js
const controllerAttribute = "data-controller"
const registeredControllers = {}
## Utilities
```
gem install rubocop
```
@frullah
frullah / script.sh
Last active March 15, 2022 17:09
shutdown until process finishes
# shutdown until process finishes
#
## arguments
# first argument is a PID
pid=$1
while true
do
if ! ps -p $pid > /dev/null
@frullah
frullah / rails_sql_log_parser.rb
Created March 21, 2022 17:15
read query from activerecord log
Rails.application.config.colorize_logging = false
io = StringIO.new
logger = Logger.new(io)
logger.formatter = proc do |_severity, _time, _progname, message|
sql = message.sub(/^\s*[A-Za-z0-9]+ Load \(\d+\.\d+ms\)\s+/, "").chomp
sql = sql.sub(/^\s*\(\d+\.\d+ms\)\s+/, "").chomp
IO.popen("sql-formatter", "r+") do |pipe|
pipe.puts sql
pipe.close_write
@frullah
frullah / create_rails_app_file.rb
Last active July 23, 2022 04:56
Used to create rails app file with module and classes included
#!/usr/bin/env rails runner
#
# Used to create rails app file with module and classes included
#
### How to use
# - Copy this into your bin folder.
# - Make this file executable by using `chmod +x`.
sub_directory = ARGV[0]
constant_name = ARGV[1]