All a man needs out of life is a place to sit ‘n’ spit in the fire.

Category: Technology (Page 2 of 4)

Tech tips, howto’s and other writings mostly concerning with Linux and Open Source or Free Libre Open Source Software (FLOSS)

Gutenberg.org

I’ve been using and abusing Gutenberg.org a lot lately.  It’s a web site dedicated to public domain books, mostly in English but there is variety in other languages too including Beowulf in Old English.  You can basically find anything you want that was published before 1923.  They have ebook formats, pdfs, html documents, and a lot of audio books submitted by supporters.  All the classics are there.

I’ve been reading Edgar Rice Burroughs’s Tarzan and John Carter of Mars books to the kids at bed time.  I loved those books as a kid and now despite limited library space and an unwillingness to store any more books in this house, I can read the classics to my heart’s content.

So here’s the work flow:  Download a book at gutenberg.org, open it up in konqueror or firefox and when you come upon a strange archaic word pop it into your kdict public domain dictionary reader and peruse several different definitions and usage entries.  I’m simply amazed at how awesome the public domain is and how many volunteers have come together to make it all possible.  Consider donating to gutenberg.org.

I just noticed that the character of Tarzan went into the public domain in 1998.  Is it a coincidence that Disney’s movie was released in 1999?  Hmmm.

Valentine’s Day for that Special Someone: Creating a Video Ringer for the Samsung Rant m540

I just got a new phone, and I wanted to customize it with some of my favorite things: my wife and songs that remind me of her, one being her incoming ring of course.  I don’t care much for any other calls, but when my love calls, my heart skips a beat, so here we go.

First, select a photo.  I choose this one because she’s smiling at me and looks lovely.

­

Next, I took a short video in order to reverse engineer the video format of the Samsung Rant m540.  Turns out the sound is AAC, 128 kbps, and the video is mpeg-4 (reports as DIVX) and the frame size is 176×144 and the rate is 15 fps.

I want to create a video with a still picture along with a song by NEK called, "Laura no está" – the sentiment of the song is that Laura is not there, but in her absence, I am tormented, she is everywhere.  I am unable to escape.  Honey, your feet must be tired, because you’ve been running around in my head all day.  Chuckle.  So I want to loop a 16 second sample of that song (the refrain) along with the above still picture.  Turns out that ffmpeg (in Linux) will help you out tons.  Check out the following gem:

­ffmpeg -loop_input -vframes 240 -r 15 -f image2 -i foo.jpg -i foo.wav -s 176x144 -f mp4 -acodec libfaac bar.m4v

-loop_input causes the image to repeat throughout the clip.  -vframes 240 is 16 seconds multiplied by 15 frames per second to give total frames.  -f image2 is from the man page of ffmpeg and and forces a format.  Specify two inputs -i foo.wav and -i foo.jpg a frame size -s 176×144, and video format -f mp4 an audio codec -acodec libfaac (you have to compile ffmpeg with libfaac support) and the output file bar.m4v.

Take the resulting video file and copy it to the directory /dcim/100ssmed/ of your phone’s memory card.  I think you have to rename the file to sspx000(?).3g2 where the "?" represents a sequential number.  I had trouble getting the video to play properly at first, but I think it’s because I had the frame rate slightly off.  I don’t know, however, because I changed the frame rate and the file name at the same time and the thing started playing, so I’m unsure which was the cause, the frame rate or special sequential internal naming of the Rant m540.  Dunno, maybe I’ll mess around with some more and post my results here.

So there you go.  Now every time my love calls, I am greeted with her smiling face and a song. 

HDR Photo Forays

I’ve been messing around with Qtpfsgui, a High Dynamic Range (HDR) photo tool for Linux, Mac, and Windows. There are number of processes that on­e can invoke to increase the dynamic range of photos from RAW captures or multiple tripod exposures, but first, an example.

This was taken at dusk at a hotel pool in Rio Grande, Puerto Rico.  Very scary sky.

The basic concept is that your camera can’t really capture a bright sky with a dark landscape.  Set the exposure for your land, and the sky is washed out.  Lower your exposure for the sky, and the land comes out too dark.  Wouldn’t it be nice if you could combine the two and fudge the photo to look more like your eye sees it?  The best way is with a tripod and multiple exposures with different settings, but I’m lazy and I want results NOW.

