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
# config/initializers/hstore_accessor.rb | |
# http://www.devmynd.com/blog/2013-3-single-table-inheritance-hstore-lovely-combination | |
module HstoreAccessor | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
def hstore_accessor(hstore_attribute, *keys) | |
Array(keys).flatten.each do |key| |
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
# Thanks to http://www.paulirish.com/2009/random-hex-color-code-snippets for the idea | |
module ColorSupport | |
# yields a random color | |
def self.random_color | |
color_for((rand() * ((0xFFFFFF + 1) << 0)).to_i.to_s(16)) | |
end | |
# yields a random color based on the given color | |
# credit: http://stackoverflow.com/a/43235 |
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 Date | |
def to_utc_ticks | |
Time.utc(self.year, self.month, self.day).to_i * 1000 | |
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
# | |
# | |
# Rails 4 concern for specifying default attribute values on models | |
# | |
# E.g. The following user has defaults defined for `active` and `manager` attributes | |
# | |
# class User < ActiveRecord::Base | |
# include Concerns::DefaultValues | |
# | |
# default_value :active, true |
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
#!/bin/bash | |
# make sure we're at the root of git repo | |
if [ ! -d .git ]; then | |
echo "Error: must run this script from the root of a git repository" | |
exit 1 | |
fi | |
git diff --numstat \ | |
| awk '{if (($1 == "-" && $2 == "-") || ($1 == "0" && $2 == "0")) { $1=$2=""; print }}' \ |
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
#!/bin/bash | |
comment=${1:-"Autosaved at $(date +%Y)-$(date +%m)-$(date +%d) $(date +%H:%M)"} | |
# make sure we're at the root of git repo | |
#if [ ! -d .git ]; then | |
# echo "Error: must run this script from the root of a git repository" | |
# exit 1 | |
#fi |
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
# gem code | |
module Trailblazer | |
class Operation | |
def self.inherited(klass) | |
qualified_name = klass.name | |
name_parts = qualified_name.split('::') | |
method_name = name_parts.last |
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
using System; | |
namespace MyNamespace | |
{ | |
public static class MyExtensions | |
{ | |
public static void Fire<TSender, TEventArgs>(this EventHandler<TSender, TEventArgs> myEvent, TSender sender, TEventArgs e) | |
where T EventArgs: EventArgs | |
{ | |
if(myEvent != null) |
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
public static class DelegateExtensions | |
{ | |
public static Func<T> Before<T>(this Func<T> func, Action before) | |
{ | |
return () => | |
{ | |
before(); | |
return func(); | |
}; | |
} |
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
require 'kernel_using' | |
class ResourceConsumer | |
def open() | |
puts 'Opening up...' | |
end | |
def close() | |
puts 'Closing up...' |
OlderNewer