bookmark_borderget 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…

bookmark_borderfunction 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!

bookmark_borderflash/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;
}

bookmark_borderWhich 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

bookmark_borderMatrix 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

bookmark_borderSimple 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();
}

bookmark_borderiReport 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.

bookmark_borderGet 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("nn")
  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>