Skip to content

Instantly share code, notes, and snippets.

View KieranP's full-sized avatar

Kieran Pilkington KieranP

View GitHub Profile

Keybase proof

I hereby claim:

  • I am KieranP on github.
  • I am k776 (https://keybase.io/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
KieranP / app-components-application_component.rb
Last active June 18, 2019 11:45
Simple Rails Component System
# frozen_string_literal: true
class ApplicationComponent
include ActiveModel::Validations
include ActionView::Helpers::TagHelper
attr_accessor :content
def initialize(*args)
@KieranP
KieranP / delayed_job_base_job.rb
Last active August 29, 2015 14:06
DelayedJob BaseJob Template - With Memory Usage Logging
class BaseJob
def self.queue(*args)
options = args.extract_options!
Delayed::Job.enqueue(new(*args), options)
end
def initialize(*args)
@args = args
end
@KieranP
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)
# A user session class, a simplified mix of the following code samples:
# * https://github.com/blog/1661-modeling-your-app-s-user-session
# * http://www.jonathanleighton.com/articles/2013/revocable-sessions-with-devise/
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
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)
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 = Hash.new
klass.reflect_on_all_associations(:belongs_to).each do |belongs_to|
assoc_name, field_name = belongs_to.name.to_s, belongs_to.foreign_key.to_s
@KieranP
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
======
README
======
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!
Install
-------