Skip to content

Instantly share code, notes, and snippets.

View bigfive's full-sized avatar

Jonathan Williams (jdub) bigfive

  • Envato
  • Perth, Australia
View GitHub Profile
@bigfive
bigfive / create_template.rb
Last active December 19, 2015 16:08
Creates a git template dir that will allow all folders that you run 'git init' in will now use a pre-commit hook that forbids commits directly on master and staging
#!/usr/bin/env ruby
def add_new_git_template
# Paths
home_dir = File.expand_path('~')
template_dir = File.join(home_dir, ".git_template")
hooks_dir = File.join(template_dir, "/hooks")
pre_commit_file = File.join(hooks_dir, "pre-commit")
@bigfive
bigfive / change_viewport_meta.js
Created December 11, 2012 08:36
Change viewport initial scale and width depending on device width
changeViewportMeta = function() {
$('meta[name=viewport]').attr('content', 'user-scalable=yes, initial-scale=1, maximum-scale=1.3, width=device-width');
if ($(window).width() <= 320) {
return $('meta[name=viewport]').attr('content', 'user-scalable=yes, initial-scale=0.63, maximum-scale=1.3, width=480');
} else if ($(window).width() <= 480) {
return $('meta[name=viewport]').attr('content', 'user-scalable=yes, initial-scale=0.89, maximum-scale=1.3, width=480');
} else if ($(window).width() <= 768) {
return $('meta[name=viewport]').attr('content', 'user-scalable=yes, initial-scale=0.8, maximum-scale=1.3, width=920');
} else if ($(window).width() <= 1024) {
return $('meta[name=viewport]').attr('content', 'user-scalable=yes, initial-scale=0.85, maximum-scale=1.3, width=920');
@bigfive
bigfive / 20120118012543_create_site_configuration.rb
Created January 20, 2012 02:01
Ruby on Rails. Key value table for site configuration integrated with Active admin and formtastic forms
# db/migrations/20120118012543_create_site_configuration.rb
class CreateSiteConfigurations < ActiveRecord::Migration
def change
create_table :site_configurations do |t|
t.string :key
t.text :value
t.string :form_type
t.string :form_collection_command
@bigfive
bigfive / gist:1399762
Created November 28, 2011 09:33
Ruby on Rails. Module to handle 'quantity' attributes by overriding the << and delete methods of the has_many association
class Package < ActiveRecord::Base
has_many :products, :through => :packagings, extend => QuantityAssociation
# ... do stuff
end
module QuantityAssociation
def include_duplicates