Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile
@mudge
mudge / production.rb
Last active November 21, 2023 14:06
How to configure Rails and Rack::Attack to use the real client IP when running behind Cloudflare
Rails.application.configure do
# Add Cloudflare's IPs to the trusted proxy list so they are ignored when
# determining the true client IP.
#
# See https://www.cloudflare.com/ips-v4/ and https://www.cloudflare.com/ips-v6/
config.action_dispatch.trusted_proxies = ActionDispatch::RemoteIp::TRUSTED_PROXIES + %w[
173.245.48.0/20
103.21.244.0/22
103.22.200.0/22
103.31.4.0/22
@jnunemaker
jnunemaker / active_job_checkins.rb
Created September 28, 2023 14:31
Automatic honey badger check ins for active job. Just setup the check in with honey badger and configure an env var to the identifier they provide.
# Set HONEYBADGER_FOO_BAR_JOB=asdf where asdf is the check in value Honeybadger gives you.
class ApplicationJob < ActiveJob::Base
after_perform { |job| job.honeybadger_checkin }
# Check in with Honeybadger to let us know that the job was performed
# if there is an identifier configured for the job.
def honeybadger_checkin
identifier = honeybadger_checkin_identifier
return unless identifier.present?
@technicalpickles
technicalpickles / benchmark.rb
Last active September 11, 2023 21:25
Bundler::Settings#[] benchmark, see https://github.com/rubygems/rubygems/pull/6923
require "benchmark/ips"
require "benchmark/memory"
require 'bundler'
class Bundler::Settings
def original(name)
key = key_for(name)
value = configs.values.map {|config| config[key] }.compact.first
converted_value(value, name)
@joemasilotti
joemasilotti / Endpoint.swift
Last active May 28, 2023 16:54
A Rails-like environment helper for iOS apps, from https://masilotti.com/rails-like-endpoint-switcher-for-ios-apps/
import Foundation
enum Environment: String {
case development, staging, production
}
extension Environment {
static var current: Environment {
if isAppStore {
return .production
@jjb
jjb / file.md
Last active April 16, 2024 00:03
Using Jemalloc 5 with Ruby.md

For years, people have been using jemalloc with ruby. There are various benchmarks and discussions. Legend had it that Jemalloc 5 doesn't work as well as Jemalloc 3.

Then, one day, hope appeared on the horizon. Someone offered a config for Jemalloc 5.

The recipe would be something like this (shown with official docker ruby image).

FROM ruby:3.1.2-bullseye
@noelrappin
noelrappin / sigilize.rb
Last active February 17, 2023 00:02
Sigilize
class Module
def sigilize(method_name)
define_method("#{method_name}?") do |*args, **kwargs|
!!method_name(*args, **kwargs)
end
define_method("#{method_name}!") do |*args, **kwargs|
result = method_name(*args, **kwargs)
raise StandardError unless result
result
@joeldrapper
joeldrapper / attribute_memoization.rb
Last active December 13, 2022 12:24
Attribute Memoization
module AttributeMemoization
def attr_accessor(*names, &block)
return super(*names) unless block_given?
attr_reader(*names, &block)
attr_writer(*names)
end
def attr_reader(*names, &block)
return super(*names) unless block_given?
@raghubetina
raghubetina / apprenticeship-artifacts.md
Last active June 10, 2022 13:06
Artifacts from DPI Software Development Apprenticeship Program

Artifacts from a 1-year Full-Stack Developer program

If we run a 1-year Full-Stack Development program, what artifacts would we want students to exit with? What would hiring managers want to see? What will make our graduates stand out?

We should contact employer partners to ask them what they'd like to see, especially ones like who have strong apprenticeship/in-house training programs in place. E.g., thoughtbot.

Once we figure out the artifacts that would best demonstrate valuable skills/make candidates attractive, we should create a dream personal website/portfolio to act as a target for students, including stretch goals. We can then backward design the curriculum from there.


@martinwoodward
martinwoodward / mermaid.md
Created February 11, 2022 20:34
GitHub HTML Rendering Pipeline
```mermaid
sequenceDiagram
    participant dotcom
    participant iframe
    participant viewscreen
    dotcom->>iframe: loads html w/ iframe url
    iframe->>viewscreen: request template
    viewscreen->>iframe: html & javascript
 iframe-&gt;&gt;dotcom: iframe ready
@amirrajan
amirrajan / main.rb
Last active November 20, 2023 07:25
DragonRuby Game Toolkit - Shadows (https://amirrajan.itch.io/shadows) (https://youtu.be/wQknjYk_-dE)
# demo gameplay here: https://youtu.be/wQknjYk_-dE
# this is the core game class. the game is pretty small so this is the only class that was created
class Game
# attr_gtk is a ruby class macro (mixin) that adds the .args, .inputs, .outputs, and .state properties to a class
attr_gtk
# this is the main tick method that will be called every frame the tick method is your standard game loop.
# ie initialize game state, process input, perform simulation calculations, then render
def tick
defaults