Skip to content

Instantly share code, notes, and snippets.


Kieran Pilkington KieranP

View GitHub Profile

Keybase proof

I hereby claim:

  • I am KieranP on github.
  • I am k776 ( on keybase.
  • I have a public key whose fingerprint is D567 916A E829 323F 1C1B 12D2 F98C BBEC 277A 2FCF

To claim this, I am signing this object:

KieranP / app-components-application_component.rb
Last active June 18, 2019 11:45
Simple Rails Component System
View app-components-application_component.rb
# frozen_string_literal: true
class ApplicationComponent
include ActiveModel::Validations
include ActionView::Helpers::TagHelper
attr_accessor :content
def initialize(*args)
KieranP / delayed_job_base_job.rb
Last active August 29, 2015 14:06
DelayedJob BaseJob Template - With Memory Usage Logging
View delayed_job_base_job.rb
class BaseJob
def self.queue(*args)
options = args.extract_options!
Delayed::Job.enqueue(new(*args), options)
def initialize(*args)
@args = args
KieranP / 1 app-models-session.rb
Last active October 8, 2020 16:11
A Ruby on Rails implementation of a Database and Cookie hybrid session storage for Devise that supports session revocation and storage of session ip and user agent for security (similar to Github)
View 1 app-models-session.rb
# A user session class, a simplified mix of the following code samples:
# *
# *
class Session < ActiveRecord::Base
# Uncomment if you use Hobo Fields, else add these yourself
# fields do
# session_id :string, :index => true, :unique => true
# accessed_at :datetime
# user_ip :string
KieranP / orphaned_check.rake
Last active October 11, 2015 11:08
Rake task that scans all Rails models for orphaned belong_to associations (Rails 3.2 or higher)
View orphaned_check.rake
task :orphaned_check => :environment do
Dir[Rails.root.join('app/models/*.rb').to_s].each do |filename|
klass = File.basename(filename, '.rb').camelize.constantize
next unless klass.ancestors.include?(ActiveRecord::Base)
orphanes =
klass.reflect_on_all_associations(:belongs_to).each do |belongs_to|
assoc_name, field_name =, belongs_to.foreign_key.to_s
KieranP / .0 Git Status Console Prompt
Last active August 30, 2015 04:55
Console script to print which git branch you're in and its current status to the shell prompt
View .0 Git Status Console Prompt
This will add a display of the current directories Git state.
Warning: This script relies on a Git version of 1.7.2 or higher!