Skip to content

Instantly share code, notes, and snippets.

View BrianSigafoos's full-sized avatar

Brian Sigafoos BrianSigafoos

View GitHub Profile
@BrianSigafoos
BrianSigafoos / rails_generators.md
Last active September 26, 2017 21:50
Rails generators

Rails Generators

rails generate <type> --help # for examples

# Model (+ migration, test, fixtures)
rails generate model NAME [field[:type][:index] field[:type][:index]] [options]

rails generate model post title:string blog:references published:boolean position:integer
rails generate model product supplier:references{polymorphic}
@BrianSigafoos
BrianSigafoos / metaprogramming.md
Last active March 8, 2023 14:43
Metaprogramming in Ruby

Dynamic Method

# Decide how to define a method at runtime
class C
end

C.class_eval do
  define_method :my_method do
    'a dynamic method'
 end
@BrianSigafoos
BrianSigafoos / testing.md
Last active August 17, 2017 20:14
Testing syntax, using Shoulda matchers

Fixtures

DEFAULTS: &DEFAULTS
  payment_trail:      $LABEL
  identifier:         $LABEL_stripe_key
  amount_cents:       <%= AMOUNT_CENTS[:one_h] %>
  paid:               false
  status:             <%= Charge::STATUSES[0] %>
  state:              <%= Charge::STATES[0] %>
  created_at:         now  # special `now` or can use <%= 1.week.from_now %>
@BrianSigafoos
BrianSigafoos / rails_setup.md
Last active August 26, 2017 14:54
Rails setup notes

Rails + React + PostgreSQL on Heroku

$ rails new <app-name> --database=postgresql --webpack=react
$ cd <app-name>
$ echo '.idea' >> .gitignore      # remove RubyMine's config
$ echo "ruby '2.4.0'" >> Gemfile  # for Heroku Ruby version
$ git add .
$ git commit -m "Initial commit"

# Create new repo on GitHub with same name...
@BrianSigafoos
BrianSigafoos / Gemfile.md
Last active August 16, 2017 16:26
Rails favorites - for faster app setup

Gemfile favorites

group :test do
  # Minitest - Rails default, but updated more often via gem https://github.com/seattlerb/minitest
  gem 'minitest'

  # Better reporting for minitiest - ala Rspec https://github.com/kern/minitest-reporters
  gem 'minitest-reporters'
@BrianSigafoos
BrianSigafoos / postgres-cheatsheet.md
Created January 25, 2017 17:38 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@BrianSigafoos
BrianSigafoos / ssl_puma.sh
Created January 13, 2017 17:35 — forked from tadast/ssl_puma.sh
localhost SSL with puma
# 1) Create your private key (any password will do, we remove it below)
$ cd ~/.ssh
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@BrianSigafoos
BrianSigafoos / rubymine.vmoptions
Created January 12, 2016 20:20
RubyMine increase memory heap size - rubymine.vmoptions
# Put this file in your /Users/<your_username>/Library/Preferences/<rubymine_version>/rubymine.vmoptions
# Ex: /Users/bob/Library/Preferences/RubyMine80/rubymine.vmoptions
-Xms128m
-Xmx1536m
-XX:MaxPermSize=250m
-XX:+UseCompressedOops
@BrianSigafoos
BrianSigafoos / aws_s3_set_cache_control_max-age.rb
Last active August 29, 2015 14:24 — forked from rahul100885/s3_header.rb
AWS S3 Cache Control Max-Age
#!/usr/bin/env ruby
require 'rubygems'
require 'aws-sdk'
s3 = AWS::S3.new(
:access_key_id => 'PASTE_HERE',
#### SECRET KEY #####
:secret_access_key => 'PASTE_SECRET_KEY_HERE')
#### DO NOT COMMIT ####