Skip to content

Instantly share code, notes, and snippets.

View channainfo's full-sized avatar
🎯
Focusing

Channa Ly channainfo

🎯
Focusing
  • InSTEDD, SureSwift Capital, BookMeBus, VTENH, Onthegosystems
  • Phnom Penh
  • X @channaly
  • LinkedIn in/channaly
View GitHub Profile
@channainfo
channainfo / git-delete-multiple-branches-with-a-pattern
Last active January 29, 2024 02:39
Delete multiple branches from a repo with a pattern
# git branch -r list all branch from the remote repo
# pipe the output to grep only branches start with 'automatic_translations'
# echo each branch_name stripping the prefix origin/
# git push origin :{each_branch_name}
git branch -r | fgrep origin/automatic_translations | while read x; do echo "deleting ${x/origin\//}"; git push origin ":${x/origin\//}"; done
@channainfo
channainfo / 20231120092630_add_signature_to_delayed_jobs.rb
Last active May 6, 2024 08:02
Unique job with delayed_job using active job api
# add a new migration to the delayed_job table to track uniqueness
class AddSignatureToDelayedJobs < ActiveRecord::Migration[7.0]
def change
add_column :delayed_jobs, :signature, 'varchar(64)', index: true
end
end
@channainfo
channainfo / app.DockerFile
Created January 23, 2023 07:28 — forked from satendra02/app.DockerFile
docker+rails+puma+nginx+postgres (Production ready)
FROM ruby:2.3.1
# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
# Set an environment variable where the Rails app is installed to inside of Docker image:
ENV RAILS_ROOT /var/www/app_name
RUN mkdir -p $RAILS_ROOT
# Set working directory, where the commands will be ran:
@channainfo
channainfo / zeitwerk_loader_spec.rb
Created September 17, 2022 01:29
Genesis spec right after integrate RSpec zeitwerk_loader_spec.rb at the root of spec directory
require 'rails_helper'
describe 'Zeitwerk' do
it 'eager loads all files' do
expect { Zeitwerk::Loader.eager_load_all }.to_not raise_error
end
end
@channainfo
channainfo / my_alias.sh
Last active August 31, 2022 04:06
useful custom alias for development
# Rails
alias "rce"="EDITOR=\"code --wait\" bin/rails credentials:edit"
alias "rapc"="bundle exec rails assets:clobber RAILS_ENV=production && bundle exec rails assets:precompile RAILS_ENV=production"
alias "rr"="bundle exec rspec"
alias "rs"="bundle exec rails s -b 0.0.0.0"
alias "rc"="bundle exec rails c"
alias "st"="spring stop"
alias "rcf"="st && rc"
alias "opengem"="gem open -e code"
alias "geminfo"="opengem"
@channainfo
channainfo / gist:6c7e09fb7ea758bb7d6fc2bb67624ed4
Last active August 25, 2022 04:41
IntelliJ IDEA macosX shortcute
### IDE Shortcut IntelliJ IDEA
``` cmd + shift + o ``` : Open file
``` cmd + d ``` : Duplicate line
``` cmd + ctrl + g ``` : Select multiple occurren
``` opt + shift + up/down ``` : Move item up and
``` opt + shift + click ``` : Multi select
@channainfo
channainfo / rails_helper.rb
Created July 27, 2022 10:17
Disable callback in rspec
#Disable XLIFF validation for all specs
config.before :all do
XliffUploader._before_callbacks.delete(:store)
end
#Enable XLIFF validation only for specs with ":enable_xliff_validation => true"
config.before :each, :enable_xliff_validation => true do
XliffUploader._before_callbacks[:store] = [:validate_xliff]
end
WITH
paid_shops AS (
SELECT DISTINCT ON(shopify_domain) shopify_domain,shop_plan, plans.name as plan_name, currency
FROM shops
INNER JOIN charges on shops.id = charges.shop_id
INNER JOIN plans ON charges.plan_id = plans.id
WHERE charges.processor = 'shopify' AND (commenced_at <= now())
AND (cancelled_at IS NULL OR cancelled_at >= now())
-- order by shopify_domain, charges.amount DESC
),
@channainfo
channainfo / project.rb
Last active August 31, 2022 02:07
State dependencies between two or model - design / retrieval technique
def self.filter_by_job_status(job_status)
projects = where(nil)
if job_status == :completed
match_all = <<~EOD
EXISTS ( SELECT 1 FROM jobs WHERE jobs.project_id = projects.id ) AND
NOT EXISTS ( SELECT 1 from jobs WHERE jobs.project_id = projects.id AND jobs.status NOT IN (?) )
EOD
return projects.where([match_all, job_status])
end
@channainfo
channainfo / main.tf
Created January 26, 2022 03:07
Amazon application load balancer with multiple certificates attachment
resource "aws_lb" "main" {
name = var.name
load_balancer_type = "application"
security_groups = var.security_group_ids
enable_deletion_protection = true
subnets = var.subnet_ids
internal = false
tags = var.default_tags
}