Skip to content

Instantly share code, notes, and snippets.

View trevorturk's full-sized avatar

Trevor Turk trevorturk

  • Chicago
View GitHub Profile

Ruby: The future of frozen string literals

What is a literal?

In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.

Some examples:

7 # integer literal
@jonatas
jonatas / poc_downloads.rb
Last active June 21, 2024 17:36
POC Make RubyGems track downloads with TimescaleDB
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'timescaledb'
gem 'bulk_insert'
gem 'pry'
end
require 'timescaledb'
@shaundon
shaundon / ContentView.swift
Created February 4, 2024 10:20
Proof of concept of UserDefaults plus Zephyr, making use of notifications to update the UI when a value changes externally.
import SwiftUI
struct ContentView: View {
@State private var preferences = PreferencesModel()
var body: some View {
VStack {
HStack {
Text("Value: ")
Text(preferences.theNumber.formatted()).bold()
@shaundon
shaundon / ContentView.swift
Last active June 27, 2024 18:52
UserDefaults group proof of concept
import SwiftUI
struct ContentView: View {
@Environment(PreferencesModel.self) var preferences
var body: some View {
Text("Salary: \(preferences.salary)")
}
}
@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 July 3, 2024 10:19
Using Jemalloc 5 with Ruby.md

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

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

Ubuntu/Debian

FROM ruby:3.1.2-bullseye
RUN apt-get update ; \
@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