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 distance loc1, loc2 | |
rad_per_deg = Math::PI/180 # PI / 180 | |
rkm = 6371 # Earth radius in kilometers | |
rm = rkm * 1000 # Radius in meters | |
dlat_rad = (loc2[0]-loc1[0]) * rad_per_deg # Delta, converted to rad | |
dlon_rad = (loc2[1]-loc1[1]) * rad_per_deg | |
lat1_rad, lon1_rad = loc1.map {|i| i * rad_per_deg } | |
lat2_rad, lon2_rad = loc2.map {|i| i * rad_per_deg } |
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
/var/lib/docker/aufs/mnt/tmp-* |
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
# config valid only for current version of Capistrano | |
lock '3.4.0' | |
set :application, 'myapp' | |
set :repo_url, '' | |
# Default branch is :master | |
# ask :branch, `git rev-parse --abbrev-ref HEAD`.chomp | |
# Default deploy_to directory is /var/www/my_app_name |
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
cap production workers:clockwork:stop; cap production workers:delayed_job:stop; cap production deploy;cap production workers:clockwork:start; cap production workers:delayed_job:start; |
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 self.close_by(lat1, lon1) | |
posts_around = [] | |
Post.where("latitude IS NOT NULL AND longitude IS NOT NULL").order('id DESC').each do |post| | |
distance = Post.new.distance(lat1.to_f, lon1.to_f, post.latitude.to_f, post.longitude.to_f) | |
radius = Setting.find(1).usersight | |
if (distance <= radius.to_f) | |
post_array = {} | |
if post.user.nil? | |
username = "" | |
else |
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 self.is_valid_google?(google_id, user_token) | |
user = user_token.to_s | |
uri = URI('https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=' + user) | |
string = JSON.parse(Net::HTTP.get(uri)) | |
error = string["error"] if string["error"].present? | |
if error | |
return false | |
elsif string["user_id"].present? | |
if string["user_id"] == google_id | |
true |
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 self.valid_api?(api_key) | |
if api_key and Apikey.where(:api_key => api_key).present? | |
api = Apikey.where(:api_key => api_key).first | |
if !api.requests.nil? | |
api.requests = api.requests + 1 | |
else | |
api.requests = 1 | |
end | |
api.save | |
true |
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 'spec_helper' | |
describe Agent do | |
describe "1. calling #request" do | |
it "serves the action POST if the request is in POST" do | |
variable = Agent.request("http://google.com", "params", "post") | |
variable.should be_truthy | |
end | |
it "serves the action GET if the request is in GET" do |
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 jobs_count_within_user | |
limit = LIMIT | |
if self.user.jobs.count > limit | |
errors.add(:base, "Every user can create max #{limit} jobs") | |
false | |
else | |
true | |
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
scope :to_do, lambda { where(:processed => false) } | |
scope :processed, lambda { where(:processed => true) } | |
scope :to_do_now, lambda { where("due_date > ? AND due_date < ?", DateTime.now, DateTime.now + 3.minutes) } | |
scope :not_processed, lambda { where(:processed => false) } | |
scope :circular, lambda { where("minutes IS NOT NULL") } |
OlderNewer