Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
#/ Usage: clean-merged-branches
#/ Delete locally merged branches
set -e
# show usage maybe
[ "$1" = "--help" ] && {
grep '^#/' <"$0"| cut -c4-
exit 0
@palkan
palkan / gist:d89757a90cfbeb047c63
Last active October 22, 2023 23:16
Rails debug cheat sheet

Setup

Replace IRB with Pry (in your Gemfile) and Byebug with pry-byebug.

gem 'pry-rails', group: [:development, :test]
gem 'pry-byebug', group: [:development, :test]

Using PRY

module Concerns::Paranoid
extend ActiveSupport::Concern
included do
scope :alive, -> { where deleted_at: nil }
scope :dead, -> { where.not deleted_at: nil }
instance_method(:destroy).tap do |destroy_method|
undef destroy
define_method(:delete_forever, destroy_method)
@danmayer
danmayer / gem_updated
Created July 3, 2014 20:20
gem update in progress
GEM_NAME = "ls-secure_gmaps"
COMMIT_MESSAGE = "update to latest ls-secure_gmaps\n This makes sure all calls are made with the correct keys for our new contract"
APPS = ["browse", "browse-service", "escapes", "events", "preferences", "sponsors"]
CMDS = ["git pull origin master",
"bundle install",
"bundle exec rake",
"bundle update #{GEM_NAME}",
"bundle exec rake",
@sarahmei
sarahmei / gist:3650927
Created September 6, 2012 03:43
The Insufficiency of Good Design
The Insufficiency of Good Design
We all want to write good code, and there is no shortage of advice on
how to do that. SOLID. SOA. SRP. LoD. These are undoubtedly important,
but none of them address the single factor that has the biggest impact
on the quality of a codebase.
That factor is Other People. The people you're working with affect the
codebase more than you do, in aggregate, if there's more than a few of
them. And it's not just the individuals. How your team is organized,
@davidjrice
davidjrice / heroku_env_clone.rake
Created March 10, 2012 19:43
Clone heroku environment variables to a .env file for foreman
desc "Clone heroku environment variables to a .env file for foreman'"
namespace :heroku do
namespace :env do
task :clone => :environment do
ignore_list = [
"DATABASE_URL",
"GEM_PATH",
"LANG",
"LOG_LEVEL",
"PATH",
@adelcambre
adelcambre / portland.md
Last active March 23, 2017 02:37
My Portland recomendations

Food to Not be missed in Portland

The "I go every time I'm there" category

  • Baan Thai - Small hole in the wall on the College campus, pretty much the best Thai Food I have found
  • Biwa - Awesome Japanese Izakaya place. I love this place so much and the owner Gabe is super nice. Get the Ramen unless it's about a million degrees. The Kara age is amazing too.
  • Bailey's Best beer spot in Portland. 20 rotating taps (almost) always from the west coast and mostly local to Portland. They never replace the a keg with the same beer so it's always a different lineup. Geoff and Michael know their shit so you can always ask for advice.
  • Bunk Sandwiches Some of the best sandwiches I've had. The pork belly bahn mi is to die for if they have it. They have a sister place called bunk bar that's open for dinner too, but I'm partial to the lunch only original.

Validations

Data integrity is an underrated part of proper application architecture. Many of the bugs in production systems are triggered by missing or malformed user data. If a user can possibly screw it up or screw with it, they will. Validations in the model can help!

On Syntax

Before we begin, let's talk about syntax. There are two primary syntaxes for writing validations in Rails 3:

validates_presence_of :price
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")