This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :bower do | |
%w[install list].each do |command| | |
desc "#{command} bower packages" | |
task command do | |
on roles(:web) do | |
within release_path do | |
execute 'bower', 'install' | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Shim the npm binary to enable custom command `npm exec`. | |
npm_shim() { | |
# Make real npm calls with full path, otherwise the alias is called recursively. | |
npm_binary=$(which npm) | |
if [ $# -eq 0 ] | |
then | |
$npm_binary | |
elif [ $# -eq 1 ] | |
then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
if ARGV.length == 0 | |
puts "☕️" | |
else | |
puts "☕️" * ARGV.first.to_i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FUNCTION {key.label} | |
{ key #20 text.prefix$ } %% Length of 20 chars should be sufficient | |
FUNCTION {calc.label} | |
{ type$ "book" = | |
type$ "booklet" = | |
type$ "inbook" = | |
or or | |
'author.editor.key.label | |
{ type$ "proceedings" = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
\lstdefinelanguage{Gherkin}{ | |
morekeywords = { | |
Given, | |
When, | |
Then, | |
And, | |
Scenario, | |
Feature, | |
But, | |
Background, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimeZoneValidator < ActiveModel::EachValidator | |
def validate_each(record, attribute, value) | |
unless ActiveSupport::TimeZone[value] | |
record.errors[attribute] << (options[:message] || 'is not a valid time zone!') | |
end | |
end | |
end | |
# Usage with rails: | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ActiveRecord stores timestamps in UTC and converts them into the application's time zone | |
# (see config.time_zone in config/application.rb). | |
# | |
# This module provides a simple to use API to automatically generate '_local' suffix methods | |
# for model attribute readers that convert dates and times according to a per model time zone. | |
module LocalDateTimeAttrReaders | |
extend ActiveSupport::Concern | |
included do | |
include ActiveModel::AttributeMethods |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the Git branch | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
# Custom bash prompt | |
# | |
# Includes custom character for the prompt, path, and Git branch name. | |
# | |
# Source: kirsle.net/wizards/ps1.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Article < ApplicationRecord | |
has_many :comments | |
has_many :tags | |
scope :draft, -> { where(published_at: nil) } | |
scope :published, -> { where.not(published_at: nil) } | |
scope :commented, -> { joins(:comments).distinct } | |
end | |
Article.published.count |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gemfile | |
gem 'paper_trail' | |
# app/models/my_model.rb | |
class MyModel < ApplicationRecord | |
has_paper_trail | |
end |