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
@mikecmpbll
mikecmpbll / en.yml
Created June 26, 2014 14:00 — forked from smaboshe/en.yml
# Variable substitution works here
foo: "The quick brown %{ animal } jumped over the lazy dog"
# Variable substitution done not work here
# Instead, "%{ animal }" gets rendered
bar: "The quick
brown %{ animal }
jumped over
the lazy dog"
class SelectedDoorkeeperFor < DoorkeeperFor
def initialize(*args)
options = args.pop if args.last.is_a? Hash
super(options)
only(args)
end
private
def only(actions)
irb(main):043:0> '2X 2T6‎", "province"'.bytes
=> [50, 88, 32, 50, 84, 54, 226, 128, 142, 34, 44, 32, 34, 112, 114, 111, 118, 105, 110, 99, 101, 34]
irb(main):044:0> '2X 2T6", "province"'.bytes
=> [50, 88, 32, 50, 84, 54, 34, 44, 32, 34, 112, 114, 111, 118, 105, 110, 99, 101, 34]
irb(main):001:0> module Foo
irb(main):002:1> def the_var(var)
irb(main):003:2> @var ||= var
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> class Bar
irb(main):007:1> end
=> nil
irb(main):008:0> Bar.extend(Foo).the_var("something")
@mikecmpbll
mikecmpbll / example.rb
Last active August 29, 2015 14:04 — forked from anonymous/example.rb
search_all = LOCAL_SETTINGS["single_site_search"]
if params[:ref].present?
spaces = Space.where(id: { params[:ref] }, parent_id: nil })
spaces = spaces.eager_loads(slots: :companies).where(companies: { parent_id: current_company_id }) unless search_all
render partial: 'call_centre_results' and return
end
AppUser.authenticate('ADMIN', '')
AppUser Load (0.9ms) EXEC sp_executesql N'SELECT TOP (1) [AppUsers].* FROM [AppUsers] WHERE [AppUsers].[UserID] = N''ADMIN'' AND [AppUsers].[Password] = N'''' ORDER BY [AppUsers].[UserID] ASC'
=> #<AppUser UserID: "ADMIN", UserName: "Administrator", MenuGroup: "SYS_ADMIN", Password: "", DefaultStoreID: "1", FullRights: true, LastChanged: "2013-10-23 17:59:52", ChangedBy: "ADMIN", Email: "", Phone: "", Deleted: false, CashierID: "", HideCostPrice: false, WebLogin: false, CustomerID: "", DepID: "", NetworkID: "">
@mikecmpbll
mikecmpbll / console
Last active August 29, 2015 14:04 — forked from anonymous/console
1.9.3p392 :002 > Postcode
=> Postcode(id: integer, postcode: string, long: decimal, lat: decimal, address: string, bias: string, data: text, tries: integer, updated_at: datetime, created_at: datetime)
1.9.3p392 :003 >
@mikecmpbll
mikecmpbll / skip_callbacks.rb
Created August 22, 2014 11:03
Skip all validations on a particular field in Rails
plain_text_password_validators = User.validators.select { |v| v.attributes.include?(:plain_text_password) }
callback_filters = User._validate_callbacks.select{ |vc| plain_text_password_validators.include?(vc.raw_filter) }.map{ |vc| vc.filter }
callback_filters.each do |cf|
User.skip_callback(:validate, :before, cf)
end
class AbstractClass
def initialize(attributes)
attributes.each do |name, value|
unless self.respond_to?("#{name}=")
self.class.send(:attr_accessor, name)
end
self.send("#{name}=", value)
end
end
end
module Test2
class << self
@var = "foo"
def test_method
@var
end
end
end