Skip to content

Instantly share code, notes, and snippets.

View sj26's full-sized avatar
🤹‍♂️

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
@sj26
sj26 / Dockerfile
Last active March 5, 2019 05:08
Docker file cache test
FROM ruby
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle --deployment
RUN bundle show rack
version: "3.6"
services:
app:
build: ..
depends_on:
- selenium
environment:
SELENIUM_HOST: selenium
@sj26
sj26 / brew-mirror-artifacts.rb
Created November 19, 2018 06:12
Setup a mirror to use with $HOMEBREW_ARTIFACT_DOMAIN
# Homebrew has $HOMEBREW_ARTIFACT_DOMAIN which allows using a mirror for downloads:
#
# https://docs.brew.sh/Manpage#environment
#
# But no easy way to create such a mirror. This command which creates a mirror from
# all core formulae downloads. Pop it in /usr/local/Homebrew/Library/Homebrew/cmd/
# with a `chmod +x` and run `brew mirror-artifacts`.
require "formula"
def link_to(url, content = nil)
if ENV["BUILDKITE"]
"\e]1339;url=#{url.gsub(";", "%3b")}#{";content=#{content.gsub(";", "%3b")}" if content}\a"
else
url
end
end
def system!(*args)
system(*args) or fail("Command exited with status #{$?.exitstatus}: #{args.join(" ")}")
def link_to(url, content = nil)
if ENV["BUILDKITE"]
"\e]1339;url=#{url.gsub(";", "%3b")}#{";content=#{content.gsub(";", "%3b")}" if content}\a"
else
url
end
end
def system!(*args)
system(*args) or fail("Command exited with status #{$?.exitstatus}: #{args.join(" ")}")
@sj26
sj26 / application.rb
Created May 6, 2018 06:51
rails/rails#32808 — demonstrate that mail is not eager loaded correctly during application initialization
gem "railties", "5.2.0"
gem "actionmailer", "5.2.0"
require "rails/application"
require "action_mailer/railtie"
class Application < Rails::Application
config.eager_load = true
end
# Weak ACID semantics for Sidekiq jobs
#
# Include this module in a Sidekiq::Worker class and it will defer enqueuing
# jobs for that worker within an open ActiveRecord transaction until it is
# committed. Rollbacks will prevent any jobs being enqueued at all.
#
# ActiveRecord keeps track of all records which are being utilized within a
# transaction so it can fulfil commit and rollback callbacks. We create a fake
# record that quacks the same way for the same hooks.
#
@sj26
sj26 / sidekiq.service
Last active May 3, 2024 07:07 — forked from dsadaka/\lib\systemd\system\sidekiq-static.service
systemd unit files for multiple sidekiq workers
[Unit]
Description=Sidekiq workers
# start as many workers as you want here
Wants=sidekiq@1.service
Wants=sidekiq@2.service
# ...
[Service]
Type=oneshot
ExecStart=/bin/true
gem "activerecord", "~> 4.0.0"
require "active_record"
## Implementation
module ActiveRecord::OmitMethods
# Inverse of #merge, negates and merges the conditions from <tt>other</tt>, if <tt>other</tt> is an <tt>ActiveRecord::Relation</tt>.
# Returns an array representing the subset of the resulting records not appearing in <tt>other</tt>, if <tt>other</tt> is an array.
# Post.where(published: true).joins(:comments).omit( Comment.where(spam: false) )
@sj26
sj26 / enumerator-rate_limiting.rb
Last active January 29, 2017 11:16
Simple Ruby thread safe rate limiter with Enumerator#rate_limited_to extension
require "thread"
# Simple thread safe rate limiter
#
# Supply a limit of operations, and an interval in seconds (defaults to 1
# second, so ops/sec).
#
# Call `#wait` on every operation which will return immediately or sleep until
# the rate limit is satified.
#