Old Emmanuel Oga's Weblog (new one is at www.emmanueloga.com)

Moving home to a jekyll powered home site: www.emmanueloga.com

Posted in ruby by emmanueloga on octubre 25, 2010

My new home is at www.emmanueloga.com

I got bored of having to use the quirky little wordpress textarea to type stuff. Is much more fun to type my blog posts in my favourite editor instead of having to mess around with the markup on wordpress (or blogger, or any other web based editor that does not behave like vim :-/). That’s why I’m using github pages (powered by jekyll) now.

My new home is at www.emmanueloga.com. Yeah I might change the domain name at some other time. For now, please endure the funny prefix. The proper domain name works too, but it redirects to the www. version. Trust me, there is a very good reason for the “www.” prefix (and that is a boring story).

Anuncios

YAAAY we finished our #railsrumble entry!!!

Posted in ruby by emmanueloga on octubre 17, 2010

Background processing yaaaay! :-)

Posted in ruby by emmanueloga on octubre 17, 2010

First 6 hours of rumble

Posted in ruby by emmanueloga on octubre 16, 2010

So basically spent the first “stage” (6hours) of the rumble installing the system, initiating the rails application, creating deploy scripts,  initial database setup/deploy, and creating a project on PT / checking some PT tasks. By this time I could have had 6 more hours of sleep if I had put the PT tasks in advance,  used puppet or chef, and used a template for the rails app. Being that I’m the only one working on the app right now I cannot show you much progress, but, the screenshot is attached. NOTE TO MY SELF FOR NEXT RUMBLE: do some homework before it starts! 🙂

I’m just gonna hit the sack and continue to work tomorrow with my buddy.

first commit

Posted in ruby by emmanueloga on octubre 15, 2010

EPIC

First Commit

Rumble 2010

Posted in ruby by emmanueloga on octubre 15, 2010

Ok, first rumble I participate in. My team

http://railsrumble.com/teams/carbon-based-lifeforms

Let’s see what happens. Installing the system as first step.

Pretty printing xhtml with nokogiri and xslt

Posted in ruby, xhtml, xml by emmanueloga on septiembre 29, 2009

[UPDATE]

Check this gist for a command line version of  xml indenter in this post.

Today I was looking for a way to pretty print xhtml. Good’ol REXML supports this in a very simple way:

Document.new("<some>XML</some>")doc.write($stdout, indent_spaces = 4)

This generates a nicely indented xml document. But REXML was not robust enough for my needs. Luckily, we now have a couple of excellent choices on ruby for parsing xml, including hpricot, nokogiri and libxml-ruby bindings.

I did not find a way to pretty print xhtml as easy as you can do with REXML with any of these libraries, though. But I did find a way of doing it using XSLT. Nokogiri supports applying XSLT to an XML document (probably libxml bindings do too, hpricot does not). Here is how:

    xsl = Nokogiri::XSLT(File.read("pretty_print.xsl"))
   html = Nokogiri(File.read("source.html"))
   File.open("output.html", "w") { |f| f << xsl.apply_to(html).to_s }

That’s it, simple enough. Got the idea from this dzone snippet.

For the xslt file I used this nice one I found on this site: http://www.printk.net/~bds/indent.html

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output method="xml" encoding="ISO-8859-1"/>
  <xsl:param name="indent-increment" select="'   '"/>

  <xsl:template name="newline">
    <xsl:text disable-output-escaping="yes">
</xsl:text>
  </xsl:template>

  <xsl:template match="comment() | processing-instruction()">
    <xsl:param name="indent" select="''"/>
    <xsl:call-template name="newline"/>
    <xsl:value-of select="$indent"/>
    <xsl:copy />
  </xsl:template>

  <xsl:template match="text()">
    <xsl:param name="indent" select="''"/>
    <xsl:call-template name="newline"/>
    <xsl:value-of select="$indent"/>
    <xsl:value-of select="normalize-space(.)"/>
  </xsl:template>

  <xsl:template match="text()[normalize-space(.)='']"/>

  <xsl:template match="*">
    <xsl:param name="indent" select="''"/>
    <xsl:call-template name="newline"/>
    <xsl:value-of select="$indent"/>
      <xsl:choose>
       <xsl:when test="count(child::*) > 0">
        <xsl:copy>
         <xsl:copy-of select="@*"/>
         <xsl:apply-templates select="*|text()">
           <xsl:with-param name="indent" select="concat ($indent, $indent-increment)"/>
         </xsl:apply-templates>
         <xsl:call-template name="newline"/>
         <xsl:value-of select="$indent"/>
        </xsl:copy>
       </xsl:when>
       <xsl:otherwise>
        <xsl:copy-of select="."/>
       </xsl:otherwise>
     </xsl:choose>
  </xsl:template>
</xsl:stylesheet>
Tagged with: , , ,

Linux: moving around files with white spaces on the path name

Posted in ruby by emmanueloga on agosto 11, 2009

