Skip to content

Instantly share code, notes, and snippets.

View kvzb's full-sized avatar

Kevin Vanzandberghe kvzb

View GitHub Profile
@kvzb
kvzb / range.rb
Created February 25, 2013 13:55
Comparing two ranges for intersections. Returns a Range if they intersect, or nil.
class Range
def intersection(other)
return nil if (self.max < other.begin or other.max < self.begin)
[self.begin, other.begin].max..[self.max, other.max].min
end
alias_method :&, :intersection
end
@kvzb
kvzb / bootstrap.sh
Created April 18, 2014 13:00
Quasi-generic Rails app bootstrapping script.
#!/bin/bash
bold=`tput bold`
normal=`tput sgr0`
Bold() { echo "${bold}---> $1${normal}"; }
Tab() { echo " $1"; }
Done() { Tab "Done."; }
# Target Ruby version.
@kvzb
kvzb / application_controller.rb
Created July 17, 2014 14:24
In Ruby 2.1, methods return a symbol representing the method name. You can do cool stuff with it.
class ApplicationController < ActionController::Base
helper_method def current_user
@current_user ||= User.find(token: params[:token])
end
end
@kvzb
kvzb / gems.txt
Created September 5, 2014 14:59
Common gems to be pre-installed on all projects.
rails
bourbon
carrierwave
coffee-rails
delayed_job
delayed_job_active_rexcord
devise
dotenv
dotenv-deployment
@kvzb
kvzb / environment_inquirer.rb
Last active August 29, 2015 14:08
A way to eliminate rails env lookup duplication.
module Rails
STABLE_ENVIRONMENTS = %w(staging production)
def stable_env?
STABLE_ENVIRONMENTS.include? Rails.env
end
module_function :stable_env?
def unstable_env?
@kvzb
kvzb / gist:d3c2543327f8c8dce11d
Created December 12, 2014 10:30
Nokogiri 1.6.3.1 without headaches.
gem install nokogiri -v '1.6.3.1' -- --with-xml2-include=/opt/boxen/homebrew/Cellar/libxml2/2.9.2/include/libxml2/ --with-xml2-lib=/opt/boxen/homebrew/Cellar/libxml2/2.9.2/lib/ --with-xslt-dir=/opt/boxen/homebrew/Cellar/Cellar/libxslt/1.1.28/ --with-iconv-dir=/opt/boxen/homebrew/Cellar/libiconv/1.14/
@kvzb
kvzb / libraries.md
Created March 20, 2019 15:39
Libraries & tools.

Non-exhaustive list of third-party libraries I use on most projects, including Lexic.

Backend (Ruby/Rails)

  • Counter culture: improvements over the standard counter cache behavior in Rails.
  • Devise: one-stop show for user authentication, verification, password reset, etc.
  • Discard: non-intrusive soft-delete for ActiveRecord models.
  • Goldiloader: automagic eager-loading for ActiveRecord queries (conditions may apply).
  • GraphQL Ruby: GraphQL server for Ruby apps.
  • Groupdate: easily query AR objects by date or time (with timezone support).
@kvzb
kvzb / Procfile.dev
Created August 14, 2024 21:18
Solo Rails #3: Front-end stack config.
web: bin/rails server -p 3000
css: bun run build:css --watch
js: bun run build --watch
jobs: bundle exec good_job start