Skip to content

Instantly share code, notes, and snippets.

View RafeHatfield's full-sized avatar

Rafe Hatfield RafeHatfield

View GitHub Profile

Clone the uptime repository

$ git clone https://github.com/fzaninotto/uptime.git

Run this command to create the Procfile:

$ echo "web: node app.js" > Procfile

Commit your changes

# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8
#!/bin/bash
# from https://coderwall.com/p/gog45a
function lastworkingday()
{
if [[ "1" == "$(date +%u)" ]]
then
echo "last friday"
else
echo "yesterday"
@RafeHatfield
RafeHatfield / ability.rb
Last active December 22, 2015 07:49 — forked from watson/ability.rb
# app/models/ability.rb
# All front end users are authorized using this class
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new
can :read, :all
@RafeHatfield
RafeHatfield / reverse polymorphic.rb
Last active December 23, 2015 05:39 — forked from runemadsen/description.markdown
Reverse Polymorphic Associations An email digest can contain either articles or questions, called as @email_digest.digest_elements
class EmailDigest < ActiveRecord::Base
has_many :digest_elements
has_many :articles, :through => :digest_elements, :source => :element, :source_type => 'Article'
has_many :questions, :through => :digest_elements, :source => :element, :source_type => 'Question'
end
class Article < ActiveRecord::Base
has_one :article_element, :as =>:element
has_one :email_digest, :through => :digest_elements
end
class Alert < ActiveRecord::Base
belongs_to :alertable, :polymorphic => true
end
class Region < ActiveRecord::Base
has_many :alerts, :as => :alertable
end
@RafeHatfield
RafeHatfield / sunspot_sidekiq.rb
Last active December 23, 2015 20:49 — forked from nz/sunspot_resque.rb
Example to queue sunspot solr updates using sidekiq instead of resque
# app/models/post.rb
class Post
searchable :auto_index => false, :auto_remove => false do
text :title
text :body
end
after_commit :sidekiq_solr_update, :if => :persisted?
@RafeHatfield
RafeHatfield / Gemfile
Last active December 24, 2015 10:49 — forked from cblunt/Gemfile
# ...
gem 'carrierwave'
gem 'fog'
require 'spec_helper'
describe FeaturePool do
it "creates a new instance given valid attributes" do
Fabricate :feature_pool
end
it "is not valid without a name" do
Fabricate.build(:feature_pool, :name => "").should_not be_valid
end
gemcutter => redis downloads spec
=================================
keys
----
downloads => global counter for all gem downloads
downloads:today => sorted set for downloads from today
downloads:rubygem:rails => counter for all rails downloads
downloads:version:rails-2.3.5 => counter for all rails 2.3.5 downloads