Skip to content

Instantly share code, notes, and snippets.

@hopsoft
hopsoft / db.rake
Last active February 5, 2025 13:23
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@philoye
philoye / heartbeat.rb
Created August 11, 2014 00:49
Simple rack middleware to provide a health monitor for rails app using sidekiq, memcache, and activerecord.
module Rack
class Heartbeat
def initialize(app)
@app = app
end
def call(env)
if env['PATH_INFO'] == "/pulse"
@messages = []
require 'rails_helper'
RSpec.describe TodosController, :type => :controller do
describe "GET #index" do
#describe "POST #create" do
#describe "GET #show" do
#describe "PATCH #update" do (or PUT #update)
#describe "DELETE #destroy" do
#describe "GET #new" do
@pdougall1
pdougall1 / gist:451e723c59c44e45e02a
Last active November 3, 2015 20:16
POODR class notes

Notes and observations

  • The next one to prove the first is wrong
  • Choose a name inline with the concept in the domain.
    • Good OO code names concepts, not worried about implementation
  • Terseness is cleverness (not goodness), stop picking on each other for being simple.
  • Smallest change you can make to prove the last test insuficient.
  • Solve the easy problems first, then maybe the hard ones become easy.
  • DRY is good, but sometimes duplication makes sense, if it passes the inebriation test, check it in and walk away
  • Open/Close Add new features without adding new code
  • lean on the green
@pdougall1
pdougall1 / gist:e79fee71e3997fe13f09
Last active November 3, 2015 20:16
POODR class notes (day 2)

Code smells, get really good at code smell (brown bag)

All you have to know is the codes smells

make a million new things > mutate objects

Forwardable (delegation)

Don't go on a virtical tangent, instead tiptoe away and finish the horizontal refactor

@elle
elle / 2015-poodnyc-notes.md
Last active September 12, 2021 11:05
Notes from Poodnyc 2015 workshop

Rules for Horizontal Refactoring

  • If you go red, undo
  • Only change one line at a time
  1. Find two strings that are the most alike
  2. Find the smallest difference
  3. Make the smallest change that make the tests pass

How to make a small change

@pdougall1
pdougall1 / gist:a8b1206758aab172509c
Created November 9, 2015 00:24
refactoring flow
╔═════════════════╗ ┌─────┐ ╔═══════════════════╗
║ ║ │ YES │ ║ Make the intended ║
───────▶║ Is it open? ╠──┴─────┴──────▶║ change. ║
▲ ║ ║ ▲ ║ ║
│ ╚═════════╦═══════╝ │ ╚═══════════════════╝
│ │ │
│ ┌────┤ │
│ │ NO │ │
│ └────┤ │
│ │ │
@chrismccord
chrismccord / upgrade.md
Last active April 7, 2023 12:03
Phoenix 1.2.x to 1.3.0 Upgrade Instructions

If you want a run-down of the 1.3 changes and the design decisions behidn those changes, check out the LonestarElixir Phoenix 1.3 keynote: https://www.youtube.com/watch?v=tMO28ar0lW8

To use the new phx.new project generator, you can install the archive with the following command:

$ mix archive.install https://github.com/phoenixframework/archives/raw/master/phx_new.ez

Bump your phoenix dep

Phoenix v1.3.0 is a backwards compatible release with v1.2.x. To upgrade your existing 1.2.x project, simply bump your phoenix dependency in mix.exs:

@radar
radar / Exam.md
Last active August 7, 2018 02:20

JEP Exam Rubric

  • Gemfile entries
    • rubocop (under development)
    • rspec-rails (under development + test)
    • devise (outside of any group)
    • mongoid (outside of any group)
  • Generated Mongoid configuration present at config/mongoid.yml
  • Rubocop rules pass
  • db/seeds.rb
    • Creates a book
@eebs
eebs / sql_statement_profiling.rb
Created December 17, 2019 21:29
spec/support/sql_statement_profiling.rb
RSpec.configure do |config|
example_sql_counts = Hash.new(0)
config.around(:example) do |procsy|
sql_count = 0
callback = ->(*args) { sql_count +=1 }
ActiveSupport::Notifications.subscribed(callback, "sql.active_record") do
procsy.call
end