Skip to content

Instantly share code, notes, and snippets.

View mikecmpbll's full-sized avatar
🎯
Focusing

Mike Campbell mikecmpbll

🎯
Focusing
  • Skipton, North Yorkshire
View GitHub Profile
module ActiveSupport
module Cache
class RedisStore
def delete(key, options = nil)
options = merged_options(options)
instrument(:delete_matched, key.inspect) do |payload|
delete_matched(namespaced_key(key, options), options)
end
end
def self.me2
total_count = 0
total_new = Project.order(datum: :asc).group("date_format(datum, '%Y%m')").count.select{|d,c| d}
total_by_month = Hash[total_new.map { |month, n| [ month, total_count += n ]}]
end
def self.mike
new_users_by_month = Project.group("date_format(datum, '%Y%m')").count.select{|d,c| d}
total_users_by_month = Hash[new_users_by_month.map do |d, c|
[d, new_users_by_month.sum do |d2,c|
@mikecmpbll
mikecmpbll / r.rb
Last active August 29, 2015 14:00
def save
ActiveRecord::Base.transaction do
return contact.save! && school.save!
end
rescue
false
end
class Contact < ActiveRecord::Base
has_and_belongs_to_many :clients, class_name: "School"
after_save :update_primary
def name
title + " " + forename + " " + surname
end
private
app
engines
engine_one
app
models
..etc
engine_two
app
models
..etc
class Widget < ActiveRecord::Base
attr_accessible :name, :snippets, :snippets_attributes, :company_id, :hostname, :first_page, :affiliate_id, :item_defaults, :read_only
has_many :snippets
has_many :permissions, dependent: :destroy
has_many :users, through: :permissions
accepts_nested_attributes_for :snippets
attr_accessor :read_only
def read_only
true
class JTask
# JTask.find()
# Retrieves records from the database file.
# --------------------------------------------------------------------------------
# Eg: JTask.find("test.json", 1) || JTask.find("test.json", first: 10)
# #=> <JTask id=x, ...>
# --------------------------------------------------------------------------------
# See wiki guide for more usage examples...
# https://github.com/adammcarthur/jtask/wiki/find
class Party < AR::Base
belongs_to :user
belongs_to :session
end
resources :groups, path: '/', only: :show do
resources :events
end
def update_status
order_statuses = self.rows.joins(row_status: :order_status).group('order_status.id').pluck('order_status.id')
self.order_status_id = order_statuses.one? ? order_statuses.pop : OrderStatus.find_by(name: "processing").id
self.save!
end