Skip to content

Instantly share code, notes, and snippets.

View azuby's full-sized avatar

azuby

  • California, USA
View GitHub Profile
class Diagnosis < ActiveRecord::Base
has_and_belongs_to_many :prescriptions
has_many :patients, :through=>:prescriptions
end
@azuby
azuby / message.rb
Created March 5, 2012 21:45 — forked from StlTenny/gist:1981303
StlTenny Models
class Message < ActiveRecord::Base
belongs_to :user
# accepts_nested_attributes_for :user
end
SyncIn::Application.routes.draw do
#devise_for :admins, :controllers => { :sessions => "admins/sessions" }
devise_for :users, :controllers => { :sessions => "sessions", :registrations => "registrations" }, :skip => [ :sessions, :registations ]
as :user do
get '/signin' => 'sessions#new', :as => :new_user_session
post '/signin' => 'sessions#create', :as => :user_session
delete '/signout' => 'sessions#destroy', :as => :destroy_user_session
validates :password, format: { with: /\d/, message: "must contain at least one number" },
allow_blank: true
validates :password, format: { with: /[a-zA-Z]/, message: "must contain at least one letter" },
allow_blank: true
it "should require a letter" do
numbers = "12345678"
user = User.new(@attr.merge(:password => numbers, :password_confirmation => numbers))
user.should have(1).error_on(:password)
user.errors_on(:password).should include("must contain at least one letter")
Method A: Carrier - Poor Location Precision, Secure
Method B: Client(phone) - High Location Precision, Insecure (Can be spoofed)
Option 1: Improve precision of Method A (Carrier Location)
* Supports all phones on Tier 1 carriers
* Find and correct for inaccuracy patterns
Option 2: Prevent spoofing of Method B (Client Location)
* Supports smart phones on all carriers
* Possible spoof prevention: http://stackoverflow.com/questions/6623945/check-if-geo-location-has-been-spoofed
def location
# return nil if !subscribed?
if last_location && (Time.now - last_location.created_at) < 5.minutes
return locations.create!( latitude: last_location.latitude, longitude: last_location.longitude, radius: last_location.radius )
end
locate
end
def self.active
s = arel_table where(
s[:begins_at].lteq(Time.now.utc).or(s[:begins_at].eq(nil)),
s[:ends_at].gt(Time.now.utc).or(s[:ends_at]).eq(nil))
)
end
def self.active
s = arel_table.where(
s[:begins_at].lteq(Time.now.utc).or(s[:begins_at].eq(nil)),
# Permissions
permission = []
[
{ action: "create", resource: "User", access: "none" },
{ action: "read", resource: "User", access: "individual" },
{ action: "update", resource: "User", access: "individual" },
{ action: "destroy", resource: "User", access: "individual" },
{ action: "create", resource: "Shift", access: "none" },
{ action: "read", resource: "Shift", access: "individual" },
{ action: "update", resource: "Shift", access: "individual" },
class Locator
@queue = :location_queue
def self.perform
begin
location = get_location
# do something useful with location
rescue LocationError => error
# do something useful with location error
<html><head><title>502 Bad Gateway</title></head><body><h1>Bad Gateway</h1>An upstream server returned an invalid response.</body></html>