Saturday, December 13, 2008

Bengali in LaTeX in Mac OS X

I have installed LaTeX for Mac OS from http://www.tug.org/mactex/

I was trying to write Bangla in LaTex. Found two ways to write bangla in LaTeX.


Unicode Standard

written by Golam Mortuza Hossain. Here I am just writing how to do this in Mac OS.

First download freefont-ttf-xyz.tar.gz from

http://savannah.nongnu.org/download/freefont/

or
ftp://ftp.gnu.org/pub/gnu/freefont/


which containing
-------------------------
FreeSerif.ttf
FreeSerifBold.ttf
FreeSerifItalic.ttf
FreeSerifBoldItalic.ttf


Paste these fonts in your "Macintosh HD/Library/Fonts/"

Now try sample document in TeXShop

\documentclass{article}
\usepackage{fontspec}
%
% This file is a based on the sample tex file to illustrate use of
% XeTeX in typesetting Bengali document.
% License under GNU FDL by Golam Mortuza Hossain, 2008
%
%url: http://methopath.wordpress.com/2008/06/26/writing-unicode-bengali-in-latex/
%
\font\serif="FreeSerif:script=beng"
\font\serifbb="FreeSerif:script=beng" at 24pt
\font\deffont="FreeSerif:script=beng" at 14pt

\title{\bf\serifbb সত্যজিৎ রায়}
\author{\bf\serif উইকিপিডিয়া, মুক্ত বিশ্বকোষ থেকে}
\date{}
\begin{document}
\deffont %Default font used for the document
\maketitle
সত্যজিৎ রায় (২রা মে, ১৯২১ – ২৩শে এপ্রিল, ১৯৯২) একজন বাঙালী চলচ্চিত্র নির্মাতা ও বিংশ শতাব্দীর অন্যতম শ্রেষ্ঠ চলচ্চিত্র পরিচালক। কলকাতা শহরে সাহিত্য ও শিল্পের জগতে খ্যাতনামা এক বাঙালী পরিবারে তাঁর জন্ম হয়। তিনি কলকাতার প্রেসিডেন্সি কলেজ ও শান্তিনিকেতনে রবীন্দ্রনাথ ঠাকুরের প্রতিষ্ঠিত বিশ্বভারতী বিশ্ববিদ্যালয়ে পড়াশোনা করেন। সত্যজিতের কর্মজীবন একজন বাণিজ্যিক চিত্রকর হিসেবে শুরু হলেও প্রথমে কলকাতায় ফরাসি চলচ্চিত্র নির্মাতা জঁ রনোয়ারের সাথে সাক্ষাৎ ও পরে লন্ডন শহরে সফররত অবস্থায় ইতালীয় নব্য বাস্তবতাবাদী ছবি লাদ্রি দি বিচিক্লেত্তে (ইতালীয় ভাষায় Ladri di biciclette, "সাইকেল চোর") দেখার পর তিনি চলচ্চিত্র নির্মাণে উদ্বুদ্ধ হন।
\end{document}



Select "XeLaTeX" from drop down menu and click "Typeset" button for Output in TeXShop.




reference: http://methopath.wordpress.com/2008/06/26/writing-unicode-bengali-in-latex/






Bangtex

First Bengali typesetting system using LaTeX. Which use a non-standard approach to write bangla.

example:

\centerline{\bngxxv ra\*g*er OShudh}
\centerline{\bngxviii sukumar ray}

-----------------------------------
which give output
-----------------------------------
রোগের ওষুধ
সুকুমার রায়

download bfonts.tar.gz, bsty.tar.gz, bsample.tar.gz from
http://www.saha.ac.in/theory/palashbaran.pal/bangtex/bangtex.html


Installing the font files
cd /usr/local/texlive/2008/texmf-dist/fonts/source
sudo mkdir bangla
extract bfonts.tar.gz in /usr/local/texlive/2008/texmf-dist/fonts/source/bangla/
Installing the macro files for LaTeX
cd /usr/local/texlive/2008/texmf-dist/tex/latex
sudo mkdir bangla
extract bsty.tar.gz /usr/local/texlive/2008/texmf-dist/tex/latex/bangla/
Initializing the files
sudo texhash

