Archive

Archive for the ‘code’ Category

simple is beautiful – command line id3 tagging

March 16th, 2008 ahmedre No comments

generally speaking, my set of mp3s is very well tagged. for my personal mp3s, i used to exclusively use easytag to tag them, and now i use a combination of easytag and amarok (which is totally awesome by the way!)

but sometimes, i have to mass edit id3tags for mp3s on the server, and i don’t have the luxury of using such gui tools for the editing. as thus, i’ve been mainly using id3v2 within some perl scripts to tag mp3s. this turns out to work great, but i also wanted to be able to add album art to the mp3s from the command line.

i couldn’t figure out how to do it using id3v2 (perhaps using the custom frames, there’s a way, but nothing extremely simple and obvious from what i was looking at). then i found the solution in the form of a id3lib-ruby, a ruby wrapper for id3lib, the same library that id3v2 is based on.

with this, everything turns out to be extremely easy -

require 'id3lib'

tag = ID3Lib::Tag.new('myfile.mp3')
cover = {
   :id => :APIC,
   :mimetype => 'image/jpeg',
   :picturetype => 3,
   :data => File.read('cover.jpg')
}

tag << cover
tag.update!

and that’s it. nice and simple. by the way, a picturetype of 3 denotes a front cover and is the default value (just learned that from a quick search). oh and the output mp3 image cover shows up fine in both linux and on itunes. beautiful!

Categories: code Tags: , ,

dealing with timezones in php

March 13th, 2008 ahmedre No comments

so i was working on some code in which i needed to know whether or not it was dst for a given country and/or timezone or not. luckily, with php5.2, some sparsely documented (yet very useful) classes were introduced – a more thorough documentation can be found here.

so let’s say i want to know whether or not egypt is in dst right now or not… so first i need to know what zoneinfo file egypt uses (for egypt, it’s simple, but this trick is useful for more obscure places, like “isle of man,” for example):

cd /usr/share/zoneinfo
grep -i egypt iso*.tab        # get the iso country code for egypt

# the above command returns 'EG' - so...
grep EG zone.tab
# returns 'Africa/Cairo'

in many cases, there are many timezones that exist for a given country. in many cases, it’s obvious which file you need, but in some cases, it’s not very obvious. in those cases, i found it helpful to open the binary files and look at the very last line, in which some hint about the offset of the timezone is given.

anyway… once you have the zoneinfo file that you would use, it’s very easy to find whether or not you are in dst (well, assuming that you know what the standard, non-dst offset from utc is). for example:

$tz = new DateTimeZone('America/New_York');
$date = new DateTime();
$date->setTimezone($tz);
echo $date->;format(DATE_RFC3339) . "\n";
echo $date->getOffset()/3600 . "\n";

running this returns the time in new york, and the offset (-4). since the standard est offset is -5 hours, -4 means we’re +1 which means we are currently on dst.

so if you don’t know the standard offset, another trick that you could do is pass some parameters to the new DateTime() constructor – so for example…

$tz = new DateTimeZone('America/New_York');
$date = new DateTime('2008-12-31');
$date->setTimezone($tz);
echo $date->getOffset()/3600 . "\n";

this returns -5, which is out of dst. anyhow, you could use the above if you don’t know the default offset for a timezone for dst by passing in 2 dates – something towards the middle of the year (july-ish) and something towards the end of the year (december-ish). if the offsets are different, the place probably has dst.

also, do note that some places have things a little differently – so dst in windhoek, namibia, for example, ends in april and starts in september.

Categories: code Tags: ,

sublime rhymes for the times

February 5th, 2008 ahmedre No comments

launched my second facebook app: sublime rhymes! still a little rough around the edges, some things can be a little more intuitive, but for now, i am going to sleep :)

Categories: code, technology Tags: ,

behind the times…

January 30th, 2008 ahmedre No comments

today, i discovered that the quranapp i’d written for facebook has been broken for some time now (mainly due to the changed notification apis, which affects both notification sending and invites). so i’ve finally updated it and it properly works again.

i actually kind of like their changes – their new invite form and friend selector are pretty simple to use and are very feature full (not to mention well documented), and not having to catch return types from sent messages and forward to a confirmation page is always a very nice thing ™.

i guess sometimes, you can’t just write software and forget about it :)

Categories: code, technology Tags: ,

nice bash tip

January 20th, 2008 ahmedre No comments

i never really used this until i ran into this article by accident, but it’s fairly cool…