If you’re shooting RAW in your digital camera, you can capture a little bit more dynamic range than what you see when you export it to a jpg.  Try using an HDR tool to pull out a little more dynamic range or, in my case, heavily process it to give you that funky black velvet painting effect.  Meh, whatever floats your boat.  A lot of people seem to like these images.  ‘Course people seem to loathe them too.

The original photo looks like this:

It’s a nice photo, but the first one is quite dramatic, no?

Here’s another dramatic shot of the Mississippi and Missouri River confluence, shot on a cold day in December from the Missouri side.

My First Forays into Typesetting with Latex

I’ve been busy copy-editing and typesetting Laura’s doctoral dissertation. I’ve always been a fan of Donald Knuth and his obsessive work in typesetting with Tex. Since my beloved wife is a Stanford Student, I figured, cool, I’ll use TeTex (Latex) to publish the thing, kinda like an homage to the their text publishing tradition. Also to thumb my nose at the Computer Science graduate students who don’t think anyone outside of their department uses TeTex/Latex. They provide a Microsoft Word Template for the rest of the school. Screw that.

Latex is not for the faint of heart, though. The text markup language has a pretty steep learning curve, but once you get the hang of it, you won’t know how you lived without it.

First: Here is what you get with a Latex source document.

  • Auto generated/indexed/enumerated list of tables and figures, complete with hyperlinks (in the PDF generated version) to their appropriate section
  • All the enumeration happens regardless of where the table is. You cross reference based on a reference flag, not text. So for example, you don’t write out, "see table 2.1" you just create a label to your table like so, giving it a human readable name (although it could be anything):

    \caption{\label{tab:Articles-with-Language}
    Articles with Language as Subject}

    and then you reference your table like this:

    The high percentage of articles on Language present
    in this local news section in contrast to a
    low percentage on Education (Table \ref{tab:Articles-with-Language})

    You never have to remember what table or figure number goes where with what table or chapter or whatever. You also don’t have to manually update your list of tables or figures. This lets the researcher get to the business of writing their paper rather than screwing around with formatting, which, let’s be honest, occupies a vastly disproportionate amount of the researcher’s time.

  • Benevolent Stanford students have graciously provided a complete thesis Latex style to take care of formatting for print/ebook publication. Even/Odd margin stuff is taken care of for you. Smart beautiful justification and hyphenation, footnoting, contents, etc is formated and beautifully handled.
  • Laura gets to write her stuff in OpenOffice, export it to Latex and I then format with Stanford’s thesis style sheet.

Here’s what it looks like:

screenshot.png

Now that I’ve gotten into this a bit, I’m addicted. I’ve seen how other people have published ebooks and to tell you the truth, they get them pretty wrong. There is no cross referencing, no hyperlinks to the sections, no footnote links, table links etc. In addition, with Lyx (frontend editor to Latex) you get to separate out your chapters, sections etc and have multiple people work on or copy edit at the same time. Since each is but a text file, you can use a source code versioning system like Subversion or CVS to track changes. This allows you to publish tight updated versions and divide up the work.

I highly recommend Lyx, Latex for any sort of professional publishing. It’s makes maintaining long documents of any sort simply a breeze.

My Thoughts on Bottom Posting

Well, they (my thoughts) are mostly unprintable, but I will strongly express my position on bottom posting.

It sucks.

But first, a bit of history:

The top posting, bottom posting debate has been mostly won by the bottom posting folks, that is, when replying to an email, your response should go after the quoted portion of the original email.

That’s caca – big stinky pungent steaming caca.

First, if the email was lengthy, you must scroll for ages to even get to your response. Second, the assertion that bottom posting "conserves" the flow of the conversation and is more "right" is also caca. The flow of the conversation is contained in your threaded mail reader. You do use a threaded mail reader, right? The threaded mail reader will preserve the flow of the conversation just fine, thank you, without all the fuss and muss of quoted portions above and below and all around.

My reasons for top posting (in email… doing so in Usenet will get you keel-hauled) is that my response is the most relevant portion of the email. My response is the reason I am sending said email. If the recipient is too lazy to look at his last email to discern to what I am replying, I have included a snippet of relevant text after my important response for reference’s sake. It is just a little reminder, not the important portion of the email. Bottom posters just don’t seem to get this, little bottom feeders that they are.

I get it, I really do. You are so humble, so meek, so respectful in your correspondence that your pathetic little response must be relegated to the tail end of the email. You suck. I don’t want to do business with you. I would rather do business with someone who has the balls to believe his words mean something and places them at the top of the email accordingly.

