Skip to content

Instantly share code, notes, and snippets.

View ruralocity's full-sized avatar

Aaron Sumner ruralocity

View GitHub Profile
@ruralocity
ruralocity / Dockerfile
Created February 21, 2021 19:59
Initial setup of a VS Code devcontainer for Rails; see https://everydayrails.com/2021/02/21/docker-devcontainer-series-setup.html
# [Choice] Ruby version: 2, 2.7, 2.6, 2.5
ARG VARIANT=2
FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT}
ARG NODE_VERSION="lts/*"
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"
# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>
@ruralocity
ruralocity / starship.toml
Created September 28, 2020 15:15
My current Starship.rs configuration file
# Don't print a new line at the start of the prompt
add_newline = false
# Disables the line_break module, making the prompt a single line.
[line_break]
disabled = true
# Replace the "❯" symbol in the prompt
[character]
symbol = "$"
@ruralocity
ruralocity / vcsh.md
Last active November 13, 2017 18:37
Utility for managing config files via multiple git repositories.

https://github.com/RichiH/vcsh

vcsh init <repo>
vcsh <repo> add <files>
vcsh <repo> commit -m "<message>"

vcsh <repo> remote add origin <remote>
vcsh <repo> push -u origin master
@ruralocity
ruralocity / Thorfile
Last active November 13, 2017 18:23
Hack to automate style guide reviews during pull requests
# Prerequisites:
#
# * Add pronto, pronto-rubocop, and any other pronto runners to Gemfile's
# development group (TODO: how to run using standalone gems?)
# Add dotenv to project's Gemfile, if necessary (dotenv-rails includes
# it by default)
# * Create a GitHub API token: https://github.com/settings/tokens.
# Give it the following scopes: repo, repo:status
# See this tutorial for more info:
# https://christoph.luppri.ch/articles/2017/03/05/how-to-automatically-review-your-prs-for-style-violations-with-pronto-and-rubocop/
@ruralocity
ruralocity / gist:0e74b642579c65282b75
Last active August 29, 2015 14:10
Code Reviews (Alex Gaynor, Hack.Summit() 2014)

Code Review

(Alex Gaynor, Python Software Foundation)

  • reviewing diffs vs. entire body of code: The latter takes the "why" out of the process
  • "raise the bus factor"
  • ensure readability: counterbalances self-optimization we do when we write code
  • catch bugs: least important purpose of code reviews
  • encourage healthy engineering culture: mechanism for giving and getting regular feedback
require 'spec_helper'
describe 'path/to/view.html.erb' do
it "renders JavaScript to connect to a pretend API" do
render
expect(rendered).to match("api_key: '#{ENV['API_KEY']}',")
expect(rendered).to match("api_endpoint: '#{ENV['API_KEY']}',")
end
end
@ruralocity
ruralocity / obfuscate.rake
Last active December 17, 2015 13:10
Simple rake task for obfuscating data, to use in screenshots, demos, etc. See http://everydayrails.com/2013/05/20/obfuscated-data-screenshots.html for context.
if Rails.env.development?
require 'faker'
namespace :obfuscate do
desc "Obfuscate user data"
task :users => :environment do
raise "Not to be run in production!" if Rails.env.production?
User.all.each do |user|
unless user.admin?
user.update_attributes(
@ruralocity
ruralocity / sessions.md
Created May 8, 2013 17:12
Sessions I attended at Railsconf 2013

Monday

  • DHH keynote
  • How Shopify scales Rails
  • Maintainable Templates
  • Building Extractable Libraries in Rails
  • Michael Lopp keynote

Tuesday

@ruralocity
ruralocity / school_year.rb
Created August 2, 2012 03:21
Calculate the date range for the school year for a given date.
require 'date'
require 'minitest/autorun'
class SchoolYear
def self.date_range(day=Date.today.to_s)
d = Date.parse(day)
if d.month >= 8
start_year = d.year
end_year = d.year + 1
else
@ruralocity
ruralocity / share_buttons.rb
Created April 17, 2012 11:20
incomplete, untested at all spaghetti helpers for social media sharing in rails
def facebook_button(url)
content_for :head do
content_tag :script,
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));