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
#! /usr/bin/env ruby
# Scrape the user list of forums.opensuse.org to make a list of those
# who have posted at least LIMIT items, for use by the feed filter mentioned in
# http://mvidner.blogspot.com/2010/07/helping-newcomers.html
require "rubygems"
require "nokogiri"
require "open-uri"
LIMIT = 15
PERPAGE = 50
#! /usr/bin/env ruby
# in ruby 1.8, Enumerator is limited
require 'generator'
# 1234 -> [1, 2, 3, 4]
# but don't use a String
def digits(i, base = 10)
g = Generator.new do |g|
begin
@mvidner
mvidner / set_flag.pl
Created February 25, 2011 14:33
How to set/unset a flag in a space separated list?
#! /usr/bin/env perl
use strict;
use warnings;
use Test::Simple tests => 2 * 9;
use List::Util qw(first);
# In a space separated list of flags, set one flag on or off (add or delete it).
# Don't modify the list unnecessarily.
sub set_flag {
#!/usr/bin/env ruby
$data = IO.read(ARGV[0], 0x2400)
def check_contents_at(offset, contents, description)
size = contents.bytesize
raise "#{description} not found at offset #{offset}" unless $data[offset, size] == contents
end
EXIF_ORIENTATION = "\x12\x01\x03\x00\x01\x00\x00\x00"
#! /bin/sh
# Convert ancient YCP syntax:
# define TYPE NAME(ARGS) ``{ BODY }
# becomes
# TYPE NAME(ARGS) { BODY }
#
# usage: $0 foo.ycp
# or
# cd tree_to_find_ycp_in; $0
FINDARGS="-name *.ycp"
@mvidner
mvidner / fake-syslog-enable.diff
Created January 30, 2012 16:42
reducing swift unit test failures from 348 to 285 via changing the config map
diff --git a/.functests b/.functests
index 86abce3..7b5aa2b 100755
--- a/.functests
+++ b/.functests
@@ -1,4 +1,5 @@
#!/bin/bash
+set -e
nosetests test/functional --exe
nosetests test/functionalnosetests --exe
#!/usr/bin/expect
# usage: ssh-password mysecret command...
# where command is ssh user@machine
# or ssh-copy-id user@machine
# ...
match_max 100000
set timeout -1
set password [lrange $argv 0 0]
spawn {*}[lrange $argv 1 end]
# Look for passwod prompt
CFLAGS=`pkg-config --cflags dbus-1` -Wall
LDFLAGS=`pkg-config --libs dbus-1`
all: dbus-example
@mvidner
mvidner / qt-bold-menuitem.rb
Created October 2, 2012 15:52
first steps with Qt 4 + Ruby, wanting a menu item with bold text
#!/usr/bin/env ruby
require 'Qt'
app = Qt::Application.new(ARGV)
# Qt.debug_level = Qt::DebugLevel::High
menu = Qt::Menu.new
click = menu.add_action("Clickme")
click.connect(SIGNAL :triggered) do
@mvidner
mvidner / rbx-encoding-backslash-x.out
Created October 16, 2012 11:54
Ruby 1.9 encoding: "\xFF" 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 with 255.chr
ASCII-8BIT: � ("\xFF") 1 bytes
* A binary packet with "\xEE"
US-ASCII: � ("\xEE") 1 bytes
* Putting them together with String#+
An exception occurred running rbx-encoding-backslash-x.rb
undefined conversion for '"\xFF"' from ASCII-8BIT to US-ASCII (Rubinius::EncodingClass::Encoding::CompatibilityError)