Older Entries »

Tecate and Artichoke Haiku

Summer is now here.
wild artichokes
Desert rapidly blooming.
tecate in the sun
Tecate Sunset.

FLV Duration in Ruby

There is a lack of decent open source FLV manipulation software out there. There is Yamdi which is a seriously awesome metadata injector, written in C, and then there is FLVTool2, which is a ruby based injector tool. FLVTool2 is really awesome, but it is a serious memory hog and 90% of the files I work with are >1gb size.

I am doing some house cleaning on one project and I have a need to quickly get the duration of an flv video file, but without loading the whole thing into memory, or even reading in the whole file. As an advantage to me, all the files in question have already been injected by yamdi, so the duration is already calculated and inserted into the files. I just need to read it, and be on my merry way.

Here it is:

def duration(filename)
    f = File.open(filename, 'r')
    raise "Could not open File!" unless f

    #check for flv text
    unless f.read(3) === 'FLV'
      raise "This does not seem to be an FLV file."
    end

    #check to make sure we are a video
    f.seek(3)
    is_video = f.read(1).unpack("H*").first.hex
    unless is_video == 1
      raise "This FLV file does not contain video."
    end

    #seek to end, get size
    f.seek(0, IO::SEEK_END)
    length = f.tell

    #calculate tag length
    f.seek(-4, IO::SEEK_END)
    taglen = f.read(4).unpack("H*").first.hex

    #finally get duration
    f.seek(length - taglen, IO::SEEK_SET)
    duration = f.read(3).unpack("H*").first.hex.to_f/1000

    f.close()
    #duration returns in seconds
    duration
  end


I ripped this out of another one of my classes that is already dealing with the flv file in other ways, so there is more validation in place than you see here. This has only been tested with files injected with yamdi 1.3 and 1.4, I have not tested with anything else, but if anyone does please let me know!

If you are interested in doing this in php there is similar scripts here which helped me greatly.

Chevy's Chipotle Salsa

Chevy's makes some mean chipotle salsa. It is so good I have tried to replicate it many times. Tons of other people have too. I think I have finally landed on what I think is the recipe:

Ingredients:

  • 5 really fresh medium sized tomatoes
  • 2-3 green jalapenos or 4-5 red jalapenos
  • 1/4 white onion
  • 2 cloves fresh garlic
  • 3 tablespoons fresh cilantro
  • 2 tablespoons white vinegar
  • 1.5 caps of liquid smoke
  • Olive Oil
Ok, so first things first, lightly coat all of your jalapenos and tomatoes with olive oil. Don't coat so much that its dripping off, or you will start a fire on the bbq. After they are well coated, put them on grilling type of sheet and put them in the bbq on medium heat. Leave the stems on the jalapenos and take them off the tomatoes. I use a pan like the one you see here on the right. I prefer to cook them for 20-40 minutes, or until there is lots of crispy looking blackness. Unlike other recipes, this will go straight into the salsa, to provide the correct color and flavor.

Now let the roasted veggies rest for a bit and cool down. Once they are room temperature or cooler, remove the stems and the seeds from the jalapenos. Do nothing to the tomatoes. If there was any liquids inside of the jalapenos, leave this out of your salsa.

Lastly, put all the ingredients into the food processor, and puree for only 5 seconds. It should be medium-chunky at this point, you can keep puree'ing if you need it less chunky. You may or may not need to add a dash of salt.

This should be pretty middle of the road for this recipe. You can always add more jalapenos if its not spicy enough, or more liquid smoke if its not smoky enough.

Enjoy!

Redmine2Twitter with isgd

So as it goes, there were a couple bugs, so I took the opportunity to fix them, and also add some additional features. In this revision we include more of the redmine message that goes along with the activity update as permitted, and then we run the direct link to the redmine page through is.gd for each issue and attach this to the tweet. Additionally I quickly optimized things and made it send is.gd https urls to redmine for my convenience. You can check it out on the second page.
Continue Reading -->

