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 / asset_file.css.erb
Created June 19, 2012 11:51
Serving fonts from Amazon S3 with Rails "Proxy" to avoid XSS problems. (Dirty way!)
@font-face {
font-family: 'HPBold';
src: url("<%= ('http://myproductionhostorsomething.com/font/HPSimplifiedW04-Bold.eot') %>");
font-weight: normal;
font-style: normal;
}
@otobrglez
otobrglez / peerindex.rb
Created June 20, 2012 10:00
Ruby wrapper for PeerIndex V2 REST API
# By Oto Brglez - <oto.brglez@opalab.com>
require 'httparty'
class PeerIndex
include HTTParty
format :json
base_uri "http://api.peerindex.net/v2"
def get(handler)
guard 'livereload', :apply_css_live => false, :apply_js_live => false do
watch(%r{app/.+\.(erb|haml|js|css|scss)})
watch(%r{app/helpers/.+\.rb})
watch(%r{(public/|app/assets).+\.(css|js|erb|html)})
watch(%r{(app/assets/.+\.css)\.s[ac]ss}) { |m| m[1] }
watch(%r{(app/assets/.+\.js)\.coffee}) { |m| m[1] }
watch(%r{(app/assets/.+\.js)\.erb}) { |m| m[1] }
watch(%r{config/locales/.+\.yml})
end
@otobrglez
otobrglez / sentence_detection.rb
Created July 10, 2012 08:34
Sentence detection with OpenNLP and jRuby
# By Oto Brglez - <oto.brglez@opalab.com>
# Read:
# http://opennlp.apache.org/documentation/1.5.2-incubating/apidocs/opennlp-tools/index.html
# http://opennlp.apache.org/documentation/1.5.2-incubating/manual/opennlp.html#tools.sentdetect.detection
require 'bundler/setup'
require 'ruby-debug'
require 'pp'
@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 / 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