technical
Syrlug Ruby Presentation
Submitted by mmorsi on Wed, 2010-07-07 01:07
Attached is the presentation I have prepared in both openoffice and text formats.
Syrlug Virtualization Presentation
Submitted by mmorsi on Sun, 2010-04-04 18:34
Attached is the presentation I have prepared as well as a list of useful packages to install and commands to run.
- mmorsi's blog
- Login to post comments
- Read more
ruby gem polisher
Submitted by mmorsi on Thu, 2010-01-14 18:28For anyone that missed it Pavol Rusnak had an excellent blog post on Fedora Planet regarding the current state of rubygems, specifically with gemcutter becoming the official rubygems source and the introduction of the new gemcutter webhook API to register callbacks to be invoked on gem updates. Also discussed is gem2rpm, which automatically converts a gem to a rpm specfile / srpm, and the need of a tool to bind those two components together.
Introducing Polisher which does just that, a rails based webapp that allows a user to add any number of gem sources, customize the packages they want to track, and register handlers to be invoked on certain gem events. Currently I have handlers to simply send an email, and/or generate a rpm artifact from the gem, and the interface is extensible enough so that anyone can add any event handler easily. I am currently working on a module that will automatically submit a bugzilla request for the gem/rpm. This will entail a feature akin to the 'dirty bit' discussed in Pavol's blogpost, for packages that need extra maintenance before submission, but polisher will still assist in the process in any case (and its possible we can develop a maintenance automation system which runs a maintainer's scripts to make changes to the package before bugzilla submission).
It is still early in development, the current state is the result of only a few days of coding, but I think it's already useful for the Ruby -> Fedora process. Lots of things still need to be added, there is no-multiuser support currently for example, but I'm already able to register callbacks for gemcutter gems, which upon being updated, get invoked.
Polisher is a webapp since the gemcutter webhook API takes a http url which to invoke w/ POST params on a gem update. Whoever will want to run this will need a public-facing domain to do so. I put a copy up on my personal domain, feel free to give it a try, just please don't try to stress test it ;-) (and forgive the simplistic interface, was going for functional/quick). polisher demo
At some point, if this takes off, it would be awesome to get some hosting space for the Fedora community, and to setup an automated Ruby->Fedora workflow engine, w/ maintainer intervention at the appropriate points.
The polisher source is licensed under the GPL and can be downloaded from github. I also pushed the polisher gem to the gemcutter repo and you can install it w/ gem install polisher provided you have a recent enough version of rubygems (w/ gemcutter officially part of the repo list).
Speaking of rubygems I've also pushed gems for several of my other projects including rxsd, simrpc, and motel, all of which are now available via gem install. Enjoy!
- mmorsi's blog
- Login to post comments
- Read more
RXSD
Submitted by mmorsi on Sun, 2009-12-13 05:41Just released RXSD (via github), a XSD <-> Ruby classes translator that makes use of Ruby's runtime introspection / reflection mechanisms to convert XML Schema Definitions to Ruby classes on the fly. Also supported is generating string Ruby class definitions (to be subsequently written to the filesystem) as well as a XSD metadata library / extendable builder interface to add output support for whatever language you need (python, c++, java, xml and other various formats, etc).
It's still pretty rough around the edges, I whipped it up in a little under a month (licensed under the LGPLv3+, so feel free to use it in proprietary apps, just make sure to publish the changes to RXSD itself back upstream), but most of whats there should be working. I'm going to keep hacking at it, mainly in part of a couple other things I'm doing, but also to improve features / support all around. This is my first project I'm hosting on github, so we'll see how that goes, from what I've seen it's pretty cool though (makes it very easy to share changes back / forth between projects).
As always, have at it!
- mmorsi's blog
- Login to post comments
- Read more
Creating a patch w/ Mercurial (hg)
Submitted by mmorsi on Thu, 2009-11-05 18:59Although I was a slow adopter, I am now an adamant git user. I won't go into all the details here, but git is a great distributed version control system (vcs), light years ahead of the last generation (cvs, svn), and honestly if it isn't too cost prohibitive, I would greatly recommend switching to it (the Linux kernel tree was moved to git, so I can't really see why anyone else wouldn't be able to).
Although I've never used it before, I've also heard alot of great things about the Mercurial (hg) distributed version control system. Recently one of the projects I was working on for work required me to use mercurial, so I've started getting up to speed.
One thing that took me a few minutes to discover is how to replate the git format-patch command w/ hg. eg with git, to see a list of all commits and then format a patch from the last one, run:
git log git log HEAD^ -p git format-patch HEAD^ git send-email 001-patchname.patch git send-email HEAD^ # alternatively
Doing the same w/ HG:
hg log # note this isn't paginated, a feature git has over hg imo hg log -r tip -p hg email -r tip
This is good starting place for those familiar w/ hg or git and are trying to use the other.
- mmorsi's blog
- Login to post comments
- Read more
Generating a random number in vim
Submitted by mmorsi on Wed, 2009-10-28 19:18In the department of things I've spent far too much time working on, I just wrote a vim script that allows you to automatically insert a random number into the file you're editing. It probably could use a little work, but does what I need it to do (easily generate random numbers for test fixtures). To use it yourself, add the following to your ~/.vimrc:
" generate random number at end of current line
function! s:Rand(max)
y a
redir @b
ruby << EOF
rmax = VIM::evaluate("a:max")
rmax = nil if rmax == ""
printf rand(rmax).to_s
EOF
redir END
let @a = strpart(@a, 0, strlen(@a) - 1)
let @b = strpart(@b, 1, strlen(@b) - 1)
let @c = @a . @b
.s/.*/\=@c/g
endfunction
command! -nargs=? Rand :call <SID>Rand(<q-args>)
nmap <F6> :Rand <CR>
nmap <F7> :Rand 100<CR>
nmap <F8> :Rand 100000<CR>When using vim, simply enter command mode and type :Genrand <maxnumber> to generate a random number and insert it at the end of the line. Alternatively, simply hit <F7> to generate and insert a random number between 1 and 100.
- mmorsi's blog
- Login to post comments
- Read more
Releasing Simrpc
Submitted by mmorsi on Fri, 2009-10-16 23:09Simrpc is a simple rpc implementation written in Ruby, relying on Apache QPID for the transport mechanism. I modeled it after Apache QMF, though nowhere near as complex (simrpc is procedural based for example, with data structures only encapsulating data, and not methods), intended to be a placeholder until QMF becomes a bit more stable.
I was able to whip it up pretty quick, it only took me a week to write end-to-end, and thus I'm releasing it under the MIT License instead of my usual favorite, the AGPL. Eventually its a possibility that I might rewrite it in C++ as there isn't anything ruby-specific in it and I could easily then after write a Ruby wrapper (or any other).
Have at it!
- mmorsi's blog
- Login to post comments
- Read more
oVirt use case to look out for
Submitted by mmorsi on Wed, 2009-10-14 16:14Sometimes all you need is a good nights rest, I spent a considerable amount of time on this problem yesterday only to realize the solution was very simple.
Watch out when running the oVirt server on an vm, with your guest network set to the libvirt 'default' network on your host machine. The oVirt server depends on / will install libvirt and run libvirtd in your vm. Thus upon your first post-install restart, you will have the libvirtd default network interface, addressed at 192.168.122.1 running in your vm. Since various packets coming from the libvirt interface on your _host_ machine will have that same address, their responses will never make it back, rather they will goto the libvirt interface on your _vm_ and be subsequently discarded.
You most likely will notice this issue if you use tcpdump and you are receiving lots of ARP requests for your MAC from ip on your guest interface but no responses. Even running tcpdump on the libvirt network interface won't yield the responses, as even though their being sent there, that address just resolves to the local machine, and the kernel just processes the packets it already has.
To resolve this either just stop the libvirt daemon running on your oVirt vm (sudo service libvirtd stop) or use another network other than the "default" as one of the two for your libvirt server vm. Hope this helps!
- mmorsi's blog
- Login to post comments
- Read more
More ActiveRecord Funkiness
Submitted by mmorsi on Mon, 2009-10-12 21:46Another caveat to look out for when using activerecord, especially for those of you who are using the nested set module and have optimistic locking turned on (which I'm guessing by the timestamp on that patch is making its ways to the Linux repos just about now).
It turns out when you go to destroy a model object in a nested set, it first updates the lft and rgt attributes before running the correct delete query against the db. eg
UPDATE "pools" SET lft = CASE WHEN lft > 13 THEN (lft - 2) ELSE lft END, rgt = CASE WHEN rgt > 13 THEN (rgt - 2 ELSE rgt END WHERE (1 = 1)
....
DELETE FROM "pools" WHERE "id" = 8 AND "lock_version" = 0
....
Unfortunately when optimistic locking is enabled (as it seems to be by default now), activerecord will detect the record has already been updated before it attempts to destroy it and will throw a "StaleObjectError" reporting "Attempted to delete a stale object". The object being used to perform the update, no longer reflects the current db state (granted it's only "lock_version", the db field used to perform lock checks, that is inconsistent, but that is enough to throw it off).
The only work around which I know of right now, save fixing ActiveRecord itself, is to use delete instead of destroy, which obviously is not optimal and doesn't work for all cases. I need to look into this issue some more myself, and will follow up with a better fix if I find it. Until then this also may help
- mmorsi's blog
- Login to post comments
- Read more
Bit of weirdness with ActiveRecord
Submitted by mmorsi on Wed, 2009-09-30 20:26Figure I'd pass on a bit of weirdness concerning Ruby's ActiveRecord. Apparently when two models class are associated via rails the association takes place through a custom ActiveRecord association class, eg if a host model has many instances of the nic model, host.nics will be an instance of ActiveRecord::Associations::AssociationProxy and _not_ a mere array of nics. AssociationProxy acts very similarily to an array, providing the expected functionality to get/set associated classes.
All of this is as expected, the weirdness arising from the fact a call to host.nics.class would return the 'Array' class and not 'AssociationProxy'. This is because AssociationProxy hijacks many methods and uses them for its own purposes, including the 'class' method.
To access an array from an instance of AssociationProxy, merely call the 'all' method, eg
host.nics.all.find { |nic| some_test }
Trying to call the 'find' method on nics directly will result in an ActiveRecord error: "Couldn't find Nic without an ID" as the AssociationProxy find method is called instead of the one you want.
- mmorsi's blog
- Login to post comments
- Read more





