Skip to content

Instantly share code, notes, and snippets.

@khoan
khoan / sidekiq_honeybadger.rb
Last active August 11, 2023 00:51
skip reporting transient errors
class TransientError < StandardError
def report_error!
@report_error = true
end
# skip error reporting by default until we're told to report error
def skip_reporting_error?
!@report_error
end
end
# When intercom javascript is excluded from HTML, any attempt to invoke `window.Intercom(...)` would
# result in runtime error. This patch introduces a callback into the controller, so that a shim can
# be inserted, when intercom javascript is excluded.
#
# Remove this patch and update your code if alternative at https://github.com/intercom/intercom-rails/pull/344
# is accepted.
spec = Bundler.definition.specs.find{|s| s.name == 'intercom-rails'}
if Gem::Dependency.new(spec.name, '> 0.4.2').match?(spec.name, spec.version)
raise Gem::DependencyError, "Check that patch is still applicable for intercom-rails gem version #{spec.version}"

Migrate Homebrew from Intel to M1

Dump install packages

brew bundle dump

Remove Intel homebrew

@khoan
khoan / browser-event.html
Created June 2, 2022 04:38
browser event
<!DOCTYPE html>
<html>
<head>
<title>Browser events</title>
</head>
<body>
<div>
https://mdn.github.io/learning-area/javascript/building-blocks/events/show-video-box.html
<button>Click me</button>
</div>
@khoan
khoan / bourne.txt
Created August 19, 2021 13:52
Bourne Shell Reference
Bourne Shell Reference:
This file contains short tables of commonly used items in this shell. In
most cases the information applies to both the Bourne shell (sh) and the
newer bash shell.
Tests (for ifs and loops) are done with [ ] or with the test command.
@khoan
khoan / australian-postcodes.sql
Created November 13, 2020 06:17 — forked from randomecho/australian-postcodes.sql
Australian postcodes (with states and suburb names) geocoded with latitude and longitude.
/*
Taken and cribbed from blog.datalicious.com/free-download-all-australian-postcodes-geocod
May contain errors where latitude and longitude are off. Use at own non-validated risk.
*/
SET NAMES utf8;
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS postcodes_geo;
@khoan
khoan / some_controller.rb
Created June 6, 2020 12:00 — forked from mlt/some_controller.rb
Stream PostgreSQL query with potentially huge result set as CSV using gzip compression in Rails and low memory overhead
headers['X-Accel-Buffering'] = 'no'
headers['Cache-Control'] = 'no-cache'
headers['Content-Type'] = 'text/csv; charset=utf-8'
headers['Content-Disposition'] = 'inline; filename="data.csv"'
headers['Content-Encoding'] = 'gzip'
sql = "select * from something;"
self.response_body = SqlToCsvStreamer.new(sql)
@khoan
khoan / user.rb
Created May 21, 2020 13:48 — forked from ziemekwolski/user.rb
Ruby model formatted
class User < ActiveRecord::Base
# == Constants ============================================================
GENDERS = [[‘Male’, ‘m’], [‘Female’, ’f’]].freeze
# == Attributes ===========================================================
# paperclip
attr_accessor :remove_logo
@khoan
khoan / ticket.rb
Created May 2, 2020 00:31 — forked from dhh/ticket.rb
class Ticket < ActiveRecord::Base
belongs_to :grouper
belongs_to :user
validate :user_cant_be_blacklisted, on: :confirmation
validate :user_cant_double_book, on: :confirmation
validate :grouper_cant_be_full, on: :confirmation
validate :grouper_cant_have_occurred, on: :confirmation
Admin
[] enable/disable inspection module on agency
PM can go through the whole motion
[] update property condition
add item to condition area /property/144/condition/area/5173
then click back /property/144/condition
items count is still the old items count
inspection report