reference: http://www.saha.ac.in/theory/palashbaran.pal/bangtex/install.html#linux

Thursday, November 06, 2008

Probhat Installer for MacOS

I have created Probhat installer for MacOS.

You can download it from Ankur website click here.




Details on Ankur Wiki

Saturday, September 20, 2008

get database structure using PHP

I was facing problem to connect a mysql host, as it was only accepting connection from a specific server. But I need to know the database structure to design some report.

At last I have written a simple php code to print the table name along with the structure.


<?php

mysql_connect("host_name","user","password") or die(mysql_error());
mysql_select_db("database_name") or die(mysql_error());


$result = mysql_query("SHOW TABLES;") or die(mysql_error());

while($row = mysql_fetch_array($result)){

echo $row[0]; //print the table name

$result2 = mysql_query("DESCRIBE ".$row[0].";") or die(mysql_error()); //get details schema for each table

echo "<table border='1' width='70%'>";
echo "<tr><td>Field</td><td>Type</td><td>Null</td><td>Key</td><td>Default</td><td>Extra</td>";

while($row2 = mysql_fetch_array($result2)){

for($i=0; $i<6; $i++){
if($row2[$i] == "" || $row2[$i] == NULL){
$row2[$i] = " ";
}
}

echo "<tr>";
echo "<td>".$row2[0]."</td><td>".$row2[1]."</td><td>".$row2[2]."</td><td>".$row2[3]."</td><td>".$row2[4]."</td><td>".$row2[5];
echo "</tr>";
}

echo "</table>";
echo "<br/>";
}

?>


Just change your database configuration then upload in your server. Browse the url and you must delete the file from server after get the structure. Be safe...

Sunday, August 31, 2008

function call in javascript

I was studying russkey.mozdev.org source code to learn how to write Firefox extension.

Found this style of function call in javascript.


var collection = {

hello : function() {
document.write("Hello World!");
},

understand : function() {
document.write("<br/>Understand!");
},

bye : function() {
document.write("<br/>bye!");
}

};


var m = new collection.hello();
var n = new collection.understand();
var o = new collection.bye();



The output will

Hello World!
Understand!
bye!

Saturday, August 30, 2008

My Facebook application



apps.new.facebook.com/circle_of_blood/
or
apps.facebook.com/circle_of_blood/


Special thanks to Dr. Hamza for joining in this project and sponsor the hosting.

Wednesday, August 27, 2008

flash/swf height width in CodeIgniter 1.6

In libraries/Upload.php

Edit the function is_image().

add the 'application/x-shockwave-flash' in $img_mimes


$img_mimes = array(
'image/gif',
'image/jpeg',
'image/png',
'application/x-shockwave-flash',
);



It simply allow set_image_properties function to read the height & width for flash.

//now this will not call for flash
if ( ! $this->is_image())
{
return;
}

Tuesday, August 26, 2008

Which user remove my facebook application

To remove the user who remove your application from facebook automatically.

In the settings of the application,
"Can your application be added on Facebook?" set it yes.


Scroll down, you will get a Post-Remove URL input box.



Facebook will send data to the post remove url page about the user removing the application.
The post_remove.php example from my server.


<?php

//facebook lib
require_once 'fbclient/facebook.php';

//my database config
require_once 'config/config.php';

$appapikey = 'you_app_api_key';
$appsecret = 'your_app_secret_key';

$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();

$user = $facebook->get_loggedin_user();

if ($user != NULL && $facebook->fb_params['uninstall'] == 1)
{
//The user has removed your app
mysql_query("DELETE FROM users WHERE userid='$user_id'") or die(mysql_error());
}

?>


Reference:
Creating Your First Application Facebook wiki
Post-Remove URL Facebook wiki

Wednesday, August 13, 2008

Matrix in OpenGL


[0 4 8 12]
[1 5 9 13]
[2 6 10 14]
[3 7 11 15]

4x4 matrix in memory.

