Skip to content

Instantly share code, notes, and snippets.

✂️
Cutting red diffs

Samuel Cochran sj26

✂️
Cutting red diffs
Block or report user

Report or block sj26

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sj26
sj26 / Dockerfile
Last active Mar 5, 2019
Docker file cache test
View Dockerfile
FROM ruby
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle --deployment
RUN bundle show rack
View docker-compose.yml
version: "3.6"
services:
app:
build: ..
depends_on:
- selenium
environment:
SELENIUM_HOST: selenium
@sj26
sj26 / brew-mirror-artifacts.rb
Created Nov 19, 2018
Setup a mirror to use with $HOMEBREW_ARTIFACT_DOMAIN
View brew-mirror-artifacts.rb
# 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"
View build-packer-templates.rb
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(" ")}")
View Rakefile
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
rails/rails#32808 — demonstrate that mail is not eager loaded correctly during application initialization
View application.rb
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
View sidekiq-after_transaction.rb
# 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 Sep 7, 2018 — forked from dsadaka/\lib\systemd\system\sidekiq-static.service
systemd unit files for multiple sidekiq workers
View sidekiq.service
[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
View omitting.rb
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 Jan 29, 2017
Simple Ruby thread safe rate limiter with Enumerator#rate_limited_to extension
View enumerator-rate_limiting.rb
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.
#
You can’t perform that action at this time.