Archive for the ‘code’ Category

scratching my head over a c problem…

Thursday, May 17th, 2007

today, i wanted to try out my test arabic gtk program to see if behdad's new changes to pango magically fixed the renown arabic shaping issue [in short, it had nothing to do with it]. anyway, i discovered that i needed to install libquran, and to make a long story short, my test program, which used to work before, segfaulted. i ran gdb and valgrind only to find the segfault happening within libquran at the closing of the configuration file (noting this libquran code hasn't been changed in 3 years now).

i looked at the source, and discovered that the file pointer was becoming null after a call to getline. i tried to see if i could reproduce this in a smaller test program, and i discovered that i indeed could -

please click here to see the program code, i am tired of trying to get the formatting right with igSyntaxHiliter and/or with the wp code editor, and i am also tired of dealing with dreamhost not letting me post an fopen function call because mod_security flags it as an emergency error and returns a 503...

the program displayed the first line from testfile, but unexpectedly displayed that fp is null and segfaulted at the fclose. checking the return from getline, i see that it returns successfully (the number of characters it read).

while i got around this problem by modifying the library to do a malloc followed by an fgets, i am just confused -this library code hasn't been touched in 3 years, it used to work before, and i just repulled it from cvs when i discovered this. so why is it broken now? the only thing that i can think of being different is that my box now runs a 64 bit version of linux, but would that break it?

any ideas?

ruby and rcairo

Wednesday, May 9th, 2007

i've recently been playing more and more with ruby and i really like it. at the same time, i've been loving launchy, an open source application launcher for windows (currently using it on my work laptop).

since i love launchy so much, i started to wonder, "why not write something similar for linux?" - now i know one will say that deskbar does the job, but its not quite the same. so anyway, because i wanted transparency and so on, i decided to look into cairo, and the rcairo ruby bindings.

here's a screenshot of what i've been playing with so far:

rcairo demo

note the very right side is the part showing of my open gvim window. while i have yet to organize the code and start writing it for real, the ruby file i have is a proof of concept of all the required pieces i can think of (cairo wise anyway) working together.

namazTime update

Sunday, September 17th, 2006

soner eker emailed me some beautiful graphics and a redone ui for namazTime, so i redid the ui based on what he sent me. you can see the screenshot here.

a quranic aim bot

Wednesday, August 16th, 2006

so i was a little bit bored today, and i wanted to write a simple quranic aim bot just for fun... so i took a look at Net::Oscar off cpan and at a sample bot, wrote a sample alpha api to allow searching over quranic realm, and the result:

(02:06:20) ahmed: 3:1
(02:06:21) chisaikaruma:
match: ayah="1"
Transliteration: Alif-lam-meem
Sahih International: Alif, Lam, Meem.


(02:06:23) ahmed: say if you love Allah
(02:06:24) chisaikaruma:
match: sura="3" ayah="31" percent="100"
Transliteration: Say (O Muhammad SAW to mankind): "If you (really) love Allah then follow me (i.e. accept Islamic Monotheism, follow the Quran and the Sunnah), Allah will love you and forgive you of your sins. And Allah is Oft-Forgiving, Most Merciful."
English: Qul in kuntum tuhibboona AllahafattabiAAoonee yuhbibkumu Allahu wayaghfirlakum thunoobakum wallahu ghafoorun raheem


(02:06:42) ahmed: bismillah alrahman alraheem
(02:06:43) chisaikaruma:
match: sura="1" ayah="1" percent="84"
Transliteration: Bismi Allahi arrahmani arraheem
English: In the name of Allah, Most Gracious, Most Merciful.

match: sura="27" ayah="30" percent="84"
Transliteration: Innahu min sulaymana wa-innahu bismiAllahi arrahmani arraheem
English: "It is from Solomon, and is (as follows): 'In the name of Allah, Most Gracious, Most Merciful:


i am not quite sure as to whether or not i can send utf8 strings over this or not... i couldn't get arabic results to work from the tiny bit i tried. it still needs some work, but its just a for-fun prototype/proof of concept. i think the greatest benefit was being able to put together an alpha version of an quranic realm api for future use.

i've taken it down for now... and by the way, for those of you wondering about the name, "chisaikaruma" comes from "chisai karuma" (ちさかるま) in japanese, which means "small car."

namazTime anonymous svn

Saturday, June 24th, 2006

just put up an svn repository for public access. you can access it here, or to obtain the latest code, just do:

svn co http://piousity.net/namazTime

thanks to mohammed sameer's suggestions, i made several changes. the version in svn is different than the release mainly because now, rather than manually make calls to libglade for loading objects from the xml files, i use the default build stuff generated by glade. while this will make a few things easier (adding translations later on, for example), i am not quite sure if i did everything right, but it seems to work so its fine for now (i am mainly unsure with respect to how to get the widgets, because the lookup method requires a parent widget which sometimes i don't have available, so i just made the main window global, and just destroyed the auxillary windows when they are closed and reopen them).

the version in subversion also links against libitl, so it is no longer bundled within the app. finally, a todo list is included for people interested in helping out.

