View papertail-versioning.rb
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 |
View medium-post-scope-1.rb
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 |
View .bash_profile
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 |
View local_date_time_attr_readers.rb
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 |
View time_zone_validator.rb
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: | |
# |
View lstdefinelanguage-gherkin.tex
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, |
View alphadin.bst
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" = |
View brew-coffee
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 |
View .bash_profile
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 |
View bower.rake
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 |