Got it?

I understand that this is a sensitive topic for many programmers and Open Source developers and furthermore that the convention of "bottom posting" or "bending over and taking up the rear" has won the day. I understand that top posting is frowned upon in public discussion forums. I disagree of course. Again, your Usenet reader is threaded, right? If you need to bottom post, I think you are an idiot, but I am outnumbered, so I acquiesce. You shall, however, not have the pleasure of enforcing upon me your flagrant disregard for common sense and decency by encroaching upon my personal email habits.

In my email I will top post. I will defend my top posting. I will throw down with anyone that wants to start a flame war on the subject.

I am prepared to defend myself.

Security for Windows Guys

P.J. and I discussing some of the confounding requests we get from windows admins as we try to protect them from themselves:

"Yeah, it’s like, ‘I want you to secure it, but I also want be able to do every stupid thing I can think of.’"

P.J Cabrera

 And there you have it in a nutshell the security problems with Microsoft users.
 

Cowon iAudio F1 Personal Music Player

iaudio_f1.jpg

I just have to comment on this great little addition to my technology array. The personal music player, Cowon iAudio F1, rocks. I love it, even if the 22 hour advertised battery life only lives up to around 13. But, it plays ogg vorbis, mp3, wma, is super small, does voice recording, has 1 Gigabyte of flash memory, is an FM tuner, records FM radio, and "line in" too all for around $125.00. This little baby rules. I’ve had it for around 6 months now, and I think it’s fabulous, small, and powerful. Highly recommended. No iPods for me, unless I hack it with RockBox… which I might do, btw.

Screw Linux on the Desktop, I Used to be Productive

I don’t want my desktop all candified.  I don’t want media.  I don’t want games.  I don’t want music.  I don’t want VOIP.  I don’t want chat.  I don’t want digg, reddit, and slashdot.

ARRRRRGGGGGGGHHHHHH!

I used to be productive.  Now I have MAME to emulate all my favorite standup video games from the eighties and nineties (endless hours of fun).   I now have instant messaging, every manner of music, video, and entertainment imaginable (not to mention all that P2P goodness and without the spyware).  MythTV handles the PVR functions and let me tell you, it’s great. 

It’s too great.

The problem is, I need to do some friggin’ work on this computer.  I remember when the desktop was austere.  I was forced to work, not goof off watching stupid video clips from video.google.com or www.youtube.com

HEY YOU MEATHEADS stop messing with the desktop.  It’s too good.  It’s too distracting.  Firefox is too good.  There are too many great extensions.  Mplayer is the best media player on the planet.  Stop it, now! 

I need to do some WORK!

Please make my desktop the non-functioning piece of utilitarian crap that it was five years ago, please please please?

 

I beg you. 

Procedural Flash Animation in Linux

Pardon me while I geek out again. This particular article falls under the, "look Ma, no hands" category, a shameless play for adoration of my cleverness. What I’m about to show is neither new nor terribly beautiful, nor cost effective for most professional flash designers and/or web designers.

It’s just cool that it was done procedurally and entirely on Linux. First, another caveat; I absolutely do not get these animation tools with their tweening, paths and visual interactions for creation ­of animations. For some reason, when I animate my stupid brain sees a stack of cells, straight up and down. I see the frame changes like a flip book. If I try to­ abstract an object in the animation into some sort of mathematical formula, line, path, or whatever, my little pile of gray matter goes all slushy. Also, my brain likes to see things in text. I know, I know, what’s the matter with me? I don’t even see the code. All I see is blonde, brunette, red-head. Chuckle.

Here’s the finished product: www.og-consulting.com

The door scene modeled in POV-ray scene description language and is typical of Old San Juan, Puerto Rico Spanish Colonial architecture. The real doors are beautiful. If you ever get a chance to take a cruise from/to Puerto Rico, don’t miss the chance to walk around Old San Juan ­(El Viejo San Juan) and check them out. I rendered three frames with the doors rotated from 0 to 75 degrees to simulate… guess what? Opening doors. Clever, huh?

There’s a lot of POV code, here’s a little bit of what it looks like:

cylinder { <0, 0.5, 0>, <0, -0.5, 0>, 0.5
        texture {
        pigment { color rgb <0.6, 0, 0> }
        normal { granite 0.02 turbulence <0.5, 0.9, 0.2> scale 0.25 }
        finish { specular 0.1 reflection .1 }
    }
  }

