Skip to content

Instantly share code, notes, and snippets.

View rlisowski's full-sized avatar

Rafał Lisowski rlisowski

  • Warsaw, Poland
View GitHub Profile
@rlisowski
rlisowski / Gemfile
Created June 2, 2017 20:58 — forked from palkan/Gemfile
RSpec profiling with RubyProf and StackProf
gem 'stackprof', require: false
gem 'ruby-prof', require: false
@rlisowski
rlisowski / track_spec_times.rb
Created May 22, 2017 12:08
track specs times
SPEC_STATS = {}
SPEC_STAT_ENABLED = 'true' == ENV['SPEC_STAT']
RSpec.configure do |config|
config.before(:each) do
@__started = Time.now if SPEC_STAT_ENABLED
end
config.after(:each) do
if SPEC_STAT_ENABLED
@rlisowski
rlisowski / geo_distance.rb
Last active February 28, 2018 07:40
Distance between two coordinates on earth is usually calculated using Haversine formula
def geo_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 }
regex = Regexp.new(/^[0-9]* (.*), (.*) [a-zA-Z]{2} [0-9]{5}(-[0-9]{4})?$/)
addresses = ["420 Fanboy Lane, Cupertino CA 12345"]
addresses << "1829 William Tell Oveture, by Gioachino Rossini 88421"
addresses << "114801 Western East Avenue Apt. B32, Funky Township CA 12345"
addresses << "1 Infinite Loop, Cupertino CA 12345-1234"
addresses << "420 time!"
addresses.each do |address|
print address
if address.match(regex)
#!/bin/bash
#
# Script to setup a Elastic Beanstalk AMI with geospatial libraries and postGIS
#
# sh aws_ami_prep.sh > aws_ami_prep.log 2>&1 &
# Go to ec2-user home directory
cd /home/ec2-user
# yum libraries
@rlisowski
rlisowski / ruby server with daemon.rb
Last active January 13, 2017 19:26
ruby daemonization
require 'fileutils'
class Server
#==========================================================================
VERSION = "1.0.0"
def self.run!
Server.new.run!
end
Your Gemfile lists the gem mysql2 (~> 0.3.11) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Your Gemfile lists the gem activerecord-jdbcmysql-adapter (>= 0) more than once.
You should probably keep only one of them.
While it's not a problem now, it could cause errors if you change the version of just one of them later.
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...
Using multi_json 1.10.1
Using rake 10.1.1
GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.21)
actionpack (= 3.2.21)
mail (~> 2.5.4)
actionpack (3.2.21)
activemodel (= 3.2.21)
activesupport (= 3.2.21)
builder (~> 3.0.0)

Download and Install Vagrant http://www.vagrantup.com/ and VirtualBox https://www.virtualbox.org/ or VMware before beginning

#Set up Vagrant *this guide assumes the use of Mac OS X Mountain Lion on local machine and Ubuntu 12.04 LTS x64 on Vagrant box. It is compatible with many other distros but hasn't been tested.

##Step 1: Make and run box

vagrant init
vagrant box add <path to box directory or name according to https://vagrantcloud.com/>
vagrant up
@rlisowski
rlisowski / README.md
Created September 15, 2013 20:48 — forked from netmute/README.md

Game of Life

An implementation of Conway's Game of Life in 140 characters of Ruby.

Author

Created by Simon Ernst (@sier).