owb’s project

policy kit

Polkit (formerly PolicyKit) is a component for controlling system-wide
privileges in Unix-like operating systems. It provides an organized
way for non-privileged processes to communicate with privileged ones.
Polkit allows a level of control of centralized system policy. It is
developed and maintained by David Zeuthen from Red Hat and hosted by
the freedesktop.org project.

Can be used to give a certain user who runs the e.g. rails application required permissions


Sinatra is a free and open source software web application library and
domain-specific language written in Ruby. It is an alternative to
other Ruby web application frameworks such as Ruby on Rails, Merb,
Nitro and Camping. It is dependent on the Rack web server interface.

Designed and developed by Blake Mizerany, Sinatra is small and
flexible. It does not follow the typical model–view–controller pattern
used in other frameworks, such as Ruby on Rails. Instead, Sinatra
focuses on “quickly creating web-applications in Ruby with minimal

Can be used to build a light and easy to use webserver for client/server implementation

event machine

EventMachine is an event-driven I/O and lightweight concurrency
library for Ruby. It provides event-driven I/O using the Reactor
pattern, much like JBoss Netty, Apache MINA, Python’s Twisted,
Node.js, libevent and libev.

EventMachine is designed to simultaneously meet two key needs

Extremely high scalability, performance and stability for the most demanding production environments.
An API that eliminates the complexities of high-performance threaded network programming, allowing engineers to concentrate on
their application logic.

This unique combination makes EventMachine a premier choice for
designers of critical networked applications, including Web servers
and proxies, email and IM production systems,
authentication/authorization processors, and many more.



Implementing a Client/Server logic. Most difficult but fastest and ressource-saving option since the Client should be wirtten in plain C.

rails as root for syscalls

Easy but bad.



padrino + puma == lightweight

Padrino is a ruby framework built upon the excellent Sinatra Web
Library. Sinatra is a DSL for creating simple web applications in Ruby
quickly and with minimal effort. This framework tries to make it as
fun and easy as possible to code more advanced web applications by
building upon the Sinatra philosophies and foundations.

Can be a good solution in combination with puma (smallest webserver)

chef for cluster provisioning

Chef is a configuration management tool written in Ruby and Erlang. It
uses a pure-Ruby, domain-specific language (DSL) for writing system
configuration “recipes”. Chef is used to streamline the task of
configuring & maintaining a company’s servers, and can integrate with
cloud-based platforms such as Rackspace, Amazon EC2, Google Cloud
Platform, OpenStack and Microsoft Azure to automatically provision and
configure new machines.

Use it with Vagrant to setup predefined settings in a big(or small) cluster of VMs
Could also be a good solution, huh?

Read More

mutlithreading in ruby

thread1 = Thread.new do
  1.upto(10) {|x| sum = sum + x}
  puts("The sum of the first 10 integers is #{sum}")

thread2 = Thread.new do
  1.upto(10) {|x| product = product * x}
  puts("The product of the first 10 integers is #{product}")


While there is great power in multithreaded code, there is also a lot of danger. A
great way to introduce hard-to-find bugs into your programs is to allow two or more
threads to modify the same data structure at the same time. A good way to avoid this
and other race conditions and make your code thread safe is to use the Monitor class:

@monitor = Monitor.new
  @monitor.synchronize do
  # Only one thread at a time here...

Read More

jquery, morris, raphael => graphs

<link rel="stylesheet" href="http://cdn.oesmith.co.uk/morris-0.5.1.css">
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js"></script>
<script src="http://cdn.oesmith.co.uk/morris-0.5.1.min.js"></script>

<div id="myfirstchart" style="height: 250px;"></div>

new Morris.Line({
// ID of the element in which to draw the chart.
element: 'myfirstchart',
// Chart data records -- each entry in this array corresponds to a point on
// the chart.
data: [
{ year: '2008', value: 20 },
{ year: '2009', value: 10 },
{ year: '2010', value: 5 },
{ year: '2011', value: 5 },
{ year: '2012', value: 20 }
// The name of the data record attribute that contains x-values.
xkey: 'year',
// A list of names of data record attributes that contain y-values.
ykeys: ['value'],
// Labels for the ykeys -- will be displayed when you hover over the
// chart.
labels: ['Value']

Read More

more lambda, more procs

p = Proc.new { |x| puts x*2 }

The ‘&’ tells ruby to turn the proc into a block

proc = Proc.new { puts "Hello World" }

The body of the Proc object gets executed when called

lam = lambda { |x| puts x*2 }

lam = lambda { puts "Hello World" }

blocks cant be called standalone while procs and lambdas can.

Also important to know is that both procs and lambdas are actually Procs

proc   # returns '#<Proc:0x007f96b1032d30@(irb):75>'
lam    # returns '<Proc:0x007f96b1b41938@(irb):76 (lambda)>'


lam = lambda { |x| puts x }    # creates a lambda that takes 1 argument
lam.call(2)                    # prints out 2
lam.call                       # ArgumentError: wrong number of arguments (0 for 1)
lam.call(1,2,3)                # ArgumentError: wrong number of arguments (3 for 1)


proc = Proc.new { |x| puts x } # creates a proc that takes 1 argument
proc.call(2)                   # prints out 2
proc.call                      # returns nil
proc.call(1,2,3)               # prints out 1 and forgets about the extra arguments

They also treat the return statement differently.. but i dont care ;/

one step further:

def calculation(a, b, operation)
  operation.call(a, b)

puts calculation(5, 6, lambda { |a, b| a + b }) # addition
puts calculation(5, 6, lambda { |a, b| a - b }) # subtraction

Read More

lambda procs and blocks

If you want to pass a code block to a existing method you can use Procs

Key here is the ampersand &.
If we have a Proc object in a
variable and we want to pass it to a method that is looking for a code block, we can
convert the Proc object back into a code block by sticking an ampersand in front of it:

class Report

  attr_reader :title, :text
  attr_accessor :formatter

  def initialize(&formatter)
    @title = 'Monthly Report'
    @text = [ 'Things are going', 'really, really well.' ]
    @formatter = formatter

  def output_report
    @formatter.call( self )

HTML_FORMATTER = lambda do |context|
  puts(' <head>')
  puts(' </head>')
  puts(' <body>')
  context.text.each do |line|

puts(' </body>')

With our new Proc -based formatters in hand, we are ready to create some
reports. Given that we have a Proc object and the Report constructor expects a code
block, we need to stick an ampersand in front of our Proc object when we create a
new Report instance:

report = Report.new &HTML_FORMATTER

Read More

yields and blocks

In Ruby, methods may receive a code block in order to perform arbitrary segments of code.

When a method expects a block, it invokes it by calling the yield function.

This comes in hand when you want to iterate over a list or provide an own algorithm


class Person 
  def initialize( name ) 
     @name = name

  def do_with_name 
     yield( @name ) 

When you now invoke the Person class and pass a block

person = Person.new("johnlol")
person.do_with_name do |name|
   puts "Hey, his name is #{name}"

This would results obviously in

Hey, his name is johnlol

another example:

palin = %w(Lagerregal Rotor Otto Rentner)
person = Person.new(palin)
person.do_with_name do |name|
   puts name.reverse


Read More

rspec receive counts

expect(...).to receive(...).once
expect(...).to receive(...).twice
expect(...).to receive(...).exactly(n).times
expect(...).to receive(...).at_least(:once)
expect(...).to receive(...).at_least(:twice)
expect(...).to receive(...).at_least(n).times
expect(...).to receive(...).at_most(:once)
expect(...).to receive(...).at_most(:twice)
expect(...).to receive(...).at_most(n).times

Read More