namazTime 0.9

Thursday, June 22nd, 2006

i've fixed some of the distribution issues with the last version of namazTime, and so here it is, namazTime 0.9. it's still linux only at the moment, and it needs a notification area - most window managers either have this (gnome, kde, xfce, fluxbox), or you can get a program to handle this for those that don't (i currently use trayer under openbox).

to bring up the prayer times, you click the icon in the notification tray. hitting x or reclicking the icon reminimizes it into the tray. to change the timings and such, right click the icon. you can find a screenshot of the program in one of the older posts about it on this weblog.

on the todo list is to fix any bugs (please comment if you find something amiss), add some sort of alarm feature (to play the athan, for example), provide translations (arabic especially), and maybe port to windows and osx.

if you try it, please leave your comments. thanks!
wsalams.

iconv, vim 7

Wednesday, May 10th, 2006

iconv rocks. so often do i find this command really useful:
iconv -f original_encoding -t utf8 file > utf8_file

i've been using vim 7 beta for a while (which, by the way, was just released as vim 7 a day or so ago), but i never really realized how easy they've made it to look at arabic text files now (compared to what it used to be... there used to be an intricate setup process and a set of patches to run for vim 6x as documented by nadim on arabeyes. now, all you have to do is :set encoding=utf8 and :set arabic and you're set.

you can see a screenshot here.

technology, languages, and y3k

Thursday, March 2nd, 2006

the past 2 days at work, i've had some interesting happenings... yesterday, i met my egyptian friend and coworker who works here with me too, and, when he asked how i was doing, i said, "el7asharat wel saraseer metala3een 3aynee" (which roughly means, 'insects and roaches are giving me a hard time') -- he said, "oh, you're one of those guys! just like these other guys who are like, 'senna zar2a' for bluetooth" :p i practiced it on some germans in broken german too, 'hast du blau tzan on dein komputer?' -- hehe.

i guess what's interesting though is that in pretty much all languages, all the technical terms are in english. it sounds really funny to say 'senna zar2a' or 'blau tzan' for bluetooth and 'saraseer' or '7asharat' for bugs... why though? hehe i guess in arabic, some people call the internet, 'alshabaka,' which literally means 'the net' (like a fishing net) -- (by the way, why don't they say '3esh el3enkaboot' or something? (spider web)). but yeah, most people call it, "el net" -- 'el' being the.

as for y3k... so today, i introduced a y3k in the source code to our application. i asked my project lead and such if it was okay, and they said, "no one will be using our software until then." -- basically, i had a list of files, *strTIMESTAMP.ext -- and i wanted to delete them all, but i don't want to delete *str.ext itself -- just the ones with a timestamp. so because the delete method doesn't take in a regex (so i can't pass in *str+.ext), i had to find another solution.

the easy way (which i didn't want to do because i am lazy) is just copy *str.ext if it exists to something else, do the delete, and copy it back. but instead, i opted to do delete *str2*, which means in the year 3000, our software will stop deleting its temporary files... i might go back and fix it later after fixing the other important bugs...

update: i found a much easier fix -- use *str?*.* instead since '?' is supported :)

namaztime development

Monday, January 16th, 2006

i've done some work on namaztime. i made a few improvements to the interface and to the calculation algorithm, and hopefully fixed some bugs.

namaztime screenshot 1/16/2006

insha'Allah hope to release sometime soon, just got a couple more things that i want to get done for this release, a couple of small things to fix, etc...

come again?

Sunday, November 27th, 2005

a long time ago, when i still used to use xmms, there was this nice plugin called Repeat It! that let you say, "repeat this song between this and this times forever."

i found myself missing that feature today... unfortunately, i don't have xmms installed and don't want it installed because i now like the gtk2 based mp3 players, like beep for example.

but because beep is being rewritten as bmpx, i figure rather than porting the plugin, i can just write a much simpler command line version based on the existing plugin that works with beep.

note however that this is really bad... it does very little error checking, and the sleep solution isn't really the best solution... but its a pretty good solution for my limited uses :)

and in 25 lines, here it is:

 
#include <stdio.h>
#include <signal.h>
#include <bmp/beepctrl.h>
 
void got_signal(int x){
	printf("Exiting!\n"); exit(1);
}
 
int main(int argc, char** argv){
 
   int startpos, endpos;
   if (!xmms_remote_is_running(0))
      return (0*printf("\033[1mbmp is not running.\033[0m\n"))-1;
 
   if (argc != 3)
      return (0*printf("usage: %s start end\n", argv[0]));
 
   startpos = atoi(argv[1]);
 
   endpos = atoi(argv[2]);
 
   signal(SIGINT, got_signal);
 
   if (!xmms_remote_is_playing(0)){ xmms_remote_play(0); }
 
   while (1){
      xmms_remote_jump_to_time(0, startpos * 1000);
      sleep(endpos - startpos);
   }
}

to compile it, just do:

 
gcc `beep-config --cflags --libs` loopsegment.c -o loop

then just run beep, load up the file you want to play, and run the script passing in start and end seconds.