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 / 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
@otobrglez
otobrglez / app.rb
Created August 10, 2013 08:45
Evaluating in MongoDB stored equations with "db.eval" in map-reduce process.
#!/usr/bin/env ruby
require 'bundler/setup'
require "mongo"
include Mongo
@client = MongoClient.new('localhost')
@db = @client['equation‎s_demos']
@equation‎s = @db['equation‎s']
@otobrglez
otobrglez / elasticsearch_script_field.rb
Created August 10, 2013 11:53
Proof of concept for executing JavaScript stored in ElasticSearch with Mozilla Rhino engine as ElasticSearch plugin.
#!/usr/bin/env ruby
# For this example to run you have to enable ElasticSearch plugin "lang-javascript" and
# also set default scripting language in elasticsearch.yml to "script.default_lang: js"
# in this way you will change scripting engine from default mvel to Mozilla Rhino
require "bundler/setup"
require 'tire'
# Tire.configure { logger STDERR }
@otobrglez
otobrglez / source_maps.rb
Created November 25, 2013 21:27
CoffeeScript Source Mapping Rails Initializer
# config/initializers/source_maps.rb
if Rails.env.development?
module CoffeeScript
class SourceMapError < StandardError; end;
class << self
def compile script, options
script = script.read if script.respond_to?(:read)
# /* vim: set ai ts=4 ft=sh: */
#
# Copyright 2011, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@otobrglez
otobrglez / local_invite_text.rb
Created December 2, 2013 10:17
Use Rails I18n integration to do translation with some defaults. Inspired by Ruby I18n - http://ruby-i18n.org/wiki
# Also!
# include ActionView::Helpers::TranslationHelper
def local_invite_text invite, options={}
invite_text = card.category.invite_text
key = invite_text.present? ? nil : :invite_via_sms
default = invite_text.present? ? invite_text : nil
time = if card.local_starts_at.present?
card.verbose_time
@otobrglez
otobrglez / blah.rb
Created December 2, 2013 15:03
How to use "block" and "yield" in Ruby.
#!/usr/bin/env ruby -w
class Card
attr_accessor :is_sync
def initialize options={}
@is_sync = options[:is_sync]
end
def is_sync?
@otobrglez
otobrglez / koordinate.rb
Created December 3, 2013 17:12
Using Hash and Array
#/usr/bin/env ruby
lokacija_a = {x: 10, y: 20}
lokacija_b = {x: 12, y: 22}
lokacija_c = {x: 13, y: 33}
# Novo polje z vsemi lokacijami
lokacije = [lokacija_a, lokacija_b, lokacija_c]
# Dodajanje lokacij
@otobrglez
otobrglez / category_image_uploader.rb
Created December 4, 2013 11:10
Simple Uploader for CarrierWave
# encoding: utf-8
class CategoryImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
def default_url
asset_path("fallback/" + [version_name, "category_image.png"].compact.join('_'))