This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User | |
# Return a string suitable for uniquely identifying this user in URLs | |
# @return [String] | |
def to_param | |
begin | |
n = shadow_username | |
n = _id.to_s if n.blank? or (username_changed? and !valid?) | |
n | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@contacts = [{:email => "[email protected]", :name => "jordan"}] | |
all_emails = @contacts.map {|c| c[:email]} | |
existing = User.where("email in (?)", all_emails).select("email").all.map(&:email) | |
@contacts.reject! {|c| existing.include? c[:email] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.9.3p286 :008 > module Kernel | |
1.9.3p286 :009?> def wtf | |
1.9.3p286 :010?> puts "wtf?" | |
1.9.3p286 :011?> end | |
1.9.3p286 :012?> end | |
=> nil | |
1.9.3p286 :013 > wtf | |
wtf? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def terms(taxonomies = [], include_taxonomies = false) | |
ids = relationships.map(&:term_taxonomy_id) | |
return [] if ids.empty? | |
proxy = Wordpress::Term.joins(:taxonomies).where(Wordpress::TermTaxonomy.arel_table[:term_taxonomy_id].in ids) | |
proxy = proxy.includes(:taxonomies) if include_taxonomies | |
proxy.where( Wordpress::TermTaxonomy.arel_table[:taxonomy].in(taxonomies) ) unless taxonomies.empty? | |
proxy.all | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'oauth' | |
module Intuit | |
module API | |
# This returns a Ruby OAuth consumer object initialized with the correct Intuit endpoints | |
def self.get_consumer(key, secret) | |
@consumer = OAuth::Consumer.new(key, secret, { | |
:site => "https://oauth.intuit.com", | |
:request_token_path => "/oauth/v1/get_request_token", | |
:authorize_path => "/oauth/v1/get_access_token", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if ((en>=shred.energy) && (cp<5)&& ((((koj_timer<((shred.energy+rake.energy-10-en)*10) && | |
((mdebuff_timer > ((shred.energy+mangle.energy-10-koj_m1-en)*10) && ((rake_timer > ((shred.energy+rake.energy-10-koj_m1-en)*10))||(rk==0)) | |
&& (cp<3) && (mdebuff_timer >= 100+lag) && rake_timer>(0) )||((sr_timer<(100+lag))&&(en>(rake.energy+sr_energy-10)))||((rip_timer<(100+lag))&&(en>(rake.energy+sr_energy-10)))||(koj_timer<(100+lag))))||(((mdebuff_timer > ((shred.energy+mangle.energy-10-en)*10) | |
&&(( rake_timer > ((shred.energy+rake.energy-10-en)*10))||(rk==0)) && (cp<3) && (mdebuff_timer >= 100+lag) && ((rake_timer>0)||(rk==0)) ) | |
||((sr_timer<(100+lag))&&(en>(rake.energy+sr_energy-10)))||((rip_timer<(100+lag))&&(en>(rake.energy+sr_energy-10)))||(koj_timer<(100+lag)))))||((cp>=3)||(rip_timer<0)))||(time_to_die_boss<=kill_mode))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Admin < APIWrapper | |
custom_post :login | |
collection_path 'admins' | |
resource_path 'admins/get/:id' | |
def self.get_admin(superadmin_id, admin_id) | |
get("admins/get/#{superadmin_id}/#{admin_id}") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SessionsController < ApplicationController | |
before_filter :require_no_session, :only => [:new, :create] | |
before_filter :require_session, :only => [:destroy] | |
def create | |
email, password = params[:session][:email], params[:session][:password] | |
api_response = Admin.login(email.downcase, password) | |
if api_response.try(:code) | |
sign_in api_response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'faraday' | |
require 'json' | |
url = "http://api.twitter.com/1/statuses/user_timeline.json?id=cheald" | |
response = Faraday.get url | |
if response.success? | |
result = JSON.parse(response.body) | |
puts "Tweets: %s\n" % result.map {|tweet| tweet["text"] }.join("\n") | |
else | |
puts "An error occurred and we couldn't get your tweets" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MongoMapper | |
module Observer | |
extend ActiveSupport::Concern | |
included do | |
include ::ActiveModel::Observing | |
class_eval do | |
[ | |
:before_save, :after_save, | |
:before_create, :after_create, |