Wednesday, May 29, 2013

Finding the culprit code for mysterious silent deletion

Today, I was debugging some complex code when I discovered that my files were being deleted at the end of my Rake task designed to make those files for me. It was silent, and although I attempted to debug it with system audit utilities like auditctl, and ausearch.  

For me, the closest those got me to my answer was this:
type=SYSCALL msg=audit(05/29/2013 16:24:10.000:900) : arch=x86_64 syscall=rmdir success=yes exit=0 a0=6bcbac0 a1=0 a2=902005 a3=858240 items=2 ppid=2027 pid=13399 auid=unset uid=ryanmt gid=ryanmt euid=ryanmt suid=ryanmt fsuid=ryanmt egid=ryanmt sgid=ryanmt fsgid=ryanmt tty=pts0 ses=4294967295 comm=ruby exe=/home/ryanmt/.rvm/rubies/ruby-1.9.2-p320/bin/ruby key=(null) 

Clearly, this wasn't enough to determine the source of the deletion code.  Conveniently, I was able to write in some pause code to my source files, then run
sudo chmod a=r DIRECTORY/SUBDIRECTORY 
to block the deletion of the generated files.  Success!  Now I am generating permission denied exceptions Errno::EACCES!

At the end of it, using
rake --trace
was enough to chase it down for me. Good luck coding!

Wednesday, June 29, 2011

Case switch statements

Thanks to my boss, I learned something I'd forgotten (more evidence for the wisdom of this blog) about the case statement. Here's my code:
case arr_of_structs.first[attribute]
when Float, Fixnum
out.puts "@attribute #{attribute} NUMERIC"
when String
out.puts "@attribute #{attribute} STRING"
when Array
out.puts "@attribute charges relational"
2.0.step(12, 0.5).each do |ph|
out.puts "@attribute charge_at_#{ph} NUMERIC"
end #ph.each do
out.puts "@end charges"
end #case
end # each do

This was failing because I had previously been comparing the .class of the attribute value to the string versions of each class name. This wasn't working, and that becomes clear when I was reminded that case uses the === operator for comparison. I don't really understand all the ramifications, but it is kinda explained here: http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html

Tuesday, June 28, 2011

Local gem referenced in Gemfile

When using the ubiquitous 'bundler' gem, you place references to the gems required for a package in the Gemfile which is used to load and automatically ensure the version control and requiring of libraries proceeds smoothly.  In actuality, it almost takes away your pain.  The one feature I wish it had is a parser that adds the version you are using and the gems you are calling and could add them to the Gemfile itself.  That would be a slick feature.

Anyway, the question I have this morning is how to reference a locally generated/installed gem.  Since most of the bundler functionality relies upon querying online repositories of gems like git, rubygems, ...

The solution is relatively simple.  You provide a path which contains a valid .gemspec.  Or, you can also explicitly specify the version of a .gem file for which to look.  http://gembundler.com/man/gemfile.5.html

Here is what I used:
gem 'isoelectric_calc_and_hist', '= 0.0.1',
:path => "/home/ryanmt/Dropbox/coding/isoelectric_calc_and_hist/"

Introduction

Well, I've been inspired by my graduate advisor, who has a blog that he uses to share little helpful snippets of code and instruction on how to solve problems he has solved.  So, I figured, for nothing more than my own reference, that I would write up the occasional explanation, knowing that I tend to forget things I've once known, and that this should let me solidify my own understanding and help when I forget things.  So, I imagine pretty much every other post will be code/computer/ruby related.