Skip to content

Instantly share code, notes, and snippets.

View ridiculous's full-sized avatar

Ryan Buckley ridiculous

  • California
View GitHub Profile
@ridiculous
ridiculous / Rakefile
Created January 23, 2023 18:49
Rakefile for split up test suite
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
Dontspreadit::Application.load_tasks
begin
require 'rspec/core/rake_task'
Rake::Task['default'].clear
@ridiculous
ridiculous / fake_schema.rb
Created October 4, 2018 23:52
Find discrepancies between Rails schema.rb and the actual database
class FakeSchema
attr_reader :defs, :diff
def self.define(*, &block)
$schema = new
$schema.instance_eval(&block)
end
def initialize
@defs = {}
require 'fileutils'
class ProcessRunner
PIDFILE_MODE = (::File::CREAT | ::File::EXCL | ::File::WRONLY)
LOG_DIR_MODE = 0o0755
LOG_FILE_MODE = 0o0644
attr_reader :name, :pidfile, :logfile
def initialize(opts = {})
#!/usr/bin/env ruby
# Installs the latest version of a gem to the "vendor/gems" directory, which can be referenced from the Gemfile
# Expects the gem to be in the "vendor/gems" directory
#
# @usage Sudo is used because it writes to a directories in "vendor/gems"
#
# sudo ruby script/unpack <gem>
#
require 'pathname'
upstream app {
server unix:/tmp/unicorn.prism.sock fail_timeout=0;
}
server {
listen 8081;
server_name localhost;
location / {
root /Users/rbuckley/apps/prism/public;
$ rspec-scaffold lib/app.rb
/Users/rbuckley/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/fileutils.rb:252:in `mkdir': Permission denied @ dir_s_mkdir - /lib (Errno::EACCES)
from /Users/rbuckley/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/fileutils.rb:252:in `fu_mkdir'
from /Users/rbuckley/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/fileutils.rb:226:in `block (2 levels) in mkdir_p'
from /Users/rbuckley/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/fileutils.rb:224:in `reverse_each'
from /Users/rbuckley/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/fileutils.rb:224:in `block in mkdir_p'
from /Users/rbuckley/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/fileutils.rb:210:in `each'
from /Users/rbuckley/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/fileutils.rb:210:in `mkdir_p'
from /Users/rbuckley/apps/gems/rspec-scaffold/lib/rspec/scaffold/file_writer.rb:20:in `write!'
from /Users/rbuckley/apps/gems/rspec-scaffold/lib/rspec/scaffold.rb:44:in `testify_file'
# @usage Start and stop a ruby process that just logs to a file every couple seconds, but can be interrupted gracefully
#
# ruby script/wb
# kill -INT `cat tmp/pids/wb.pid`
#
require "logger"
require "fileutils"
PID_FILE = File.expand_path("../../tmp/pids/wb.pid", __FILE__)
LOG_FILE = File.expand_path("../../log/wb.log", __FILE__)
@ridiculous
ridiculous / unicorn_reaper.rb
Last active January 31, 2017 04:06
Ruby thread to monitor ruby processes and stop them should they reach a certain memory size
# This file can be required from "config/unicorn.rb" so the thread will run alongside the master process
# This will kill any rogue memory-greedy unicorn processes
unicorn_worker_memory_limit = 220_000
Thread.new do
loop do
begin
lines = `ps -e -www -o pid,rss,command | grep '[u]nicorn_rails worker'`.split("\n")
lines.each do |line|
parts = line.split(' ')
module VersionableApi
def self.extended(base)
base.class_eval do
def call_versioned_method(name)
VersionableApi.controllers[self.class].call_action(self, name)
end
end
end
class << self
module Usable
def config
@config ||= Config.new
end
def use(mod, options = {})
send :include, mod unless self < mod
if block_given?
yield config
else