This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Prawn | |
module Errors | |
exceptions = %w[ FailedObjectConversion InvalidPageLayout NotOnPage | |
UnknownFont IncompatibleStringEncoding UnknownOption ] | |
exceptions.each { |e| const_set(e, Class.new(StandardError)) } | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contact = Struct.new(:first, :last, :email) | |
p Contact.new(*%w[James Gray james@grayproductions.net]) | |
# >> #<struct Contact first="James", | |
# last="Gray", | |
# email="james@grayproductions.net"> | |
p Contact.new(*%w[James Gray]) | |
# >> #<struct Contact first="James", last="Gray", email=nil> | |
p Contact.new("James") | |
# >> #<struct Contact first="James", last=nil, email=nil> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'airbrake' | |
Airbrake.configure do |config| | |
config.api_key = '092f2e6780f7c9117353d28dbe8486a3' | |
config.logger = Logger.new STDOUT | |
end | |
params = { 'blah' => 'blah', 'deeper_level' => {'stuff' => 'stuff', 'array' => ['a', 'b', 'c'] } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dir["*.rb"].each { |f| puts f } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# downloading content from the web | |
require 'open-uri' | |
url = 'http://blog.stackoverflow.com/audio/stackoverflow-podcast-001.mp3' | |
open(url).read.to_file(url.split('/').last) | |
# And boom, you’ve downloaded the file to “stackoverflow-podcast-001.mp3” |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# napisi program u kojem korisnik unosi neke brojeve od 1 do n i ispisuje zbroj neparnih brojeva | |
puts "Upisite n:" | |
n = gets.chomp.to_i # gets => čitanje sa tipkovnice dok ne stisneš enter | |
# chomp => makni enter s kraja stringa ("\n") - jer smo stisnuli enter i dodali ga | |
# to_i => pretvara string u broj | |
# nek sad krene unosit tih n brojeva | |
brojevi = (1..n).map { gets.chomp.to_i } # <3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Nes | |
{ | |
public static void main(String[] args) { | |
String a = "lastavice trče"; | |
for (int i=0; i < a.length(); i++){ | |
if (i % 2 != 0){ | |
a = a.substring(0,i-1) + "&" + a.substring(i, a.length()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Exceptional::Remote.error(Exceptional::ExceptionData.new(RuntimeError.new, "Test Exception")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'rubygems' | |
require 'httparty' | |
require 'net/http' | |
require 'base64' | |
set :dump_errors, false | |
class Representative | |
include HTTParty |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Base | |
def call | |
'call' | |
end | |
end | |
p Base.new.call #=> "call" | |
# Monkeypatching "works" but doesn't provide access to #super |