Skip to content

Instantly share code, notes, and snippets.

View thisismydesign's full-sized avatar

Csaba Apagyi thisismydesign

View GitHub Profile
@thisismydesign
thisismydesign / README.md
Last active March 21, 2018 18:10
Losing main thread with rake on Interrupt

Rakefile:

code = <<EOF
  begin
    sleep
  rescue Exception => e
    gets
  end
EOF
@thisismydesign
thisismydesign / rubocop_parallel_autocorrect.sh
Last active April 10, 2018 15:12
RuboCop parallel auto-correct problem
$ rubocop --parallel --auto-correct
# =>
# -P/--parallel can not be combined with --auto-correct.
@thisismydesign
thisismydesign / aw_rpa.sh
Last active April 10, 2018 15:11
RuboCop parallel auto-correct solution
$ aw rpa
# =>
# [fb34328a] Running rubocop --parallel
# [fb34328a] Inspecting 157 files
# [fb34328a] ..................................C..........................................................................................................................
# [fb34328a]
# [fb34328a] Offenses:
# [fb34328a]
# [fb34328a] app/app.rb:28:8: C: Layout/TrailingWhitespace: Trailing whitespace detected. (https://github.com/bbatsov/ruby-style-guide#no-trailing-whitespace)
# [fb34328a] end
@thisismydesign
thisismydesign / x.rb
Created April 25, 2018 08:56
Rails: slow query logging instrumentation
ActiveSupport::Notifications.subscribe("sql.active_record") do |_name, start, finish, _id, payload|
duration = finish.to_f - start.to_f
if duration >= 1.0 # Feel free to change
Rails.logger.warn "slow query detected: #{payload[:sql]}, duration: #{duration}"
caller.each do |line|
next unless line.include? Dir.pwd
Rails.logger.warn line
end
end
end
@thisismydesign
thisismydesign / settings.js
Last active May 4, 2019 13:17
VSCode config
{
// [OPTIONAL]
// https://code.visualstudio.com/docs/editor/integrated-terminal#_changing-how-the-terminal-is-rendered
// "terminal.integrated.rendererType": "dom",
// options for JS code formatting with Prettier
"editor.formatOnSave": false,
"eslint.autoFixOnSave": true,
@thisismydesign
thisismydesign / _rails#32910.rb
Last active May 18, 2018 16:49
Rails#32910 SQLite3 uses different root paths for db:create and db:drop tasks
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
a = gemfile(true) do
@thisismydesign
thisismydesign / _rails#32914.rb
Last active May 17, 2018 12:32
Rails#32914 db:drop drops not created DB with postgresql and sqlite3 adapters (but not with mysql2)
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
a = gemfile(true) do
@thisismydesign
thisismydesign / _rails#32915.rb
Last active May 17, 2018 15:23
Rails#32915 db:create cannot be executed twice via `Rake::Task.invoke`
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
a = gemfile(true) do
@thisismydesign
thisismydesign / _rails#32918.rb
Last active May 17, 2018 15:22
ActiveRecord::Base is not `connected?` after successful `establish_connection`
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
a = gemfile(true) do
@thisismydesign
thisismydesign / minimal_inline_rspec.rb
Created May 18, 2018 11:50
Ruby minimal inline RSpec
# frozen_string_literal: true
begin
require "bundler/inline"
rescue LoadError => e
$stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler"
raise e
end
gemfile(true) do