It’s pretty simple. You place objects in an X-Y-Z space (Cartesian coordinates) like a sphere, cylinder, box or any other of the predefined primitives. You can merge them, subtract them, intersect them in creative ways. Finally, you apply some sort of texture which includes a pigment, a surface (normal), and a finish (reflections effects etc). There are easier ways to model, but sometimes POV-ray’s scene description language is just the most elegant and easiest way to model something.

The next step was to convert the png files to jpegs for inclusion in the flash animation. I used a little sprinkle of bash and a dash of kosher ImageMagick’s convert.

for file in *.png; do convert -quality 100 "$file" "${file%.png}.jpg"; done

For each png file, convert the png file to a 100 percent quality jpeg file. We use 100% quality because I’m going to let the swftools take care of the final compression. There’s no sense in lossy compressing then lossy compressing again. That’s just crazy talk.

We will now create the flash source file. Open a new file slideshow.sc. This is the textual language for the swftools Linux Flash toolkit. I have never ever ever looked at a flash source file from any Macromedia product, so I have no idea if this animation description method looks/acts/walks/talks in anyway shape or form like Macromedia’s products. Don’t know, don’t care.

.flash bbox=640x480 filename="slideshow.swf" version=6 fps=25 compress background=white

  .jpeg s1 "puerta_open03.jpg"
  .jpeg s2 "puerta_open02.jpg"
  .jpeg s3 "puerta_open01.jpg"
  .font font "gilc____.ttf"
  .font arial "arialbi.ttf"
  .text text1 text="Opening Doors" font=font
  .text text2 text="Opening Doors" font=font
  .text text3 text="Opening Doors" font=font
  .text text4 text="OG" font=arial
  .text text5 text="Experts in" font=font
  .text text6 text="Open Source" font=font

  .put s1 scalex=640 scaley=480 alpha=100%
  .put text1 scale=100% x=40 y=220 alpha=0%

  .frame 25
  .put s2 scalex=640 scaley=480 alpha=0%
  .change text1 alpha=100%
  .put text2 scale=100% x=40 y=220

  .frame 100
  .change s2 alpha=0%
  .change text1 alpha=100%
  .change text2 alpha=100%

  .frame 125
  .change text1 alpha=0%
  .change text2 alpha=100%
  .change s2 alpha=100%
  .put s3 scalex=640 scaley=480 alpha=0%
  .put text3 scale=100% x=40 y=220