so:

echo {one,two}.sh

outputs:

one.sh two.sh

this means that you can, as the article says, do something like this:

cp /etc/apache2/httpd.conf{,.bak}

to backup your apache conf. cool huh? the article has more details and such, but that’s just a summary.

Categories: code Tags: ,

quranicaudio.com redone!

September 4th, 2007 ahmedre 2 comments

keeping the seo statements from the previous post in mind, audio.islamicnetwork.com has become http://quranicaudio.com/ — it is now running on lighttpd (rather than apache – by the way, so far, i really like lighty masha’Allah) and al7amdulillah, so far, things look good.

quranicaudio.com is one of the web’s largest (if not the largest) collection of cd quality downloadable quran mp3s (and some oggs). check it out!

Categories: code, technology Tags: , ,

lessons learned through writing a facebook app

July 31st, 2007 ahmedre 6 comments

a long time ago, when facebook opened its api, i wrote a Quran application for facebook [see my previous post, here]. however, it was a hack, wasn’t fully featured, it didn’t look great, and, most importantly, it wasn’t put on the facebook application directory. sometime later, someone launched a Quranic Verses application – it was much nicer, more feature rich, and, most importantly, it was in the application directory.

feeling a bit competitive, i spent most of my past weekend rewriting, adding viral features suggested by my friends, and polishing the app. after three days of hard work, i finally launched. its been one day now since i launched, and here’s what i learned:

  1. being first to market is a huge competitive edge – i started out with around 40 user, whereas the other app has about 24,000. regaining the lost share of users will be extremely difficult.
  2. on the same note as the above, it seems as though getting to the market first is more important in some ways than what you bring to the market. if your product is the only one out there, people will use it, even if it has problems. once they start using it, the chances that they leave yours and use another one are slim. even if a competitor comes out, you can just improve your app and keep the market share.
  3. features aren’t always what you think they are – some features that you think are critical and awesome won’t be used by anyone at all – other features that you think are useless will be used a lot. its actually pretty odd, the one feature that i thought would be the selling feature of my app has gotten no usage by anyone except me, and the one feature i left out is the only one anyone asked me about.
  4. connections are important – a person who knows how to spread a viral app can do it, and can work wonders for your app and users. a solid and passionate user base can help your app grow, but without it, nagging can only take you so far. also, your connections can give you really good ideas and valuable user feedback that’s hard to get otherwise.
  5. its amazing how much you can get done in such a short period of time when you have a burning desire and passion to get something done.
  6. from a technical stand point, certain things may seem daunting at first, but a solid will to succeed makes these technical hurdles surmountable.
  7. even if something didn’t turn out quite the way one expected, there’s always some benefit to be taken out of it – so take the benefit, learn from the negatives, and move on :)

so yeah… i guess that about covers it… i still have a hope that the unused feature will be used and i can start a wildfire of users adding the app, but at the same time, i am being realistic and sticking to point 7 above by writing this blog post and consciously thinking about these matters.

Categories: code, technology Tags: ,

scraping websites…

June 26th, 2007 ahmedre No comments

many times, i find myself having to scrape a website for any particular reason. now a days, if i need to do it, i’d probably do it with some version of mechanize (www::mechanize in perl, hpricot in ruby, etc). when i was looking for a bug in one of the scrapers i’d written a long time ago, what took me by surprise was that i’d written a lexer to do it.

i guess this was shortly after i’d taken “languages and interpreters” in college, in which we used [f]lex and yacc/(bison). i just figured it was interesting, after working with a technology, that we try to utilize it. its not necessarily a bad way to do things, i just would do things differently now…

Categories: code Tags:

quran facebook application

June 15th, 2007 ahmedre No comments

i figured i’d play around with the facebook api today, so i wrote a little facebook quran app for displaying verses from the quran on your profile page. not very polished if i should say so myself, but… it works (at least for me). if you try it, please let me know if you find any bugs or have any feature suggestions.

you can test it here: http://facebook.cafesalam.net/quranapp.

Categories: code, islam, technology Tags: ,

zomg lolcats ftw!

May 29th, 2007 ahmedre No comments

this is off the hook!

HAI
CAN HAS STDIO?
PLZ OPEN FILE "LOLCATS.TXT"?
	AWSUM THX
		VISIBLE FILE
	O NOES
		INVISIBLE "ERROR!"
KTHXBYE

they actually have a few test interpreters for it and more examples here.

Categories: code Tags: