Skip to content

Instantly share code, notes, and snippets.

View vmoravec's full-sized avatar

Vladimir Moravec vmoravec

View GitHub Profile
@vmoravec
vmoravec / mkcloud.yml
Last active August 29, 2015 14:14
Example of mklcloud config that will be parsed and passed to bash script
mkcloud:
cloudid: default
TESTSHEAD: 1
source: develcloud5
nodes:
- os: sle12
role: compute
hv: xen
- os: sle11sp3
@vmoravec
vmoravec / irb3.rb
Last active August 29, 2015 14:10 — forked from peterc/irb3.rb
#!/usr/bin/env ruby
# encoding: utf-8
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using RVM)
#
# By Peter Cooper, BSD licensed
#
# Main dependency is term-ansicolor for each impl:
# rvm exec gem install term-ansicolor

Business Models

Advertising

Models Examples
Display ads Yahoo!
Search ads Google
@vmoravec
vmoravec / systemd_service_test.rb
Last active August 29, 2015 14:00
Test for stop and restart
context "Restart a service on the installation system" do
it "restarts a service with a specialized inst-sys helper if available" do
File.stub(:exist?).with('/bin/service_start').and_return(true)
service = SystemdService.find("sshd")
SCR.stub(:Execute).and_return({'stderr'=>'', 'stdout'=>'', 'exit'=>0})
expect(service).not_to receive(:command) # SystemdUnit#command
expect(service).to receive(:stop)
expect(service).to recieve(:start)
expect(service.restart).to be_true
end
@vmoravec
vmoravec / add-on-map.rb
Created January 10, 2014 15:51
Find why it maps false
AddOnProduct.add_on_products = Builtins.maplist( AddOnProduct.add_on_products) do |prod|
media = Ops.get_string(prod, "media_url", "")
pth = Ops.get_string(prod, "product_dir", "/")
if String.StartsWith(media, "relurl://")
base = AddOnProduct.GetBaseProductURL
media = AddOnProduct.GetAbsoluteURL(base, media)
Builtins.y2milestone("relurl changed to %1", media)
end
Ops.set(@sources, media, Ops.get(@sources, media, {}))
# set addon specific sig-handling
# USAGE: Hash.from_xml:(YOUR_XML_STRING)
require 'nokogiri'
# modified from http://stackoverflow.com/questions/1230741/convert-a-nokogiri-document-to-a-ruby-hash/1231297#1231297
class Hash
class << self
def from_xml(xml_io)
begin
result = Nokogiri::XML(xml_io)
return { result.root.name.to_sym => xml_node_to_hash(result.root)}
# USAGE: Hash.from_libxml(YOUR_XML_STRING)
require 'xml/libxml'
# adapted from
# http://movesonrails.com/articles/2008/02/25/libxml-for-active-resource-2-0
class Hash
class << self
def from_libxml(xml, strict=true)
begin
XML.default_load_external_dtd = false

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Modules

Namespace for classes and modules that handle serving documentation over HTTP

@vmoravec
vmoravec / spark.rb
Created September 4, 2013 21:44 — forked from jcromartie/spark.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# prints a sparkline in the terminal using the supplied list of numbers
# examples:
# spark.rb 10 20 30 100 90 80
# spark.rb 1 2 0.4 0.1 1.3 0.7
@ticks = %w[▁ ▂ ▃ ▄ ▅ ▆ ▇]
values = ARGV.map { |x| x.to_f }

TL;DR

Unicorn was by far the best performing (5.94 trans/sec over the 1-minute test, 352 total). Puma (3.95 trans/sec, 235 total) appeared to perform no better than Webrick, despite the default behavior of using up to 16 threads. Perhaps increasing its worker count to the number of cores will improve its performance.

I've tried to run multiple Puma workers with the workers directive (per their sample documentaiton), but I receive errors about undefined method 'workers' for #<Puma::Configuration::DSL:0x007ffca4bde798>).

Webrick

Server

$ bundle exec rails server