Skip to content

Instantly share code, notes, and snippets.

View codespectator's full-sized avatar

James MacLeod codespectator

View GitHub Profile
redis = Redis.new(:url => 'redis://localhost:7372')
redis.set('test','test')
=> nil
redis.get('test')
=> nil
redis.client.connection.connected?
=> true
redis.client.connected?
=> true
[fetchRequest setPredicate:[NSPredicate predicateWithFormat:@"engineer.serverId = %@", self.currentEngineer.serverId]];
class Job < ActiveRecord::Base
include NearbyMethods
end
module NearbyMethods
include ActiveSupport::Concern
def nearby(asset, radius=10)
asset.singularize.constantize.find_near(self.latlng, radius) # forget nearby and do a radius search
end
@codespectator
codespectator / application.css
Created November 8, 2012 23:22
Assets not included
/*
*= require_self
*= require reset
*= require lib/master_layout
*= require lib/nav
*= require lib/headers
*= require lib/sidebar
*= require lib/forms
*= require lib/calendar
*= require lib/search
@codespectator
codespectator / gist:3559798
Created August 31, 2012 22:06
Headache with account id int
# I have this in my routes
scope ':account_ident' do
resources :things
end
# this scope is only active when a user is logged in and if possible I would like to append the account_ident automatically rather than having to do this in all the views:
link_to "A thing", thing_path(thing, :account_ident => current_account.account_number)
@codespectator
codespectator / gist:3186845
Created July 27, 2012 08:33
Adding errors in a setter method
validate :full_name_length
def full_name
[forename, surname].compact.join(' ')
end
def full_name=(full_name_str)
name_arr = full_name_str.split(' ',2)
self.forename = name_arr.first
self.surname = name_arr.last
def array_method(*args)
# Do stuff...
end
array_method([1,2,3,4])
@codespectator
codespectator / gist:3182542
Created July 26, 2012 14:57
Problem with controller
class CustomersController < ApplicationController
end
## Error
wrong number of arguments (1 for 0) (ArgumentError)
./app/controllers/customers_controller.rb:1:in `<top (required)>'
message = NotificationMailer.method(mailer_method.to_sym).call(email_address, full_name)
message.deliver
class Exercise
belongs_to :language_one, :class => '::LanguageCode', :foreign_key => 'lanaguage_one_id'
belongs_to :language_two, :class => '::LanguageCode', :foregin_key => 'language_two_id'
end
class LauangeCode
end