And so on (that’s not the whole file, but the rest is just repetition. There are 71 total lines of code for that little flash animation. Is that a lot or a little? Seems pretty small to me anyway. Basically, with swftools you define an object (image, or text); you put it; then you change it. You can change its fade, size, location, and more. The swfc program will implement the change from the object’s last known state. Check out swftools for more examples (that’s where I got all the reference I needed to make my little flash thingie).

So there you have it. I walk through the frames, changing elements, putting, fading, growing, moving stuff around. It’s was all described from start to finish in a procedural language, from the POV-ray scene description language, to bash and ImageMagick for command line image manipulation, and finally to swftools flash scene language for the final animation. Pretty nifty, huh?

The neat thing about this is that once the procedure has been developed, you can reuse it for other clients, other looks, colors, messages, etc. In fact, you could directly render it on the server to update information on the fly via end user input. There’s no limit to what you can do with something like this.

Of course if you’re on Windows, you would probably just buy Macromedia’s software… but where’s the fun in that?

Ruby on Rails – Insert Multiple Child Records

Yes, I understand this is going to be a weird post for some of you.  Frankly, I haven’t been writing enough about what I spend most of my day doing, so here it is.

­I have been having a bafflingly hard time trying to figure out the proper way to insert multiple child records from one single webform.  It is the standard fare for posting things like invoice headers and details.  Say for example, you’ve got an invoice record which consists of an order number, date and whatnot.  That particular piece of tabular data is then considered the parent of its child line items (product_id, description, quantity, price, etc).  So you’ve got this Order which consists of an invoice and line items. 

It’s pretty basic, but I’ve had the hardest time figuring out how to do this is Ruby on Rails.  I know it’s not hard in theory, but with Rails, since there is only One Right Way(TM) to do things, ’cause you’re on Rails, it takes a bit of doing to figure out this Right Way(TM).  I personally don’t have a problem doing it Rails’ way, but please dear God, just tell me what it is.  I bought the book and everything.

So here’s the dope, folks.  Please correct me if there’s a better way of doing this, ’cause I’m a Rails n00b.  For reference sake, I am using Ruby on Rails 1.0 with Postgres 8.0.4 and Ruby 1.8.4

First the webform:

<ul id=items>
   <% for item in @items %>
   <li><%= check_box_tag 'line_item', item.id, checked=false, {:name => "line_item[item_id][]", :id => "line_item_id_#{item.id}" }  %><label for="line_item_id_<%= item.id %>"> <%= item.title  %></label></li>
   <% end %>
</ul>

Make sure to use check_box_tag instead of check_box.  check_box holds a hidden text input that by default inserts a 0 into the database.  From http://rubyonrails.org/api/classes/ActionView/Helpers/FormHelper.html

The checked_value defaults to 1 while the
default unchecked_value is set to 0 which is convenient for
boolean values. Usually unchecked checkboxes don’t post anything. We
work around this problem by adding a hidden value with the same name as the
checkbox.

You don’t want that.  You want the plain vanilla check_box_tag which does none of that nonsense, because you in fact, don’t want your line_item table being filled with up with all kinds of line_items referring to product "0" or product "NULL".

So that’s our form.  The line <% for item in @items %> comes from the items.rb model and is just a little database query to get all the items associated with a particular order for posting in our invoice.  Why would we use checkboxes?  Well, maybe we’re not going to invoice the whole order.  Maybe we’re out of some items.  We’ll let our warehouse guy check off the checkboxes on his wireless pda.  How’s that?

If you were watching closely, you’ll notice that I modified the check_box_tag behavior with options of my own with the following:

:name => "line_item[item_id][]"

This is what gives us multiple lines (an array of items) to pass to the controller.  [] is the important part.

Now, so far this is easy, or at least I thought so.  I’ve done this a hundred times in php, but that’s just the problem, I got tired of writing and re-writing this.  I wanted Rails to handle all the parent child relationships for me and leave me alone.  I’m lazy.

But I couldn’t figure out exactly how to do this.  Frankly, I’m still trying to fit all the method/class/object/instance/variable blah blah blah into my head and keep all the Invoice invoice invoices straight.  I know, I know, it’s probably me, but I’ll wager there are a few more slow-witted programmers out there for whom this is all so confusing.  A phrase that I have been becoming more familiar with while working in Ruby on Rails is, "Use the force."  It’s funny, but most of the time when I relax and make stuff up without trying to "understand,"  things usually Just Work(TM).  Jedi Programming… who knew?

So we’ve got our form.  Now we need to post the parent and the children in one fell swoop.

Now for the model (no, not Victoria’s Secret):  Invoice will not reference the children (the children will come running when they hear their parent’s voice regardless of whether they are called by name).  The parent "has_many" children and does not bother remembering their names or ids or anything.  The children on the other hand "belong_to " (or reference) the parent and are tattooed with the parent_id stamp of ownership (big ears for example).   When they are required, they will all line up under the parent and file out like good little children.

Got it?  Parent -> has_many :children, Child -> belongs_to :parent – the model of a perfect Catholic Rails family.

Now we need to post the stuff.  This is a snippet from the invoice_controller.rb:

   def create
      @invoice = Invoice.new(params[:invoice])
      @invoice.order_id = @session["order_id"]
      for item_id in params[:invoice_item][:item_id] do
              @invoice.invoice_items << InvoiceItem.new(:item_id => item_id)
      end
      if @invoice.save
         flash[:notice] = 'Invoice was successfully created.'
         redirect_to :action => 'list'
      else
         render :action => 'new'
      end
   end

order_id is stored in the session array and is used to reference the invoice.  The invoice in turn has items added to it for each item_id in the params passed from our form.  What happens on @invoice.save is the following:

  1. Rails inserts the invoice header (the parent)
  2. Immediately fetches currval(invoices_id_seq) to retrieve the newly created invoice_id
  3. Uses that invoice_id number and iterates over the invoice_items inserting both the item_id and invoice_id
  4. commits the results if successful

That’s it!  Easy, huh?  Well it took me all day to figure it out.  I knew it was easy, but perhaps I don’t have mad google sklz or something, because it left me scratching my head.  Hopefully someone will find this useful.  Leave a comment and I’ll do my best to answer your questions.  If not, I’m sure I’ll forget it in a few months and have to reread this *G*.

« Older posts Newer posts »

© 2024 El Gringoqueño

Theme by Anders NorenUp ↑