Redmine2Twitter

What do you do when you have mail, instant messages, rss feeds, web pages, text messages and revision control to all keep up with? Myneid came up with an idea of getting redmine updates from within twitter, so I took a crack at it:

#!/usr/bin/env ruby
require 'rubygems'
gem 'feedtools'
gem 'htmltokenizer'
require 'feed_tools'
require 'html/htmltokenizer'
require 'twitter'

#your redmine url
feed_url = "http://redmine.yourcompany.net/projects/activity?format=atom&key=YOURRSSKEY"

#grab redmine data
feed = FeedTools::Feed.open(feed_url)
post_these = Array.new

#fetch salient pieces from this stream
feed.items.each do |act|
  tweet =  "#{act.title}"
  t = HTMLTokenizer.new(act.description)
  desc = String.new
  unless ARGV[0].nil? or ARGV[0] != 'full'
    while token = t.getTag('p')
      desc << t.getTrimmedText('p').gsub(/\n/, ' ')
    end
    tweet << "\t#{desc[0..137]}..."
  end
  if act.time >= 5.minutes.ago
    post_these << tweet
  end
end

#connect to twitter if we need to
if post_these.size > 0
  twitter = Twitter::Base.new('YOURTWITTERUSERNAME', 'YOURTWITTERPASSWORD')
end

#post the oldest first
for tweet in post_these.reverse
  status = twitter.post(tweet)
end


Beware, this script has no real error checking, but as long as your credentials and access key are all correct it should be golden. You will need the feedtools, twitter, and html tokenizer gems to get it to run.

I run this from cron every 5 minutes. As long as the redmine server and the server that the cron is run from both have accurate system clocks it should work well. A more elaborate version some day may include more error checking and dupe checking.

Have fun out there.

Older Entries »

Tag cloud

  1. 1 entries are tagged with 2007
  2. 1 entries are tagged with 2008
  3. 2 entries are tagged with applevalley
  4. 1 entries are tagged with archlinux
  5. 1 entries are tagged with artichoke
  6. 1 entries are tagged with automation
  7. 1 entries are tagged with bigsur
  8. 5 entries are tagged with burningman
  9. 1 entries are tagged with christmas
  10. 4 entries are tagged with code
  11. 1 entries are tagged with cplusplus
  12. 1 entries are tagged with desert
  13. 1 entries are tagged with drinks
  14. 1 entries are tagged with dspam
  15. 2 entries are tagged with dunes
  16. 1 entries are tagged with energy
  17. 1 entries are tagged with esplanade
  18. 5 entries are tagged with europe
  19. 1 entries are tagged with evdo
  20. 2 entries are tagged with flv
  21. 1 entries are tagged with gadgets
  22. 1 entries are tagged with government
  23. 1 entries are tagged with haiku
  24. 1 entries are tagged with internetradio
  25. 2 entries are tagged with losangeles
  26. 1 entries are tagged with motivation
  27. 1 entries are tagged with moving
  28. 1 entries are tagged with newserver
  29. 1 entries are tagged with obama
  30. 1 entries are tagged with productivity
  31. 1 entries are tagged with rails
  32. 3 entries are tagged with recipe
  33. 1 entries are tagged with redmine
  34. 2 entries are tagged with reflections
  35. 8 entries are tagged with ruby
  36. 1 entries are tagged with salmon
  37. 1 entries are tagged with salsa
  38. 3 entries are tagged with site
  39. 2 entries are tagged with snow
  40. 1 entries are tagged with tecate
  41. 1 entries are tagged with thanksgiving
  42. 6 entries are tagged with travel
  43. 1 entries are tagged with trip
  44. 1 entries are tagged with turkey
  45. 3 entries are tagged with twitter
  46. 1 entries are tagged with website
  47. 2 entries are tagged with work
  48. 1 entries are tagged with x4200
  49. 3 entries are tagged with yz250

Twitter Updates

Links to check out

Subscribe RSS