Skip to content

Instantly share code, notes, and snippets.

View jaydorsey's full-sized avatar
💊
Ruby on Rails

Jay Dorsey jaydorsey

💊
Ruby on Rails
View GitHub Profile
@jaydorsey
jaydorsey / gist:fbd6d569b702ce9fbe10c806fefe2eb3
Created August 12, 2022 03:05
Examples of gem/bundle install w/ cflags
# these are examples; maybe not the right flags
gem install ffi -v '1.12.2' -- -- with-cflags="-Wno-error=implicit-function-declaration"
bundle config build.ffi --with-cflags=\"-Wno-error=implicit-function-declaration\"
@jaydorsey
jaydorsey / unused.md
Created July 20, 2022 13:11
Finding unused code in ruby and ruby on rails projects

This is a strategy I use to find unused code in ruby projects. These instructions are for macOS, but you only need access to the tools for this to work.

  1. Install unused following the instructions here
  2. Install universal-ctags. I use the brew instructions here
  3. Generate your tag file from your project root, including your library methods as well. I typically run /usr/local/bin/ctags . $(bundle list --paths) to add all of my library methods for the project. This has some other benefits, like allowing code-jumping in vim

    Bonus: You can set this command up as a git hook to run every time you make changes to your code locally. I have an example of this here

  4. Once this command is done, you can look at the tags file in your repository root to make sure it's populated with data correctly (`cat tags | w
@jaydorsey
jaydorsey / integration.yml
Created June 7, 2022 18:17
Using hurl.dev for integration tests
---
name: Run Integration Tests
on: [workflow_dispatch]
# .github/workflows/integration.yml
#
# You manually trigger this from your Github actions. Maybe after merging to main, and triggering
# a deploy out to your pre-production environment
#
@jaydorsey
jaydorsey / heroku_secret_inventory.rb
Created June 2, 2022 14:59
Heroku secret inventory
# frozen_string_literal: true
# This script uses the platform-api gem to retrieve secrets from Heroku apps, pipelines, and test
# environments. This can be used to generate an inventory of all your secrets, so you can cross-reference
# it to determine if you had any pipeline/test secrets which were compromised as part of the recent
# Heroku breach
#
# I suggest importing these CSVs into a database, adding a couple metadata fields (compromised:boolean,
# notes:text, environment:string, status:string) and writing some SQL to come up with a list of secrets
# that were re-used across different environments
@jaydorsey
jaydorsey / 20211227213338_create_users.rb
Last active December 27, 2021 22:17
Converting a boolean column to an enum in ActiveRecord/Rails
# frozen_string_literal: true
# db/migrate/20211227213338_create_users.rb
#
# This is an example of what the Users table might have been created as
# or would look like before the migration from a boolean field to an enum
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :name, null: false
@jaydorsey
jaydorsey / disable_github_list.js
Last active August 24, 2021 07:21
Tampermonkey script to sisable the Github automatic list completion behavior
// ==UserScript==
// @name Disable Github List Completion
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Disables the behavior described in https://github.blog/changelog/2020-12-15-markdown-list-syntax-now-autocompleted/
// @author Jay Dorsey
// @match https://*.github.com/*
// @grant window.focus
// ==/UserScript==
@jaydorsey
jaydorsey / s3_uploader.rb
Last active May 27, 2021 12:52
AWS S3 uploader
require "aws-sdk-s3"
# Original source: https://gist.github.com/fleveque/816dba802527eada56ab
#
# This version is for the newer aws-s3-sdk v3
#
# You need to require some of the components, at least this one from what I remember:
require 'aws-sdk-s3'
# Upload a folder of files as public files, to S3, using threads. Useful for
# pushing assets compiledi in a rails app on S3, so you can front them with cloudfront.
@jaydorsey
jaydorsey / build_crystal.sh
Last active April 13, 2021 03:10
Build crystal
# Sources:
#
# https://github.com/crystal-lang/crystal/issues/10066
# https://github.com/crystal-lang/crystal/pull/10348#issue-564769672
#
# Usage:
#
# - Follow the instructions here to install ibrew: https://soffes.blog/homebrew-on-apple-silicon
# - brew install gmp libevent libyaml openssl@1.1 pcre pkg-config libatomic_ops llvm
# - brew unlink bdw-gc
@jaydorsey
jaydorsey / custom_errors.rb
Last active April 2, 2021 21:43
Customer errors with an argument
# Custom errors with arguments
#
# Example usage:
#
# ENV.fetch('BLAH') { raise EnvironmentError.new('BLAH') }
class EnvironmentError < StandardError
attr_reader :key
def initialize(key)
@key = key
@jaydorsey
jaydorsey / aws_upload.rb
Created November 19, 2020 13:40
Upload file to S3 using the aws-sdk-s3 v3
require 'aws-sdk-s3'
# Creds get picked up from ENV vars per AWS docs
resource = Aws::S3::Resource.new(region: 'us-east-1')
bucket = resource.bucket('my-bucket')
bucket.put_object(
key: 'foo.gif',
body: File.read('foo.gif'),
acl: 'public-read'
)