Skip to content

Instantly share code, notes, and snippets.

View stephaneliu's full-sized avatar

Stephane Liu stephaneliu

  • Hawaii
  • 02:32 (UTC -10:00)
View GitHub Profile
@stephaneliu
stephaneliu / noticed.rb
Created February 8, 2025 19:42
Notice extensions
module EventExtensions
extend ActiveSupport::Concern
included do
scope :by_category, ->(category) { where.any(categories: category) }
end
end
module NotificationExtensions
extend ActiveSupport::Concern
@stephaneliu
stephaneliu / deploy.yml
Created February 4, 2025 19:41
Kamal deploy.yml for PSQL
# Name of your application. Used to uniquely configure containers.
service: hcr_kamal
# Name of the container image.
image: stephaneliu/hcr_kamal_pg
# Deploy to these servers.
servers:
web:
- kamal.hawaiiancrane.com
@stephaneliu
stephaneliu / record_strategy.rb
Last active April 4, 2023 08:01
Custom RuboCop cop to prevent using VCR cassettes with record strategies that make live requests
# .rubocop.yml
require:
- ./lib/custom_cops/vcr/record_strategy.rb
# lib/custom_cops/custom_cop_base.rb
# frozen_string_literal: true
# See https://docs.rubocop.org/rubocop/1.23/development.html for more info on creating new [Rubo]cops
module CustomCops
class CustomCopBase < RuboCop::Cop::Base
@stephaneliu
stephaneliu / .solargraph.yml
Created February 28, 2023 18:34
solargraph
---
include:
- "**/*.rb"
exclude:
- spec/**/*
- test/**/*
- vendor/**/*
- ".bundle/**/*"
require: []
domains: []
#!/usr/bin/env ruby
run_check = ENV['SAFE_COMMIT'].nil?
if run_check
focus_hits = []
binding_hits = []
# Find all filenames in spec directory that have been (A)dded (C)opied or (M)odified
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n")
# https://replit.com/join/eugzahzgxx-stephaneliu1
module GridPrinter
def print
sleep(0.2)
system 'clear'
(1..grid_size).each do |row|
puts grid[row][1..grid_size].join(' ')
end
end
require 'net/http'
require 'uri'
Net::HTTP.get(URI.parse('https://somewhere.com'))
# Gemfile
group :test do
gem "vcr", require: false
gem "webmock"
end
# spec/support/vcr.rb
# frozen_string_literal: true
require "vcr"
class Test < Thor
include Thor::Actions
desc "insert", "an example"
def insert
content = <<~EOL
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }\n\n
EOL
insert_into_file("spec/rails_helper.rb", content, before: "RSpec.configure do")
class CreateMailer
def initialize(event_catalog, ccir_mailer_policy_class)
@event_catalog = event_catalog
@ccir_mailer_policy = ccir_mailer_policy_class.new(event_catalog)
end
def send
return false unless ccir_mailer_policy.send_email?
# ...
end