I have a couple of big hard drives on my desktop PC. Still, from time to time I need to do some maintenance to get rid of all the junk I throw at them. Lately, I’ve been moving files around a lot. And I was doing it all wrong! I set the laziness aside and thought about ways of improving my “work flow”.

Whitespace, go away!

The first issue I had is that bash gets confused when the filenames include white space.


[emmanuel@going_merry ~/files]
$ ll
total 4
-rw-r--r-- 1 emmanuel users 2818 2009-08-11 11:38 This is my afn.py

[emmanuel@going_merry ~/files]
$ mv This is my afn.py afn.py
mv: target `afn.py’ is not a directory

[emmanuel@going_merry ~/files]
$ mv This\ is\ my\ afn.py afn.py

Notice the slashes I had to add on the second mv call. This might seem pretty obvious. Bash usually puts those slashes automatically when using tab completion. But the thing is, what I really need in my case is to move a whole set of files returned by other utility, like find, to another place:


[emmanuel@going_merry ~/files]
$ ll
total 8
drwxr-xr-x 2 emmanuel users 4096 2009-08-11 11:41 dir1
drwxr-xr-x 2 emmanuel users 4096 2009-08-11 11:41 dir2

[emmanuel@going_merry ~/files]
$ find dir1/
dir1/
dir1/My afn 1.py
dir1/My afn 2.py

[emmanuel@going_merry ~/files]
$ find dir1/ | xargs -I {} mv {} dir2
mv: cannot stat `dir1/My afn 1.py’: No such file or directory
mv: cannot stat `dir1/My afn 2.py’: No such file or directory

The problem here is in the find output. The list of  path names returned by find may have unescaped spaces on path names. I needed to escape those spaces before using those path names with other utilities. I looked around for a unix utility to help me in this regard, but not easily finding anything good around, I just wrote a little ruby script for dealing with this: “escapepath”.


[emmanuel@going_merry ~/files]
$ which escapepath
/usr/bin/escapepath


[emmanuel@going_merry ~/files]
$ cat `which escapepath`

#!/usr/bin/ruby
require 'shellwords'

while not STDIN.eof?
  puts(STDIN.gets.chomp.shellescape)
end

gist

Now I can do things like:


[emmanuel@going_merry ~/files]
$ find dir1/ -type f | escapepath | xargs -I {} mv {} dir2/


If you are typing too much, you are not aliasing enough

An anti-pattern I was using was… typing a lot. I kept running again and again things like:

[emmanuel@going_merry ~/files]
$ ack -a -f | grep thing_i_want_to_find -i | escapepath | xargs -I {} mv {} /some/directory

…to find several files at once using a case insensitive regular expression and move all of them to a certain directory. The solution: bash aliases:


[emmanuel@going_merry ~/files]
$ cat ~/.bashrc

# ...
alias xmv='escapepath | xargs -I {} mv {}'
alias ifind='ack -a -f | grep -i'
# ...

Note: ack is a cool alternative to find+grep which also has some nice file finding features. Check it out.

Know I can do things like:


[emmanuel@going_merry ~/files]
$ ifind thing_i_want_to_rm | xargs rm
[emmanuel@going_merry ~/files]
$ ifind thing_i_want_to_move | xmv /some/directory

Ah! much more easy on my poor fingers…. 🙂

Locos por Rails Conference in Buenos Aires, Argentina

Posted in people, rails, ruby by emmanueloga on enero 23, 2009

Badge Locos X Rails Conference

Por fin!, una conferencia de ruby y rails en Argentina! La misma se realizará el 3 y 4 de Abril en la Universidad de Palermo, C.A.B.A. Estan cordialmente invitados. La inscripción no ha empezado todavía, pero si pueden mandar sus propuestas para disertar en la misma.

Locos Por Rails Conference 2009 will be held on April 3rd and 4th in Buenos Aires, Argentina. Registration is not open yet, but the call for papers is already open. Send yours!

Tagged with: , ,

facebooker gem outdated on rubyforge

Posted in ruby by emmanueloga on diciembre 8, 2008

If you are building a facebook applicaction using facebooker gem, beware the version of the gem in rubyforge is outdated. The easier way to deal with this is to clone the github repo of facebooker and install the gem from there.

  1. git clone git://github.com/mmangino/facebooker.git
  2. cd facebooker

Then:

  1. rake gem
  2. cd pkg
  3. sudo gem install facebooker-[insert-version-here]

UPDATE

But this won’t work… the updated method is:

  1. rake gemspec
  2. gem build facebooker.gemspec
  3. sudo gem install facebooker-[insert-version-here]

At this point, the lastest version on github is 0.9.9 1.0.8!!! (0.9.5 in rubyforge), and this is a version you are going to need because of this commit.

UPDATE:

Although the procedure above still works, you may find it easier to install the gem directly from github, now that its gemspec has been made github-compatible:

  1. gem sources
  2. sudo gem sources –add http://gems.github.com (if it is not already listed when you run step 1)
  3. sudo gem install mmangino-facebooker

…although because of github gemspec security policy, the gem there is _not always_ the lastest…

Tagged with: