Thursday, 19 April 2012

Food honour :P

Mongolian traditional food called "Huushuur"




Indian Food "Butter Chicken & Butter Nun"

Korean food "Takturitan"


Saturday, 14 April 2012

C#: Multilingual application

This is all about developing an application which supports multiple languages.
So that, you need two or more resource files as you need. These files hold the translations corresponding to languages.
As shown bellow figure, you can add resource files to your application. (C#.NET 2005).

Wednesday, 11 April 2012

C# :Count the total number of lines in RichTextBox

All you have to use is RichTextBox.GetLineFromCharIndex method.

int lineNumber = richTextBox1.GetLineFromCharIndex(richTextBox1.TextLength) + 1;
MessageBox.Show(lineNumber.ToString());
This 2 lines of code will give you number of lines in RichTextBox

You will find more detailed explanation here:
GetLineFromCharIndex[^]

Here is complete example of counting total number of lines in RTB

Saturday, 7 April 2012

C#: Read from excel file

I used .NET 2.0 framework. Reading from excel file is depends on excel's version, not entirely but it will affect your source code little bit.

Here is little tip about reading excel file.
string mFileName; // file name which you will read from.
System.Data.OleDb.OleDbConnection connection;
string mSheetName; // excel file consists of many sheets / pages.
System.Data.OleDb.OleDbDataAdapter dtAdapter;
Reading from excel file is as same as reading from database, so that you will need connection string which helps you to connect your program to excel sheets, as well as dataAdapter which will retrieve data from excel sheet.

This function accepts 2 arguments which are describe excel file's name, and it's version.
If you are using excel 2007 then send true as a second argument, or else send false when you call this function.

C#: Read from command Prompt

I've been trying to read from Command prompt using c#. My application supposed to read lines from cmd whatever it shows. My Purpose was developing code editor and using external compiler.
 You need to use  System.Diagnostics.Process(System.Diagnostics.ProcessStartInfo).

System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo("file.exe", "command");
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardOutput = true;
startInfo.StandardOutputEncoding = //change if you need, you might need it
startInfo.StandardErrorEncoding = //change if you need, you might need it
//...

Using this example, file.exe could be any executable file and command, it should be related to exe file. In this example, file.exe is "cmd.exe" and "command" is "RUNCOB"

PHP: How To Create Thumbnail image.

Someone may wonder that when we have Photoshop, why do we bother to create thumbnail images using Php? Well answer is quite easy, whenever you upload photos to your web site to attract your readers or someone, every time you will have to cut or crop or do something on your photos by manually. Is not it annoying?
Once you completed your few lines of code you will no longer suffer from editing photos.
Here is your source code.

// Path of photo.
$img_name="Gear2nd.sized.jpg";
//In this case thumbnail image size will be twice smaller than its original.
//based on original photo's size this size can be changed.
$thm_size=2;
// Type
header('Content-type: image/jpeg');
// Generating Thumbnail's size.
list($width, $height)=getimagesize($img_name);
$new_width=$width / $thm_size;
$new_height =$height / $thm_size;
// Generating thumbnail image
$thm_img=imagecreatetruecolor($new_width, $new_height);
$img=imagecreatefromjpeg($img_name);
imagecopyresampled($thm_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
// show off the thumbnail
imagejpeg($thm_img, null,100);

Result :
Good luck

Wednesday, 29 February 2012

In museum.

I wanted to upgrade ram of my laptop so much. So i went to several shops and service centers and i got same answers, which was
"I could find matching ram in museum".
It inspired me, because i've got valuable museum item LoL.



After, i wanted to change my cell phone's battery and i went to Nokia shop, and i was questioned if i have permission to carry a weapon (nokia 3310)?
i found it very funny.

Monday, 30 January 2012

Car racing Game: Source code Step by Step - 2

OK, here is the last step of the game. You can copy this code and arrange these 3 steps as follows.
step - 1
step - 2
step - 0
I mean, 1st copy the step - 1 into some CPP file and then step - 2 and lastly step - 0.
Hope you'll enjoy the game.

Monday, 26 December 2011

Car racing Game: Source code Step by Step - 1

I know that looking at plain code is not desirable, so just keep this code with you and wait for few days. The game, car racing, will be completed in few days. Just as i said, it is pain in the ass looking at the code that doesn't have an explanation but if you pay attention and need any help, i would gladly support you in any way.
I'm ready to explain every single line if you require. But first complete the game, and execute the game.
First thing is first.
So here code comes.

Tuesday, 20 December 2011

Car racing Game: Source code Step by Step - 0

I mentioned about developing car racing game earlier. So now i think i will supply the source code of it. Since it ain't small program, i'll make it several parts.
Here, i start with the main function, and next time i will add all necessary classes and its methods.
So, main function comes as follows

Wednesday, 7 December 2011

C#: System data types

C#
Shorthand
System Type
Range
Meaning in life
sbyteSystem.Sbyte -128 to 127Signed 8-bit number
byteSystem.byte 0 to 255Unsigned 8-bit
number
shortSystem.Int16 -32.768 to 32.767Signed 16-bit number
ushortSystem.UInt16 0 to 65.535Unsigned
16-bit number
intSystem.Int32 -2.147.483.648 to
2.147.483.647
Signed 32-bit
number
uintSystem.UInt32 0 to 4,294,967,295Unsigned
32-bit number
longSystem.Int64 –9,223,372,036,854,775,808
to
9,223,372,036,854,775,807
Signed 64-bit
number
ulongSystem.UInt64 0 to
18,446,744,073,709,551,615
Unsigned
64-bit number
charSystem.Char U0000 to UffffA single 16-bit
Unicode character
floatSystem.Single 1.5x10-45 to 3.4x103832-bit floating
point number
doubleSystem.Double 5.0x10-324 to 1.7x1030864-bit floating
point number
boolSystem.Boolean true or falseRepresents
truth or falsity
decimalSystem.Decimal 100 to 1028A 96-bit signed
number
stringSystem.String Limited by system memoryRepresents a
set of Unicode
characters
objectSystem.Object Any type can be stored
in an object variable
The base class of all
types in the .NET
universe

Saturday, 3 December 2011

PHP: Validating email address.

function emailValidate($email)
{
   if(!eregi("^[a-z]+[a-z0-9_-]*(\.[a-z0-9_-]+)*@[a-z0-9]+
      (\.[a-z0-9_-]+)*\.(\.[a-z]+){2,}$",$email))
  {
      return true;
  }
  return false;
}

eregi case insensitive regular expression math.

Friday, 2 December 2011

log2( x ): Binary Logarithm

In the math.h of Turbo C, binary logarithm ( log2( ) ) doesn't exists. When we are working with tree, we need to calculate depth of the tree, as well as the number of nodes in that depth.
The number of nodes in ith depth can be calculated using : 2i . formula
the max number of node in ith depth : n = 2i - 1 (complete tree).
You can use these formula to find the number of nodes in particular depth.

On the other hand, you may need to find the depth you are currently in.
There is a very easy way to do that. This is using binary logarithm to find the current depth.

...
#include <math.h>
double log2(double x)
{
       return log(x) / log(2);
}

If i made mistakes let me know
Good luck

Wednesday, 30 November 2011

PHP: data grid view

Lets demonstrate how to show data in data grid view using php.
When we are working on website, one of the most important things is to show the data in brief and in a nice way
To do that combining HTML tags along with php.
Now lets see small example

Tuesday, 29 November 2011

Binary Search

Very useful searching algorithm, in every step the number of data, which is going to be sorted will cut into half (fig 1). But keep it in your mind that it works on only sorted data.
Let N be the number of data then,
in worst case the comparison will be done log2(N) + 1 times. And in case of linear searching, the number of comparison would be N.
For example: if we are going to search a number among a million others, in the worst case scenario, the number of comparison would never be exceeded 20. But in case of linear searching algorithm, the number of comparison would be 1.000.000

Source code :

Saturday, 26 November 2011

Indian Wedding (Photos)

This is the wedding of one of the biggest college's principal's daughter. There was everything that you could possible eat in India, Most important thing is that they are all free hehe. I mean food




Tuesday, 10 May 2011

PHP : Login Page


Here is simple guide to create login page. About design, you can create one as you like using html. This is simple design that i created to demonstrate how login page works. You can use just two text-boxes and submit button, that is all.

Make sure that your text-boxes and submit button are inside the "Form" which uses method field and action field as shown below.

<Form name="Form1" method="post" action="login.php"> ...
When you hit login or submit button, all data which are inside this form will be thrown to login.php.
And they won't appear in address bar. Because method is post.

Saturday, 23 April 2011

C/C++ : Quick Sort

Here is the source code of quick sort. This algorithm also knowns as most efficient search algorithm.
I don't know why but it doesn't work appropriately. It works on 100 data but more than that it crushes.
If you find bug let me know, thank you.

I've used Hoare-partition
Here is the code.

int partition( int a[ ]int low, int high )
{
    int piwot, right, left;
    left = low + 1 ;
    right = high ;
    piwot = alow ];
    while(1)
    {
        while( aright ] > piwot ) right--;
        while( a[ left ] < piwot &&a left < high ) left++;
        if ( left < right )
            swap( a, left, right );
        else{
            swap( a, low, right );
            return right;
        }
    }
}

void quickSort( int a[ ]int low, int high)
{
    int part;
    if( low &lt; high )
    {
        part = partition( a, low, high );
        quickSort( a, low, part -1 );
        quickSort( a, part +1, high );
    }
}

Tuesday, 19 April 2011

C# : Detecting cursor position in RichTextBox

When i was working on RichTextBox the main thing that i had to handle was counting lines and detecting cursor position. Now lets see how to get these things done. Let me tell you about how to detect cursor position.

You need to use:
RichTextBox.SelectionStart and RichTextBox.GetLineFromCharIndex()
But make sure you use instance method of RichTextBox class as show
here :GetLineFromCharIndex[^] and GetLineFromCharIndex[^]
    
private static int EM_LINEINDEX = 0xbb;

int index, line, col;

[DllImport("user32.dll")]

extern static int SendMessage(IntPtr hwnd, int message, int wparam, int lparam);   


[DllImport("user32.dll")]
This line of code shouldn't be written in any method or functions.
You will find detailed explanation here:
 DllImportAttribute[^]