Skip to content

Instantly share code, notes, and snippets.

View natematykiewicz's full-sized avatar
🚀

Nate Matykiewicz natematykiewicz

🚀
  • Wisconsin, USA
  • 01:19 (UTC -05:00)
View GitHub Profile
@scpike
scpike / incompat_71.rb
Last active February 28, 2024 16:26
Check for silent gem incompatibilities in Rails 7.1
#!/usr/bin/env ruby
# Run like `ruby incompat_71.rb ~/path/to/Gemfile.lock`
# From the team at infield.ai
#
PACKAGES = [['activerecord-import', '1.5.0'],
['anycable-rails', '1.4.1'],
['blazer', '3.0.1'],
['bullet', '7.1.2'],
['data_migrate', '9.2.0'],
['database_cleaner-active_record', '2.1.0'],
@kamilogorek
kamilogorek / _screenshot.md
Last active May 27, 2024 12:50
Clutter-free VS Code Setup
image
@AliOsm
AliOsm / .env
Last active April 17, 2024 17:18
Deploy Rails, GoodJob, PostgreSQL, Redis, Memcached, Meilisearch, and ChromaDB on the same server using Kamal.
KAMAL_REGISTRY_PASSWORD=dckr_pat_xXXxx_x0xXxXx-xX-XXX0xX0x-x
RAILS_MASTER_KEY=00x00xxx000xxx000000xx0x000x0x00
POSTGRES_PASSWORD=xXxxx0xXXx0
MEILI_MASTER_KEY=xXxxx0xXXx0
BLAZER_DATABASE_URL=postgres://service:{POSTGRES_PASSWORD}@service-name-postgres:5432/service_production
import { Controller } from "@hotwired/stimulus"
// use with Rails' `time_Tag` helper like so:
// <%= time_tag campaign.starts_at, campaign.starts_at.to_formatted_s(:short), data: { controller: "localized-time", localized_time_type_value: "datetime-short" } %>
export default class extends Controller {
static targets = [ ]
static values = {
type: String,
style: { type: String, default: 'medium' },
locale: { type: String, default: 'default' },
@bkeepers
bkeepers / flipper.js
Last active February 4, 2024 10:46
Simple Flipper API for your app
// Plain ol' JavaScript module for fetching feature flags from the server
//
// import { isEnabled } from './flipper.js'
//
// if (await isEnabled("new_feature")) {
// // render new feature
// } else {
// // render old feature
// }
//
@jjb
jjb / file.md
Last active May 29, 2024 01:55
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 ; \
@andynu
andynu / show_method_history.rb
Created August 26, 2022 18:56
Given a ruby file and method name shows you all the different versions across the git history.
#!/usr/bin/env ruby
# Given a file and method_name
# Show all the different implementations across the git history (first commit per implementation).
#
# show_method_history <file> <method_name> --html
#
# e.g. show_method_history test/test_helper.rb sign_in --html
#
# WARNING: the --html output just dumps html files into your current folder.
#
@palkan
palkan / README.md
Created January 24, 2022 13:29
Rails boot time profiling

Add the following to application.rb:

$icallbacks = []
$icallbacks.define_singleton_method(:print) do
  puts sort_by { |(a, b)| -b }.map { |(a, b)| "#{b}\t\t#{a}" }.join("\n")
end

ActiveSupport::Notifications.subscribe("load_config_initializer.railties") do |event|
 $icallbacks &lt;&lt; [event.payload[:initializer], event.duration]
@brenogazzola
brenogazzola / custom_active_storage_urls.rb
Last active October 17, 2022 15:34
Creating a custom ActiveStorage controller to generate "pretty urls" or help migration from another lib
# This demonstrates how we create a SEO friendly url for the previews of the artworks we sell.
#
# This is the URL we want:
# https://festalab.com.br/image/invitation/birthday/carnival.jpg
#
# First, the route.
#
# "model" is the name of the active storage model that has the preview.
# "classification" and "identifier" are together a unique key for the records.
@DmitryTsepelev
DmitryTsepelev / change_column_type.rb
Created August 27, 2020 08:46
How to change column type (e.g., int -> bigint) without downtime
ActiveRecord::Migration.remove_foreign_key(:current_table, :foreign_table) # no lock
ActiveRecord::Migration.add_column(:current_table, :column_bigint, :bigint) # no lock
copy_data = lambda do
CurrentTable.where(column_bigint: nil).where.not(column: nil).in_batches do |batch|
batch.update_all("column_bigint = column")
end
end