Skip to content

Instantly share code, notes, and snippets.

View mfojtik's full-sized avatar

Michal Fojtik mfojtik

View GitHub Profile
def self.new(user_name, password, api_url, &block)
API.new(user_name, password, api_url, &block)
end
@mfojtik
mfojtik / config.ru
Created January 13, 2012 11:56 — forked from adjohu/config.ru
module Rack
class JSON
def initialize app
@app = app
end
def call env
status, headers, body = @app.call env
[status, headers, body.to_json]
end
end
@mfojtik
mfojtik / credentials.rb
Created February 7, 2012 11:16
deltacloud-client-valid-credentials
def self.valid_credentials?(user_name, password, api_url, opts={})
api=API.new(user_name, password, api_url, opts)
result = false
api.request(:get, '', :force_auth => '1') do |response|
result = true if response.code.eql?(200)
end
return result
end
@mfojtik
mfojtik / handle_backend_error.rb
Created February 7, 2012 11:19
handle_backend_error.rb
def handle_backend_error(response)
response_xml = Nokogiri::XML(response)
backtrace = (response_xml/'error/backtrace').empty? ? nil : (response_xml/'error/backtrace').text
raise BackendError.new(:message => (response_xml/'error/message').text,
:code => response.code,
:backtrace => backtrace)
end
@mfojtik
mfojtik / dsl_sample.rb
Created February 28, 2012 16:43
Deltacloud DSL example
@sample = Deltacloud::DSL::Task('launch some EC2 and RHEV-M instances') do
instances(:driver => :ec2, :username => '', :password => '') do
instance 'test-ec2-1' do
realm 'us-west-1'
image 'ami-12345'
profile 't1.micro'
end
instance 'test-ec2-2' do
@mfojtik
mfojtik / dmd_streams.xml
Created March 6, 2012 17:40
Markiza VOYO DMD stream
<item>
<title>Markiza VOYO</title>
<link>rtmp://195.168.10.68:1935/live swfUrl=http://voyo.markiza.sk/static/sk/shared/swf/flowplayer.commercial-3.2.4.swf?0.9358190796338022 live=true pageUrl=http://voyo.markiza.sk/lbin/player/LiveStream.php?channel=markiza&amp;r=0.5112703468184918 swfVfy=true playpath=markiza.sdp</link>
<thumbnail>http://www.lyngsat-logo.com/logo/tv/mm/markiza.jpg</thumbnail>
</item>
@mfojtik
mfojtik / show.rb
Created March 14, 2012 22:06
:show operation in Sinatra
get "/items/:id" do
@item = Item.find(params[:id])
halt 404 if @item.nil?
haml :'items/show'
end
@mfojtik
mfojtik / rabbit_example1.rb
Created March 14, 2012 22:29
rabbit_example1
require 'sinatra/base'
require 'sinatra/rabbit'
class MyApp < Sinatra::Base
include Sinatra::Rabbit
get '/' do
redirect '/images'
end
@mfojtik
mfojtik / cond_routes.rb
Created March 14, 2012 22:48
Conditional routes in Rabbit
class MyApp < Sinatra::Base
include Sinatra::Rabbit
collection :instances do
operation :reboot, :if => reboot_supported? do
# ...
end
end
end
@mfojtik
mfojtik / subcollections.rb
Created March 14, 2012 22:51
Sub-collections in Rabbit
class MyApp < Sinatra::Base
include Sinatra::Rabbit
collection :buckets do
collection :blobs, :with_id => :bucket_id do
description "Blobs are binary objects stored in buckets"
# GET /buckets/:bucket_id/blobs/:id
operation :show do