Skip to content

Instantly share code, notes, and snippets.

View RafeHatfield's full-sized avatar

Rafe Hatfield RafeHatfield

View GitHub Profile
@RafeHatfield
RafeHatfield / clicktracker.js
Created May 18, 2013 05:41
quick jquery script to track clicks on the site
$(function(){
$('a').click(function(){
var source = '';
var destination = '';
var link_text = '';
source = window.location.pathname;
if($(this).attr('href')){
@RafeHatfield
RafeHatfield / randomizer.js
Created May 18, 2013 05:51
quick js randomizer
if (Math.floor(Math.random()*2) == 1) {
alert('foo')
} else {
alert('bar')
}

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'