Skip to content

Instantly share code, notes, and snippets.

View otobrglez's full-sized avatar
🏗️
Building.

Oto Brglez otobrglez

🏗️
Building.
View GitHub Profile
@otobrglez
otobrglez / geo_move.rb
Created July 17, 2012 10:43
Calculating coordinates from given coordinate
# You have coordinate in array and you want to calculate coordiante that is away from it by length_degree and direction_degree
def move point, length_degree=10, direction_degree=0
[
point[0]+length_degree*Math.cos(direction_degree*Math::PI/180),
point[1]+length_degree*Math.sin(direction_degree*Math::PI/180)
]
end
@otobrglez
otobrglez / hash.rb
Created July 30, 2012 09:23
Convert keys_to_symbols for Hash.
class Hash
# This is monkey patch to convert keys to symbols.
def keys_to_symbols!
self.keys.inject({}) { |i,k|
i.merge!({k.to_sym => self.values_at(k).first}) }
end
end
@otobrglez
otobrglez / smb.conf
Created September 18, 2012 16:17
Samba Configuration that works with OSX...
[cs]
path = /home/zver/cs
public = yes
writable = yes
printable = no
guest ok = yes
create mask = 0644
directory mask = 0755
force create mode = 0644
force directory mode = 0755
@otobrglez
otobrglez / hookz.rb
Created November 12, 2012 08:17
Playing with callbacks...
require 'minitest/spec'
require 'minitest/autorun'
# Simulating existing structure
module Animal
def self.included who
who.extend ClassMethods
end
module ClassMethods
@otobrglez
otobrglez / keybase.md
Created October 13, 2015 20:12
keybase.md

Keybase proof

I hereby claim:

  • I am otobrglez on github.
  • I am otobrglez (https://keybase.io/otobrglez) on keybase.
  • I have a public key whose fingerprint is 4FE7 0346 C546 B9C0 31D9 B91B 0441 9BCA 2621 C2E3

To claim this, I am signing this object:

@otobrglez
otobrglez / rethinkdb_requests_second.js
Created November 26, 2015 17:41
Experimenting with map-reduce / aggregation in RethinkDB
// successful jobs grouped by type maped by req/sec
r.db('qm_production').table('jobs')
.filter({'last_event_type': 'success'})
.map(function(doc) {
return {
'ds_type': doc('ds_type'),
'last_event_type': doc('last_event_type'),
'res_sec': doc("stats_event_response_count").div(doc('stats_run_duration')),
'req_sec': doc("stats_event_request_count").div(doc('stats_run_duration'))
};
@otobrglez
otobrglez / dabblet.css
Created January 7, 2013 21:52
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
@otobrglez
otobrglez / gist:4585762
Last active December 11, 2015 10:18
rake db:seed crash (updated)
*[master][~/opalab/citysocialize_api]$ rake db:seed rvm:ruby-1.9.3-p194@citysocialize_api
rake aborted!
SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B
/Users/otobrglez/.rvm/gems/ruby-1.9.3-p194@citysocialize_api/gems/recurly-2.1.5/lib/recurly/api/net_http_adapter.rb:72:in `request'
/Users/otobrglez/.rvm/gems/ruby-1.9.3-p194@citysocialize_api/gems/recurly-2.1.5/lib/recurly/api.rb:50:in `get'
/Users/otobrglez/.rvm/gems/ruby-1.9.3-p194@citysocialize_api/gems/recurly-2.1.5/lib/recurly/resource.rb:319:in `find'
/Users/otobrglez/opalab/citysocialize_api/app/models/plan.rb:39:in `recurly_plan'
/Users/otobrglez/opalab/citysocialize_api/app/models/plan.rb:21:in `update_from_recurly'
/Users/otobrglez/.rvm/gems/ruby-1.9.3-p194@citysocialize_api/gems/activesupport-3.2.11/lib/active_support/callbacks.rb:418:in `_run__443529181208233123__save__306707287606003360__callbacks'
/Users/otobrglez/.rvm/gems/ruby-1.9.3-p194@cit
@otobrglez
otobrglez / gist:4585906
Created January 21, 2013 13:07
Getting ugly...
/Users/otobrglez/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799: [BUG] Segmentation fault
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin10.8.0]
-- Control frame information -----------------------------------------------
c:0066 p:---- s:0274 b:0274 l:000273 d:000273 CFUNC :connect
c:0065 p:0011 s:0271 b:0271 l:000800 d:000270 BLOCK /Users/otobrglez/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799
c:0064 p:0031 s:0269 b:0269 l:000268 d:000268 METHOD /Users/otobrglez/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:54
c:0063 p:0026 s:0257 b:0257 l:000256 d:000256 METHOD /Users/otobrglez/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/timeout.rb:99
c:0062 p:0485 s:0251 b:0251 l:000800 d:000800 METHOD /Users/otobrglez/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:799
c:0061 p:0011 s:0243 b:0243 l:000242 d:000242 METHOD /Users/otobrglez/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:755
@otobrglez
otobrglez / compare_arrays.rb
Last active December 12, 2015 07:58
Finding fastest way to compare 2 arrays...
require 'benchmark'
require 'set'
a = ["a","b","c","d"]
b = ["b","d"]
Benchmark.bm do |x|
x.report do
(a.inject(0) {|s,i| s += b.include?(i)?1:0 } == b.size)
end