[R0 R3 R6 Tx]
[R1 R4 R7 Ty]
[R2 R5 R8 Tz]
[ 0 0 0 1]

'R' represents rotations and scaling (and shearing)
'T' translation


First, I read the matrix and print it.


float x[16];
int i;

//read the 4x4 matrix and store in x
glGetFloatv (GL_MODELVIEW_MATRIX, (float*)x);

//print the matrix
for(i=0; i<4; i++){
printf("%f\t%f\t%f\t%f", x[i], x[i+4], x[i+8], x[i+12]);
printf("\n");
}

glTranslatef(2, 0.0, 0.0);


//print the matrix after translate

glGetFloatv (GL_MODELVIEW_MATRIX, (float*)x);

printf("\n-----------------------\n");

for(i=0; i<4; i++){
printf("%f\t%f\t%f\t%f", x[i], x[i+4], x[i+8], x[i+12]);
printf("\n");
}



Run the program.

After translate our matrix changes in "Tx" -2.000000

-1.000000   0.000000   0.000000   0.000000
0.000000  -0.196116   0.980581   0.000000
0.000000   0.980581   0.196116  -10.198039
0.000000   0.000000   0.000000   1.000000
-----------------------------------------
-1.000000   0.000000   0.000000  -2.000000
0.000000  -0.196116   0.980581   0.000000
0.000000   0.980581   0.196116  -10.198039
0.000000   0.000000   0.000000   1.000000



Instead of translate if we use rotation

glRotatef(45, 0.0, 1.0, 1.0);

After rotation our matrix changes in "R"

-1.000000   0.000000   0.000000   0.000000
0.000000  -0.196116   0.980581   0.000000
0.000000   0.980581   0.196116  -10.198039
0.000000   0.000000   0.000000   1.000000
-----------------------------------------
-0.707107   0.500000  -0.500000   0.000000
-0.588348  -0.023793   0.808257   0.000000
0.392232   0.865699   0.310998  -10.198039
0.000000   0.000000   0.000000   1.000000




Reference: www.gamedev.net Forum

Saturday, July 19, 2008

Simple Solar System in OpenGL




I have created a simple Solar System using OpenGL




#include <stdlib.h>
#include <GLUT/glut.h>
#include <math.h>
#include <stdio.h>

static float Xvalue = 0.0, Yvalue = 0.0, Angle = 0.0;

int MoveX = 0;
int MoveY = 0;

void myInit(void) {
glClearColor (0.0, 0.0, 0.0, 0.0);
}


static float x1[360][2];
static float x2[360][2];
static float x3[720][2];


void generateCircle()
{
int i = 0;

for(i=0; i <= 360; i++)
{
x1[i][0] = sin(i*3.1416/180)*3;
x1[i][1] = cos(i*3.1416/180)*3;
}

for(i=0; i <= 360; i++)
{
x2[i][0] = sin(i*3.1416/180)*1;
x2[i][1] = cos(i*3.1416/180)*1;
}

for(i=0; i <= 720; i++)
{
x3[i][0] = sin(i*3.1416/180)*5;
x3[i][1] = cos(i*3.1416/180)*5;
}

}




void myDisplay(void) {

glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1.0, 1.0, 1.0);

//sun
glPushMatrix();
gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
glTranslatef(Xvalue, 0.0, Yvalue);
glRotatef(Angle, 0.0, 0.0, 1.0);
glutWireSphere (0.5, 15, 15);
glPopMatrix();

glPushMatrix();
gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
if(MoveX==360)
MoveX = 0;
glTranslatef(x1[MoveX][1], x1[MoveX][0], 0.0);
glRotatef(Angle, 0.0, 0.0, 1.0);
glutWireSphere (0.4, 15, 15);
glTranslatef(x2[MoveX][0], x2[MoveX][1], 0.0);
glutWireSphere (0.2, 15, 15);
glPopMatrix();

