Skip to content

Instantly share code, notes, and snippets.

View kirkbushell's full-sized avatar

Kirk Bushell kirkbushell

  • Tectonic Digital
  • Sydney
View GitHub Profile
@kirkbushell
kirkbushell / filters.js
Created May 28, 2013 04:11
Default value filter for Angular JS applications - allows you to output a variable, and assign it a default value if it has a value of 0, null, or is an empty string. Very similar to PHP's empty() function, but provides a default value instead of a boolean.
/**
* Sets a default value for a given input.
*
* @param mixed input
* @param string defaultValue
* @return string
*/
module.filter( 'default', [ '$filter', function( $filter ) {
return function( input, defaultValue ) {
if ( !input ) return defaultValue;
@kirkbushell
kirkbushell / .bash_profile
Created May 22, 2013 22:40
Bash profile colours/settings.etc.
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
source "$HOME/.bash_aliases"
LS_COLORS='di=1:fi=0:ln=31:pi=5:so=5:bd=5:cd=5:or=31:*.deb=90'
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME}: ${PWD}\007"'
@kirkbushell
kirkbushell / paginator.js
Created March 28, 2013 04:07
Paginator module for AngularJS, in combination with Laravel's paginator class
/**
* Paginator
*
* The paginator can be used within any controller to easily set up
* some pagination options, including number of pages, page navigation
* and more. It is built to work with Laravel's own pagination library,
* which returns data in a particular format.
*
* Usage:
* Before you can use paginator, make sure you specify the URLs to your pagination
# PRODUCT MODEL
has_many :product_people
has_many :people, :through => :product_people
accepts_nested_attributes_for :people
# PRODUCTS IN ACTIVE ADMIN
f.inputs "Cast" do
f.has_many :product_people do |p|
p.input :name
@kirkbushell
kirkbushell / gist:1721258
Created February 2, 2012 03:34
Confirmation validation conditional
validates :password_confirmation, :presence => true, :if => Proc.new { |u| !u.password.blank? && u.password_confirmation.present? }
@kirkbushell
kirkbushell / gist:1702294
Created January 30, 2012 03:25
rspec mock issue
require "spec_helper"
describe UserMailer do
describe "registration_email" do
@user = mock_model(User, :email => 'some@email.com', :first_name => 'john')
let(:mail) { UserMailer.registration_email(@user) }
it "renders the headers" do
mail.subject.should eq("Welcome to ScreenZone!")
conditions = {}
conditions.merge({:first_name.matches => '%'+@search_value+'%'} | {:last_name.matches => '%'+@search_value+'%'}) unless @search_value.blank?
conditions = {}
conditions[:title.matches] = '%'+@search_value+'%'
conditions[:description.matches] = '%'+@search_value+'%'
conditions[:status] = params[:show] if params[:show] != 'all'
# flash partial
- flash.each do |type,value|
- unless value.nil?
%div{:class => type.to_s}
%div
%span
= value
- unless object.nil?
%ul
- object.errors.full_messages.each do |msg|
# SQLite version 3.x
# gem install sqlite3
development:
adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000
production:
adapter: mysql