Skip to content

Instantly share code, notes, and snippets.

View wrburgess's full-sized avatar
:shipit:
Shippin'

Randy Burgess wrburgess

:shipit:
Shippin'
View GitHub Profile
@wrburgess
wrburgess / intro_to_the_console.md
Last active December 26, 2019 05:12
Intro to the Console

Intro to the Console for Randy

  • cd (changes directory)

  • cd ~ (changes to home directory)

  • cd .. (moves up one directory)

  • ls (lists files in folder)

@wrburgess
wrburgess / *rail_static_assets_on_heroku_cedar.md
Created December 10, 2016 21:14 — forked from bensheldon/*rail_static_assets_on_heroku_cedar.md
Serving Rails Static Assets on Heroku using a CDN with gzip and cache control

Optimizing Rails Static Assets on Heroku Cedar

Serving Rails static assets is hard, especially on Heroku Cedar where Heroku forces Rails to serve static assets itself (which isn't particularly performant nor worth your dyno-dollar)---this is different than Heroku Bamboo which used Varnish and is no more. To make the best of the situation, I highly recomend:

  1. Using the Heroku-Deflater gem which will selectively gzips assets (it gzips text-based files; and excludes images or binary files, which can actually be bigger when gzipped)

  2. Configure your production environment to set cache-control headers and get out of denial about how static assets are being served on Heroku Cedar

  3. Use AWS Cloudfront (or a CDN of your choosing) to serve the assets. Cloudfront is great because you can use the same Distribution

@wrburgess
wrburgess / rspec_rails_cheetsheet.rb
Created December 4, 2016 23:31 — forked from them0nk/rspec_rails_cheetsheet.rb
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@wrburgess
wrburgess / example_job.rb
Last active April 6, 2020 20:17
ActiveJob on Rails 5 with RSpec
# app/jobs/example_job.rb
class ExampleJob < ActiveJob::Base
queue_as :default
rescue_from(ActiveRecord::RecordNotFound) do
retry_job wait: 1.minute, queue: :default
end
def perform(param_1, param_2)
@wrburgess
wrburgess / README.md
Last active December 4, 2016 22:56
Pundit in Rails 5 setup with rspec

Notes

  • This is a simple example of setting up Pundit with a standard and headless policy system.
  • The static_controller is simply a controller that lacks a model and renders static pages, such as a home page, about page, etc.
  • The secure action is just a fill-in example for a page the needs to be secure, it doesn't actually represent a common use case (i.e. you don't need a page called "secure" on a website)

Refs

@wrburgess
wrburgess / 1_add_activable_fields_to_model.rb
Last active March 19, 2018 00:01
Activatable concern for Rails 5
class AddActivatableFieldsToModel < ActiveRecord::Migration[5.0]
def change
add_column :users, :archived, default: false
add_column :users, :test, default: false
add_column :users, :dummy, default: false
add_index :users, :archived
end
end
@wrburgess
wrburgess / 1_add_roles_to_user_model.rb
Last active December 3, 2016 19:22
Using Modules for Model Instance Type Management with Specs in Rails 5
class AddRolesToUserModel < ActiveRecord::Migration[5.0]
def change
add_column :users, :roles, :text, array: true, default: []
end
end
@wrburgess
wrburgess / 1_initial_migration.rb
Last active December 7, 2023 14:14
Setting up UUID columns for Rails 5+ models utilizing Postgres 9.4+
class InitialMigration < ActiveRecord::Migration[5.0]
def change
enable_extension "pgcrypto" unless extension_enabled?("pgcrypto")
end
end
@wrburgess
wrburgess / getty_api_and_keywords.md
Last active October 15, 2016 03:13
Keyword Issue with Getty Contributions

Using the "dueling" keyword as an example (from the Getty keywords resource):

{:term=>"dueling", :term_id=>"15115081"}

I am trying to update an existing contribution with the dueling keyword like this:

{:file_name=>"3_312032_1.mov",
 :external_file_location=>"https://s3.amazonaws.com/wpa-getty-assets/3_312032_1.mov",
 :headline=>"Gun Fight in the Old West",
@wrburgess
wrburgess / all_s3_objects.rb
Created September 21, 2016 02:30 — forked from brianhempel/all_s3_objects.rb
List/fetch all objects in a bucket with AWS::S3 Ruby gem
# by default you only get 1000 objects at a time
# so you have to roll your own cursor
S3.connect!
objects = []
last_key = nil
begin
new_objects = AWS::S3::Bucket.objects(bucket_name, :marker => last_key)
objects += new_objects