Skip to content

Instantly share code, notes, and snippets.

View bwillis's full-sized avatar

Ben bwillis

View GitHub Profile
@bwillis
bwillis / Readme.md
Last active December 25, 2015 00:49
Convert camel case variables to hyphen case. This was useful when upgrading from Bootstrap 2 to 3.

Pass the filename or pipe the contents of the file into the script.

#> ./camel-to-hyphen-case.rb path/to/file.scss > converted_file.scss
@bwillis
bwillis / gist:6710718
Last active December 23, 2015 23:29
Notes for version cake issue

Rails uses a concept called details to find a template using an Action View Resolver (actionpack-3.2.14/lib/action_view/template/resolver.rb). Version Cake registers an additional detail (called versions) to add more granularity when locating a template. The resolver builds a query from the details which is used to search the directory for the templates.

resolver = ActionView::OptimizedFileSystemResolver.new(Rails.root.join("app/views"))
template_name = "tester/index"
details = {:locale => [:en], :formats => [:html], :handlers => [:erb, :builder, :coffee, :jbuilder], :versions => [:v1]}

# without RABL
query = resolver.build_query(template_name, details)
 => ".../app/views/tester/index{.en,}{.v1,}{.html,}{.erb,.builder,.coffee,.jbuilder,}"
@bwillis
bwillis / git_commands.zsh
Last active November 8, 2018 02:28
Git and Github commands I use via .zshrc
# Git commands
# ggh - git url: get the url to the current github repo (assumes it's the remote push server)
# ggbn - git branch name: get the name of the current branch
# ggwip - git wip: commit the current staged and unstaged files with a commit message of WIP
# ggundo - git undo: pull the last commit off as staged changes
# ggbh - git branch history: list the 6 recent branches by commit date
# ggbs - git branch smart history: list the 6 recent branches by commit date without master, staging or production
# ggbl - git branch last: get the last branch that is not master, staging or production
alias ggh="git remote -v 2> /dev/null | grep push | awk '{print \$2}' | sed 's/:/\//' | sed 's/git@\(.*\)\.git/https:\/\/\1/'"
@bwillis
bwillis / top_github_stargazers.rb
Created November 16, 2012 18:47
Retrieve a Github project's Stargazers meta data
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
class GithubStargazers
def initialize(repo)
@repo = repo
@bwillis
bwillis / active_record_monkey_patch.rb
Created March 22, 2012 16:29
Fix unprecise MySQL dates for active record
class ActiveRecord::Base
DATE_FIELDS = [:created_at, :updated_at]
after_save :make_dates_less_precise
def make_dates_less_precise
DATE_FIELDS.each do |date_field|
if respond_to? date_field
time = self.send(date_field)