glPushMatrix();
gluLookAt (0.0, 10.0, 2.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
if(MoveY==720)
MoveY = 0;
glTranslatef(x3[MoveY/2][1], x3[MoveY/2][0], 0.0);
glRotatef(Angle, 0.0, 0.0, 1.0);
glutWireSphere (0.4, 15, 15);
int i = 0;
//glBegin(GL_LINE_STRIP);
glBegin(GL_QUAD_STRIP);
for(i=0; i <= 360; i++)
{
glVertex3f(sin(i*3.1416/180)*0.5, cos(i*3.1416/180)*0.5, 0 );
glVertex3f(sin(i*3.1416/180)*0.7, cos(i*3.1416/180)*0.7, 0 );
}
glEnd();
glRotatef(Angle, 0.0, 0.0, 1.0);
glPopMatrix();

glFlush ();
}


void resize(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
}


void animation()
{
Angle += 15.0;
glutPostRedisplay();
MoveX +=1;
MoveY +=1;
glutPostRedisplay();
glutTimerFunc(100, animation, 0);

}


int main(int argc, char ** argv){

glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 150);
glutCreateWindow("OpenGL");
myInit();
glutDisplayFunc(myDisplay);
glutReshapeFunc(resize);
generateCircle();
glutTimerFunc(100, animation, 0);
glutMainLoop();
}


Tuesday, July 01, 2008

iReport java.lang.NullPointerException

I was facing some problem to start iReport in my Debian

salahuddin@crab:~/iReport-2.0.3$ ./iReport.sh
Exception in thread "main" java.lang.NullPointerException
at java.util.Hashtable.put(libgcj.so.70)
at javax.swing.plaf.basic.BasicToolBarUI.setBorderToRollover(libgcj.so.70)
at javax.swing.plaf.basic.BasicToolBarUI$ToolBarContListener.componentAdded(libgcj.so.70)
at java.awt.Container.addImpl(libgcj.so.70)
at javax.swing.JToolBar.addImpl(libgcj.so.70)
at java.awt.Container.add(libgcj.so.70)
at it.businesslogic.ireport.gui.ToolbarFormatPanel.initComponents(ToolbarFormatPanel.java:170)
at it.businesslogic.ireport.gui.ToolbarFormatPanel.(ToolbarFormatPanel.java:57)
at it.businesslogic.ireport.gui.MainFrame.(MainFrame.java:487)
at it.businesslogic.ireport.gui.MainFrame.main(MainFrame.java:8020)
salahuddin@crab:~/iReport-2.0.3$


Here is my .bashrc
export CVSROOT=:ext:salahuddin@paq:/home/cvs
export CVS_RSH=/usr/bin/ssh
export ANT_OPTS=-Xmx512m
export ANT_HOME=/usr/ant
export JAVA_HOME=/usr/jdk1.5.0_03
export CLASS_PATH=$JAVA_HOME/lib/:$JAVA_HOME/jre/lib
export CLASSPATH=$JAVA_HOME/lib/:$JAVA_HOME/jre/lib
export PATH=$PATH:$ANT_HOME/bin:$JAVA_HOME/bin
export CATALINA_HOME=/usr/tomcat
export CVSEDITOR=vim

Note: My /usr/java is soft linked with
/usr/jdk1.5.0_03

Main problem /usr/bin/java was linked with
/etc/alternatives/java
salahuddin@crab:/usr/bin$ ls -l java*
lrwxrwxrwx 1 root root 22 2008-04-30 22:29 java -> /etc/alternatives/java
lrwxrwxrwx 1 root root 23 2008-06-26 15:52 javac -> /etc/alternatives/javac
lrwxrwxrwx 1 root root 25 2008-07-01 15:58 javadoc -> /etc/alternatives/javadoc
lrwxrwxrwx 1 root root 23 2008-06-26 15:52 javah -> /etc/alternatives/javah

The main problem was it was using java from the gij package/

#cd /usr/bin/
#mv java java2
#mv javac javac2
#mv javah javah2
#mv javadoc javadoc2

#ln -s /usr/java/bin/java
/usr/bin/java
#ln -s /usr/java/bin/javac /usr/bin/javac
#ln -s /usr/java/bin/javah /usr/bin/javah
#ln -s /usr/java/bin/javadoc /usr/bin/javadoc

