Skip to content

Instantly share code, notes, and snippets.

View mvidner's full-sized avatar

Martin Vidner mvidner

  • SUSE
  • Prague, CZ, EU
View GitHub Profile
@mvidner
mvidner / rbx-encoding-ljust.out
Created October 16, 2012 12:23
Ruby 1.9 encoding: String#ljust forces US-ASCII
rbx-2.0.0-dev
Running with rubinius 2.0.0dev (1.9.3 9ad741f3 yyyy-mm-dd JI) [i686-pc-linux-gnu]
* A binary packet
ASCII-8BIT: � ("\xFF") 1 bytes
* Aligning before appending more data, with String#ljust
US-ASCII: � ("\xFF\x00\x00\x00") 4 bytes
* More data
ASCII-8BIT: � ("\xEE") 1 bytes
* Putting them together with String#+
An exception occurred running rbx-encoding-ljust.rb
@mvidner
mvidner / rbx-encoding-pack-zstar.out
Created October 16, 2012 12:31
Ruby 1.9 encoding: Array#pack('Z*') is not binary
rbx-2.0.0-dev
Running with rubinius 2.0.0dev (1.9.3 9ad741f3 yyyy-mm-dd JI) [i686-pc-linux-gnu]
* A binary packet
ASCII-8BIT: � ("\xFF") 1 bytes
* A unicode string
UTF-8: Václav Havel ("V\xC3\xA1clav Havel") 13 bytes
* Plan B
** Adding NUL
UTF-8: Václav Havel ("V\xC3\xA1clav Havel\x00") 14 bytes
** Forcing 8-bit
@mvidner
mvidner / quick_vm.rb
Created October 17, 2012 14:34 — forked from rubiojr/quick_vm.rb
Quick OpenStack Server Create with ruby Fog
#!/usr/bin/env ruby
#
require 'rubygems'
require 'fog'
%w{OS_PASSWORD OS_USERNAME OS_AUTH_URL}.each do |env|
if ENV[env].nil?
$stderr.puts "Missing #{env} environment variable."
exit 1
end
@mvidner
mvidner / var-const.rb
Created November 2, 2012 16:27
Ruby Variables and Constants
#!/usr/bin/env ruby
# Ruby Variables and Constants
module M
variable = 1
CONSTANT = 2
variable = 3
# IMMUTABILITY is not guaranteed
@mvidner
mvidner / dbus-pulseaudio.rb
Created November 19, 2012 16:56
Pulse Audio socket path with ruby-dbus
#! /usr/bin/env ruby
require 'rubygems'
require 'dbus'
b = DBus.session_bus
ps = b.service 'org.PulseAudio1'
po = ps.object '/org/pulseaudio/server_lookup1'
po.introspect
pi = po['org.PulseAudio.ServerLookup1']
a = pi['Address']
path = a.split('=').last
@mvidner
mvidner / ifcfg-eth0-tn.171
Created December 3, 2012 12:48
AutoYaST: network interface naming tests
BOOTPROTO='dhcp'
STARTMODE='auto'
@mvidner
mvidner / cli-dns-hostname.sh
Last active December 11, 2015 15:19
Testing FATE#312733 - hostname and nameservers via yast cli
#! /bin/sh
echo "1..2"
YASTCLI=/sbin/yast2
#####
newhn=atestinghostname
$YASTCLI dns edit hostname=$newhn
#! /usr/bin/env ruby
$deps = {
:network => [ :foo, :bar, :baz],
:foo => [:testsuite, :yast2],
:bar => [:yast2, :testsuite],
:baz => [:yast2, :testsuite],
:yast2 => [:testsuite],
:testsuite => []
}
{
module "Intermediate";
import "Modelist";
global void Hello() {
Modelist::Hello();
}
}
// https://github.com/yast/yast-ruby-bindings/issues/23
// Y2DEBUG=1 /usr/lib/YaST2/bin/y2base -l - ~/snippets/dummy-location.ycp UI |& grep SECRET
{
term dummy_data = `DataMap($[], $[], $[], "DEFAULT");
// YCP:
// [agent-dummy] snippets/dummy-location.ycp:8 LOGTHIS_SECRET_314 Read .target.bash "ls" "DEFAULT"
// RB:
// [agent-dummy] :0 LOGTHIS_SECRET_314 Read .target.bash "ls" "DEFAULT"
SCR::RegisterAgent (.dummy, `ag_dummy(dummy_data));
any a = SCR::Read (.dummy.target.bash, "ls");