Skip to content

Instantly share code, notes, and snippets.

require "rails_helper"
# https://mvaragnat.medium.com/rails-6-and-rspec-how-to-test-zeitwerk-mode-81782b6d3388
describe "Zeitwerk" do
it "eager loads all files" do
# like running `bin/rails zeitwerk:check`
expect { Zeitwerk::Loader.eager_load_all }.not_to raise_error
end
end
@mpvosseller
mpvosseller / loadAppEnv.js
Last active April 26, 2023 21:06
Add support to Next.js for multiple "app environments" .env files (development, preview, staging, production)
// loadAppEnv.js
const fs = require('fs')
const dotenvFlow = require('dotenv-flow')
// This module loads .env files from the config/ directory based the "app
// environment" that it is being built for or is running in (e.g. development,
// preview, staging, beta, canary, production, etc..). The "app environment"
// is determined by APP_ENV (if defined) or NODE_ENV. It exports a set of
// environment variables which should be passed to Next.js as the env config.
//
@mpvosseller
mpvosseller / create_heroku_app.rb
Last active January 2, 2023 19:34
Ruby function to create a new Heroku app with the Heroku Platform API
# Function to create a new Heroku app instance using the ruby Heroku Platform API
#
# Documentation:
# https://devcenter.heroku.com/articles/setting-up-apps-using-the-heroku-platform-api
# https://devcenter.heroku.com/articles/platform-api-reference#app-setup
# https://github.com/heroku/platform-api
# https://heroku.github.io/platform-api
#
# Add the gem 'platform-api'
require "platform-api"
@mpvosseller
mpvosseller / txt-preview.zsh
Created November 26, 2021 13:27
txt-preview - function to open text from stardard-input in Preview
## function to open text from stardard-input in Preview
## inspired by the `man-preview` function of Oh My Zsh that opens any man page in Preview https://github.com/ohmyzsh/ohmyzsh/blob/b60b3f184275c39800dd7284d6904fcf295b3956/plugins/macos/macos.plugin.zsh#L221
## requires enscript: `brew install enscript`
## example usage:
## echo "hello world" | txt-preview
function txt-preview() {
enscript -q -B -p- | open -f -a Preview
}
@mpvosseller
mpvosseller / UnknownMaybe.ts
Created May 3, 2021 02:10
UnknownMaybe: utility type that treats an object as "unknown but might be of type T"
// utility type that treats an object as "unknown but might be of type T"
// allows you to access each property that T has but assumes the value is `unknown | undefined`
// this lets you test the values of each property to determine if it is in fact a T
// autocomplete and refactoring the property names work
// you get a compiler error if you try to access a property not in T
type UnknownMaybe<T> = {
[P in keyof T]?: T[P] extends object ? UnknownMaybe<T[P]> : unknown
}
interface Message {
@mpvosseller
mpvosseller / focus.sh
Last active September 25, 2020 15:22
shell aliases to temporarily block and unblock a set of hostnames to better focus
# add to your shell startup file (e.g. ~/.zshrc or ~/.bash_profile)
export FOCUS_IGNORE_SITES="twitter.com api.twitter.com www.facebook.com www.nytimes.com"
alias focus='sudo echo "127.0.0.1 ${FOCUS_IGNORE_SITES} # FOCUS_IGNORE_SITES" | sudo tee -a /etc/hosts > /dev/null'
alias unfocus="sudo sed -i '' '/FOCUS_IGNORE_SITES/d' /etc/hosts"
@mpvosseller
mpvosseller / gist:5749ad19d046cf14ebf24c837665dc25
Created May 28, 2018 14:59
Use Slack reminders to improve timely attendance
/remind #general "Team meeting starts in 15 minutes https://meet.google.com/XXXXXXX" at 10:45AM every Monday
/remind #general "Team meeting starts in 5 minutes https://meet.google.com/XXXXXXX" at 10:55AM every Monday
/remind #general "Team meeting starts in 1 minute https://meet.google.com/XXXXXXX" at 10:59AM every Monday
@mpvosseller
mpvosseller / example.swift
Last active February 28, 2018 19:53
When implementing a protocol property that returns an optional value you must explicitly declare the type (as an optional) in your implementation. See below comment for details.
protocol MyProtocol {
var name: String? { get }
}
extension MyProtocol {
var name: String? {
return "aDefaultName"
}
}
@mpvosseller
mpvosseller / make-ios-icons
Created February 12, 2018 18:31
Given a 1024x1024 iOS app icon this script creates all the other requires sizes
#!/bin/sh
convert Icon-1024.png -resize 20x20 Icon-20.png
convert Icon-1024.png -resize 40x40 Icon-20@2x.png
convert Icon-1024.png -resize 60x60 Icon-20@3x.png
convert Icon-1024.png -resize 29x29 Icon-29.png
convert Icon-1024.png -resize 58x58 Icon-29@2x.png
convert Icon-1024.png -resize 87x87 Icon-29@3x.png
convert Icon-1024.png -resize 40x40 Icon-40.png
convert Icon-1024.png -resize 80x80 Icon-40@2x.png
convert Icon-1024.png -resize 76x76 Icon-76.png
@mpvosseller
mpvosseller / gist:8897b379f040e0ca1476
Created January 20, 2016 04:25
Xcode Build Phase Run Script to Disable AppTransportSecurity in DEBUG Simulator Builds
#!/bin/sh
## Disable AppTransportSecurity in DEBUG Simulator Builds
if [[ ${CONFIGURATION} == "Debug" ]] && [[ $PLATFORM_NAME == *"simulator"* ]]; then
TARGET_INFOPLIST="${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"
## Delete NSAppTransportSecurity entry if it already exists
/usr/libexec/PlistBuddy -c "Delete :NSAppTransportSecurity" "${TARGET_INFOPLIST}" 2>/dev/null