It simply solve the problem.

Thursday, June 12, 2008

Get system load using Python Script

I have written a simple python script that collect system load information and store in a XML file.


#!/usr/bin/env python

import os
import commands
import time
from time import gmtime, strftime

while 0 < 10:

file_name = strftime("%Y_%m_%d_%H_%M", gmtime())

data = commands.getoutput("w | grep load")
xml_data = ""+ data + ""

print xml_data


if os.path.isfile(file_name + ".xml"):
x=0
else:

f_prev=open(file_name + ".xml", 'a')
f_prev.write("")
f_prev.close

f=open(file_name + ".xml", 'w')
f.write("\n\n")
f.close()


f=open(file_name + ".xml", 'a')

f.write(xml_data+"\n")

f.close()
time.sleep(3)



We will get XML file like this.
<?xml version='1.0' encoding='utf-8'?>
<data>
<load> 01:40:38 up 6:27, 3 users, load average: 0.07, 0.07, 0.03</load>
<load> 01:40:48 up 6:27, 3 users, load average: 0.06, 0.07, 0.03</load>
<load> 01:40:58 up 6:27, 3 users, load average: 0.05, 0.07, 0.03</load>
</data>

Monday, June 09, 2008

putpixel in Linux

Some days ago I was trying to read a BMP format file and show it using putpixel.

I haved used qdbmp.sourceforge.net which is a minimalistic cross-platform C library for handling BMP image file.

The Allegro (www.allegro.cc) graphics library that provides many functionality.

putpixel
Writes a pixel into a bitmap.
Description void putpixel(BITMAP *bmp, int x, int y, int color);

Download qdbmp.c qdbmp.h from the qdbmp website


Sample code that reads a BMP file and show it using Allegro library

/*
* Example program for the Allegro library, by Shawn Hargreaves.
*
* This is a very simple program showing how to get into graphics
* mode and draw text onto the screen.
*/

#include <allegro.h>
/* Creates a negative image of the input bitmap file */
#include "qdbmp.h"
#include <stdio.h>

int main( int argc, char* argv[] )
{
BMP* bmp;
UCHAR r, g, b;
UINT width, height;
UINT x, y;

int color;
/* you should always do this at the start of Allegro programs */
if (allegro_init() != 0)
return 1;

/* set up the keyboard handler */
install_keyboard();

/* set a graphics mode sized 320x200 */
if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
return 1;
}
}

/* set the color palette */
set_palette(desktop_palette);

/* clear the screen to white */
clear_to_color(screen, makecol(255, 255, 255));

/* you don't need to do this, but on some platforms (eg. Windows) things
* will be drawn more quickly if you always acquire the screen before
* trying to draw onto it.
*/
acquire_screen();

/* write some text to the screen with black letters and transparent background */
// textout_centre_ex(screen, font, "Hello, world!", SCREEN_W/2, SCREEN_H/2, makecol(0,0,0), -1);


if ( argc != 3 )
{
fprintf( stderr, "Usage: %s <input file> <output file>\n", argv[ 0 ] );
return 0;
}

/* Read an image file */
bmp = BMP_ReadFile( argv[ 1 ] );
BMP_CHECK_ERROR( stderr, -1 ); /* If an error has occurred, notify and exit */

/* Get image's dimensions */
width = BMP_GetWidth( bmp );
height = BMP_GetHeight( bmp );

/* Iterate through all the image's pixels */
for ( x = 0 ; x < width ; ++x )
{
for ( y = 0 ; y < height ; ++y )
{
/* Get pixel's RGB values */
BMP_GetPixelRGB( bmp, x, y, &r, &g, &b );

color = makecol(r,g,b);

putpixel(screen, x, y, color);

/* Invert RGB values */
BMP_SetPixelRGB( bmp, x, y, 255 - r, 255 - g, 255 - b );
}
}


// putpixel(screen, SCREEN_W/2, SCREEN_H/2, 50);

/* you must always release bitmaps before calling any input functions */
release_screen();

/* wait for a key press */
readkey();

