Skip to content

Instantly share code, notes, and snippets.

View brand-it's full-sized avatar

Brandt Lareau brand-it

View GitHub Profile
@brand-it
brand-it / application_controller.rb
Created April 1, 2010 03:00
It is a creative way to create access levels for the admin and any other type of users. Very scalable.
# Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
# Make sure that all the methods that redirect are handled in the controllers.
class ApplicationController < ActionController::Base
include AuthenticatedSystem
include Userstamp
include ExceptionLoggable
local_addresses.clear
@brand-it
brand-it / rubocop_pre_commit_hook
Last active July 21, 2020 15:50 — forked from mpeteuil/rubocop_pre_commit_hook
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'json'
def files
@files ||= begin
`git diff --staged --name-only --cached`.split("\n").reject do |file|
!File.exists?(file)
end
end
@statico
statico / gist:3172711
Created July 24, 2012 21:15
How to use a PS3 controller on Mac OS X 10.7 (Lion)

How to use a PS3 controller on Mac OS X 10.7 (Lion)

  1. Open Apple menu -> System Preferences -> Bluetooth and disable Bluetooth on Mac as well as any other nearby Macs or devices which will try to pair with and confuse the controller.

  2. Reset PS3 controller by inserting paperclip into pinhole near L2 button.

  3. Connect PS3 controller to Mac with USB cable.

  4. Enable Bluetooth.

@mpeteuil
mpeteuil / rubocop_pre_commit_hook
Created August 3, 2013 17:44
Ruby style guide git pre-commit hook using Rubocop as the style guide checker. Only runs on staged ruby files that have been added and/or modified.
#!/usr/bin/env ruby
require 'english'
require 'rubocop'
ADDED_OR_MODIFIED = /A|AM|^M/.freeze
changed_files = `git status --porcelain`.split(/\n/).
select { |file_name_with_status|
file_name_with_status =~ ADDED_OR_MODIFIED
@brand-it
brand-it / create_ssl.sh
Last active June 9, 2022 16:05
This build tinderbox ssl certs for local development. Can be used for other things but. Also designed to add it to Mac credentials
#!/usr/bin/env ruby
require 'fileutils'
require 'tempfile'
# cn = '*.tb.local.vhost'
# server_name = 'dev.tb.local.vhost'
# admin_server_name = 'admin.tb.local.vhost'
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'net/http'
require 'open-uri'
require 'tempfile'
require File.expand_path('ruby_bash', __dir__).to_s
options = {}
def format_as_table(header, data)
total_columns = data.first.size
data.insert(0, header) if header
column_widths = total_columns.times.map { |col| data.map { |row| row[col].size }.max }
if header
data.insert(1, Array.new(total_columns, '-').zip(column_widths).map { |a, b| a * b })
end
data.map do |row|
row.zip(column_widths).map do |cell, width|
cell.to_s.ljust(width)
@brand-it
brand-it / install
Last active September 7, 2022 16:25
A simple tool to run rubocop on files you have changed
echo "Creating $(git rev-parse --git-dir)/hooks/pre-commit.d"
mkdir $(git rev-parse --git-dir)/hooks/pre-commit.d
echo "Downloading rubocop hook into $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop"
wget -O $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop https://gist.githubusercontent.com/brand-it/93d04c839238283e3e756811b9c9cee0/raw/616bf812b58bcefc52d564ed8abacbf30966193c/pre-commit.d_rubocop
echo "Changing rubocop into a executable $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop"
chmod 755 $(git rev-parse --git-dir)/hooks/pre-commit.d/rubocop
echo "adding hooks_directory variable to $(git rev-parse --git-dir)/hooks/pre-commit if it does not already exist"
grep -qxF 'hooks_directory=$(git rev-parse --git-dir)/hooks/pre-commit.d' $(git rev-parse --git-dir)/hooks/pre-commit || echo 'hooks_directory=$(git rev-parse --git-dir)/hooks/pre-commit.d' >> $(git rev-parse --git-dir)/hooks/pre-commit
echo "adding $hooks_directory/rubocop variable to $(git rev-parse --git-dir)/hooks/pre-commit if it do
@brand-it
brand-it / .irbrc
Last active November 7, 2023 06:39
.irbrc with a bunch of stuff I found useful. This is all sort of hacky but that kinda of the point. Do what you want take what you need. no need to be perfect
# frozen_string_literal: true
MAX_COLUMNS_FOR_TABLE = 15 unless defined?(MAX_COLUMNS_FOR_TABLE)
DEFAULT_EDITOR = 'code' unless defined?(DEFAULT_EDITOR)
class PrettyString < String
# https://no-color.org/
NO_COLOR = ENV.key?('NO_COLOR') || `tput colors`.chomp.to_i < 8 unless defined?(NO_COLOR)
unless defined?(ANSI_COLORS)
ANSI_COLORS = {
red: 31,
@maxivak
maxivak / __readme.md
Last active January 19, 2024 15:00
Load code in libraries in Rails 5

Load lib files in production (Rails 5)

If you have your code defined in classes in lib/ folder you may have problems to load that code in production.

Autoloading is disabled in the production environment by default because of thread safety.

Change config/application.rb:

    config.autoload_paths << Rails.root.join("lib")
 config.eager_load_paths &lt;&lt; Rails.root.join("lib")