Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@eLafo
eLafo / exceptions.rb
Created July 18, 2014 09:19
Concern exceptions
module Exceptions
extend ActiveSupport::Concern
included do
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, with: :render_error
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
rescue_from ActionController::RoutingError, with: :render_not_found
rescue_from ActionController::UnknownController, with: :render_not_found
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
require 'socket'
require 'gosu'
class GameWindow < Gosu::Window
def initialize
super 640, 480, false
self.caption = "Client"
@image = Gosu::Image.new(self,"headcrab.bmp",false)
@x, @y = get("x"), get("y")
end
@justinweiss
justinweiss / settings.rb
Created May 27, 2014 16:54
Simple settings for Rails
require 'yaml'
require 'erb'
require 'ostruct'
class Settings < OpenStruct
# Settings.new(:google_analytics)
def initialize(config_file_base_name)
super(YAML.load(ERB.new(File.read(Rails.root.join("config", "#{config_file_base_name}.yml"))).result)[Rails.env])
end
@thebucknerlife
thebucknerlife / authentication_with_bcrypt_in_rails_4.md
Last active March 12, 2025 18:03
Simple Authentication in Rail 4 Using Bcrypt

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
#Deploy and rollback on Heroku in staging and production
class RakeHerokuDeployer
def initialize app_env
@app = ENV["#{app_env.to_s.upcase}_APP"]
end
def run_migrations
push; turn_app_off; migrate; restart; turn_app_on; tag;
end
@stephancom
stephancom / stripe_customer.rb
Created March 21, 2014 03:54
Stripe Customer rails concern
# _ _
# __| |_ _ _(_)_ __ ___
# (_-< _| '_| | '_ \/ -_)
# /__/\__|_| |_| .__/\___|
# |_|
# __ _ _ __| |_ ___ _ __ ___ _ _
# / _| || (_-< _/ _ \ ' \/ -_) '_|
# \__|\_,_/__/\__\___/_|_|_\___|_|
#
# (c) 2013 stephan.com
@justinweiss
justinweiss / filterable.rb
Last active January 30, 2025 13:06
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with names based on the keys in <tt>filtering_params</tt>
# with their associated values. For example, "{ status: 'delayed' }" would call
@ggarnier
ggarnier / class_variables.rb
Last active May 12, 2025 01:02
Class variables and class instance variables in Ruby
class Superclass
@@var1 = "var 1 Superclass"
@var2 = "var 2 Superclass"
def self.var1
@@var1
end
def self.var2
@var2