Skip to content

Instantly share code, notes, and snippets.

View mfojtik's full-sized avatar

Michal Fojtik mfojtik

View GitHub Profile
@mfojtik
mfojtik / restclient.py
Created February 16, 2011 14:26
Simple REST client to use with DeltaCloud API
from httplib2 import Http
from urllib import urlencode
import libxml2
class RestClient:
"""A simple REST client library"""
def __init__(self, api_url, api_user, api_password):
self.url, self.user, self.password = api_url, api_user, api_password
self.client = Http()
@mfojtik
mfojtik / deltacloud_teambox_irc_bot.rb
Created March 14, 2011 17:20
Deltacloud Teambox bot
require 'rubygems'
require 'cinch'
require 'json'
require 'pp'
require 'rest-client'
def client(uri)
RestClient::Resource.new("https://teambox.com/api/1/#{uri}", 'x', 'x')
end
@mfojtik
mfojtik / identica.rb
Created May 3, 2011 12:34
Posting status update to Identi.ca
require 'rest-client'
class Identica
attr_reader :client
def initialize(username, password)
@client = RestClient::Resource.new("http://identi.ca/api", username, password)
end
@mfojtik
mfojtik / bitly.rb
Created May 3, 2011 12:34
Using bit.ly API to shorten URL
class Bitly
attr_reader :client
def initialize(username, password)
@username, @password = username, password
@client = RestClient::Resource.new('http://api.bitly.com/v3')
end
def shorten(url)
require 'rubygems'
require 'cinch'
require 'nokogiri'
require 'pp'
require 'rest-client'
FEED_URL="https://www.aeolusproject.org/redmine/activity.atom?key=296155b7b55159144a341f198e5909d24cd003ea"
def feed
client = RestClient::Resource.new(FEED_URL, '<username>', '<password>')
@mfojtik
mfojtik / koji.rb
Created October 18, 2011 16:29
How to query Koji in Ruby
require 'xmlrpc/client'
require 'pp'
server = XMLRPC::Client.new2("http://koji.fedoraproject.org/kojihub")
result = server.call "search", "deltacloud-core", "build", "regexp"
pp result
@mfojtik
mfojtik / vsphere_cdrom.rb
Created November 4, 2011 13:41
Add CDROM to Vsphere VM
require 'rubygems'
require 'rbvmomi'
machine_conf_spec = RbVmomi::VIM.VirtualMachineConfigSpec(
:deviceChange => [{
:operation => :add,
:device => RbVmomi::VIM::VirtualCdrom(
:key => 2,
:connectable => RbVmomi::VIM::VirtualDeviceConnectInfo(
:startConnected => true,
@mfojtik
mfojtik / course.rb
Created November 8, 2011 13:44
Ruby course RSS scapper
require 'open-uri'
require 'nokogiri'
module Course
class RSSSource
attr_accessor :url
attr_accessor :xml
def initialize(url)
self.url = url
@mfojtik
mfojtik / scapper2.rb
Created November 8, 2011 14:24
Ruby course RSS scapper mail
require 'open-uri'
require 'nokogiri'
require 'pony'
#sudo gem install pony
module Course
class RSSSource
attr_accessor :url
attr_accessor :xml
module Helpers
def operations_for_collection(collection)
collections[collection].operations.values.select { |op| op.has_capability?(driver) }
end
end