Skip to content

Instantly share code, notes, and snippets.

Avatar

Tudor Pavel tudorpavel

  • Cluj-Napoca, Romania
View GitHub Profile
@tudorpavel
tudorpavel / RUBY_SETUP.md
Last active Sep 27, 2016
Local setup for using Ruby on Linux
View RUBY_SETUP.md
@tudorpavel
tudorpavel / some_model.rb
Created Sep 13, 2015
Rails PostGIS within_range query.
View some_model.rb
def self.within_range(range_km, lat, lng)
if lat.present? && lng.present?
joins(location: :point)
.where(
"ST_DWithin(Geography(ST_MakePoint(longitude, latitude)),
Geography(ST_MakePoint(#{lng}, #{lat})),
#{(range_km * 1000).to_i})"
)
else
none
View functions.rb
def calc(arr)
arr[0] + (13.0 * arr[1] / arr[2]) + arr[3] + (12 * arr[4]) - arr[5] + (arr[6].to_f * arr[7] / arr[8])
end
def solutions
[1,2,3,4,5,6,7,8,9].permutation.to_a.keep_if { |p| calc(p) == 87.0 }
end
@tudorpavel
tudorpavel / RAILS_SETUP.md
Last active Feb 11, 2016
Local setup for Ruby on Rails development on Linux
View RAILS_SETUP.md

Ruby on Rails Setup

Install Ruby

Ruby on Rails depends on the Ruby programming language (doh), so we need to install that first. Follow the Ruby Setup guide to install a local version of Ruby.

Install Rails

Install the latest version of Rails