Skip to content

Instantly share code, notes, and snippets.

@jjb
jjb / file.md
Last active March 19, 2024 23:29
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
# BAD each iteration loads invoice model
class Company < ApplicationRecord
has_many :invoices
end
class Invoice < ApplicationRecord
belongs_to :company
end
@brenogazzola
brenogazzola / fix_action_text.rb
Last active February 14, 2022 20:29
Fix ActionText Images
# After active storage urls are changed, use this to recreate all trix attachments
def self.refresh_trixes
ActionText::RichText.where.not(body: nil).find_each do |trix|
Trix::RefreshJob.perform_later(trix)
end
end
# After active storage urls are changed, use this to recreate a specific strix attachments
def self.refresh_trix(trix)
return unless trix.embeds.size.positive?
@statico
statico / cloudWatchAlarmsToSlack.js
Created January 19, 2022 21:20
Lambdas for Slack Notifications
const fetch = require('./fetch')
const RED = '#cd3131'
const YELLOW = '#e5e512'
const GREEN = '#05bc79'
const BLUE = '#2472c8'
exports.handler = async function(event, context) {
// Debugging
// console.log('event', JSON.stringify(event, null, 2))
@threepointone
threepointone / feature-flags-client-implementation.md
Last active June 1, 2023 18:35
Implementing a client for feature flags

On implementing a client for feature flags in your UI codebase

This document isn't an explainer on Feature Flags, you can find that with my amateur writeup, or literally hundreds of better writeups out there.

This document is also agnostic to the choice of service you'd use: LaunchDarkly or split.io or optimizely or whatever; that's orthogonal to this conversation.

Instead, this document is a list of considerations for implementing a client for using Feature Flags for User Interface development. Service providers usually give a simple fetch and use client and that's it; I contend that there's a lot more to care about. Let's dive in.

To encourage usage, we'd like for the developer experience to be as brutally simple as possible. So, this should be valid usage:

@tannerlinsley
tannerlinsley / README.md
Last active March 27, 2024 10:07
Replacing Create React App with the Next.js CLI

Replacing Create React App with the Next.js CLI

How dare you make a jab at Create React App!?

Firstly, Create React App is good. But it's a very rigid CLI, primarily designed for projects that require very little to no configuration. This makes it great for beginners and simple projects but unfortunately, this means that it's pretty non-extensible. Despite the involvement from big names and a ton of great devs, it has left me wanting a much better developer experience with a lot more polish when it comes to hot reloading, babel configuration, webpack configuration, etc. It's definitely simple and good, but not amazing.

Now, compare that experience to Next.js which for starters has a much larger team behind it provided by a world-class company (Vercel) who are all financially dedicated to making it the best DX you could imagine to build any React application. Next.js is the 💣-diggity. It has amazing docs, great support, can grow with your requirements into SSR or static site generation, etc.

So why

@dhh
dhh / Gemfile
Created June 24, 2020 22:23
HEY's Gemfile
ruby '2.7.1'
gem 'rails', github: 'rails/rails'
gem 'tzinfo-data', '>= 1.2016.7' # Don't rely on OSX/Linux timezone data
# Action Text
gem 'actiontext', github: 'basecamp/actiontext', ref: 'okra'
gem 'okra', github: 'basecamp/okra'
# Drivers
@haproxytechblog
haproxytechblog / haproxy-config-2-0.cfg
Created June 13, 2019 20:41
HAProxy 2.0 configuration
#
# This is the ultimate HAProxy 2.0 "Getting Started" config
# It demonstrates many of the features available which are now available
# While you may not need all of these things, this can serve
# as a reference for your own configurations.
#
# Have questions? Check out our community Slack:
# https://slack.haproxy.org/
#
@mrk21
mrk21 / json_logger.rb
Created June 11, 2019 10:20
JSON logger for Rails
# This logger is having the interface is same to `ActiveSupport::TaggedLogging`.
# @see https://github.com/rails/rails/blob/master/activesupport/lib/active_support/tagged_logging.rb
class JSONLogger < ActiveSupport::Logger
class Formatter < ActiveSupport::Logger::SimpleFormatter
def call severity, timestamp, progname, message
JSON.generate({
type: severity,
time: timestamp.iso8601,
progname: progname,
message: message,
@lleger
lleger / sync-ssh-keys.sh
Created April 4, 2019 18:42
Sync SSH keys from an S3 bucket
#!/bin/sh -e
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-us-west-1}
S3_BUCKET=team-ssh-keys
SSH_USER=${SSH_USER:-ubuntu}
MARKER="# KEYS_BELOW_MANAGED_BY_TEAM_SSH_KEYS"
KEYS_FILE=/home/$SSH_USER/.ssh/authorized_keys
TEMP_KEYS_FILE=$(mktemp /tmp/authorized_keys.XXXXXX)
PUB_KEYS_DIR=/home/$SSH_USER/.ssh/team_ssh_keys