/* Save result */
BMP_WriteFile( bmp, argv[ 2 ] );
BMP_CHECK_ERROR( stderr, -2 );

/* Free all memory allocated for the image */
BMP_Free( bmp );

return 0;
}

END_OF_MAIN()

Compile
$gcc -g -O2 -o name `allegro-config --libs` sample.c qdbmp.c


Resources:
http://qdbmp.sourceforge.net/
http://www.allegro.cc/manual/api/drawing-primitives/putpixel
http://www.allegro.cc/manual/api/truecolor-pixel-formats/makecol

Wednesday, March 12, 2008

Probhat in MacOS

I have ported the Probhat Layout (a bangla keyboad) in MacOS .

Download link
http://www.ankur.org.bd/wiki/Documentation#Mac_OS_X_2

* Unpack the zip file, there will be two files "Probhat.icns" and "Probhat.keylayout".
* Paste these two files in "Macintosh HD/Library/Keyboard Layouts/" or "Home/Library/Keyboard Layouts/", which will install the keyboard layout.


* Go to "System Preferences" > "International" > "Input Menu" scroll down and make sure that "Probhat" is checked.





* Make sure Show input menu in menu bar is checked, default English layout will be highlighted in the menu bar.



* Now click on "Keyboard Shortcuts" and in the "Input Menu" section put your desired keyboard shortcut that will enable you to change the keyboard layout (Our choice was Alt+Space).


* Now while typing in any application, pressing Alt+Space will switch to Probhat Layout and Probhat layout symbol will be highlighted in the menu bar.

Tuesday, January 29, 2008

LDAP address book in Debian

#apt-get install slapd ldap-utils ldapscripts


edit /etc/ldap/slapd.conf
----------------------------
//change the suffix accodring to your domain. here "example.com.bd"
suffix "dc=example,dc=com,dc=bd"

//uncomment this line
rootdn "cn=admin,dc=example,dc=com,dc=bd"

//add after rootdn line (it is plain text password)
rootpw secret

//change the dc=example,dc=com,dc=bd everywhere in slapd.conf
//keep other config as it is.

restart ldap
#/etc/init.d/slapd restart

edit /etc/ldap/ldap.conf


create a file name directory.ldif in /etc/ldap/schema/

directory.ldif
----------------
dn: dc=example,dc=com,dc=bd
objectClass: top
objectClass: dcObject
objectClass: organization
dc: example
o: Example Inc.

dn: ou=addressbook, dc=example,dc=com,dc=bd
objectClass: top
objectClass: organizationalUnit
ou: addressbook




from shell cd to /etc/ldap/schema/
$ldapadd -x -D 'cn=admin,dc=example,dc=com,dc=bd' -f directory.ldif -W
(give pass secret here)


To check
$ldapsearch -b 'dc=example,dc=com,dc=bd' 'objectclass=*' -x


Input data using phpldapadmin

#apt-get install phpldapadmin

http://localhost/phpldapadmin/

login: cn=admin,dc=example,dc=com,dc=bd
pass: secret

or you can add data manually

create a file contact.ldif in /etc/ldap/schema/

contact.ldif
--------------
dn: cn=Blogger OS, ou=addressbook,dc=example,dc=com,dc=bd
objectClass: top
objectClass: person
objectClass: organizationalPerson
objectClass: inetOrgPerson
cn: Blogger
gn: Ldap
sn: OS
mail: blogger@example.com.bd
physicalDeliveryOfficeName: Dhaka, Bangladesh.
postalAddress: PO BOX 909
ou: addressbook
st: LA
postalCode: 1215
telephoneNumber: 111-111-1111
facsimileTelephoneNumber:
111-111-1111
pager:
111-111-1111
mobile:
111-111-1111
homePhone:
111-111-1111

from shell cd to /etc/ldap/schema/
$ldapadd -x -D 'cn=admin,dc=example,dc=com,dc=bd' -f contact.ldif -W
(give pass secret here)

To check
$ldapsearch -b 'dc=example,dc=com,dc=bd' 'objectclass=*' -x



Reference:
ONLamp.com Link
OpenLDAP Link