Friday, October 31, 2008

Unix Style Tail Command

Unix Style Tail Command

SUMMARY: Display the most recent results of a log file with the tail command for Windows XP.

The tail command, on most Unix-style operating systems, lets you display the last 10 or so lines of a text file. It also supports a feature allowing you to keep a file lock on a particular file, displaying new lines as they appear. This is most commonly used for displaying the results of log or debug files, letting you see only the most recent activity of a particular process.

While Windows XP does not normally come with a 'tail' tool, it is available in the Windows 2003 Resource Kit. It is a large download, but besides the 'tail' command, the Windows 2003 Resource Kit also provides tools to remap keys, query the Active Directory, and more. To download and install the Resource Kit:

1. Go to the Microsoft Windows Server 2003 download section at http://www.microsoft.com/windowsserver2003/
downloads/tools/default.mspx
. Or, if that link does not work, visit http://www.microsoft.com/ and search for "Windows 2003". Once there, choose the "Downloads -> Tools" link.

2. Select the link "Windows Server 2003 Resource Kit Tools".

3. Click the "Download" link. Choose to register or not, depending on your choice, and follow the on-screen instructions to download and install the product. The default install directory is "C:\Program Files\Windows Resource Kits\Tools\".

Once the Windows 2003 Resource Kit is installed, you may need to reboot your machine for the directory "C:\Program Files\Windows Resource Kits\Tools\" to be added to your path.

Now that the tail command is available, to see the online help, enter the following DOS command:

tail /?

Here is a command summary:

C:\>tail FILENAME

Display the last ten lines from file FILENAME. For example, to see the last ten activities made by the Windows Update tool, issue these commands:

C:\>c:
C:\>cd \windows
C:\>tail "Windows Update.log"

C:\>tail -n FILENAME

Display the last 'n' lines from file FILENAME. For example, view the last 20 lines in the Windows Setup log:

C:\>c:
C:\>cd \windows
C:\>tail -20 setuplog.txt

C:\>tail -f FILENAME

Keep accesing FILENAME, displaying new lines as necessary.

To see this feature in action, open up a new file in Notepad, write the word 'hello, world', and save it as c:\test.log. Keep the file open in Notepad. Now, issue the following DOS commands:

C:\>c:
C:\>cd \
C:\>tail -f test.log

You should see the word 'hello, world' in your DOS prompt. Now, go back to Notepad and write the text "Process executed." Save the file. The DOS prompt should now say "Process executed." Whatever you add to the file in Notepad should then appear in your DOS prompt until you terminate the command.

Wednesday, October 29, 2008

The Miracle of Quran

as u know 18 and 81 are written in our hands in Arabic.

u must have heard these 2

18+81=99=Al Asma'ul Husnaa

81-18=63=the hijri years Muhammad(saw)lived.

now he found this:

when we write it like this:

18 81=1881=19x99

19 is the miracle of Quran(we are not submitters,if you want to see really Quran is coded somehow with 19,check www.quranmiracles.com
it is the miracle of Quran,not the miracle of Rashid Khalifa.)

99 is Al Asma'ul Husnaa (again) :)

and suddenly,i found this

81 18=8118=123x66

66 is the abjad of Allah(swt)

123 also means something but what?
 
THE AMAZING FACTS OF QURAN
Check this out, very interesting findings of Dr. Tariq Al Swaidan might
grasp your attention:

Dr.Tarig Al Swaidan discovered some verses in the Holy Qur'an that mention
one thing is equal to another, i.e. men are equal to women.


Although this makes sense grammatically, the astonishing fact is that the
number of times the
word man appears in the Qur'an is 24 and number of times the word woman
appears is also 24, therefore not only is this phrase correct in the
grammatical sense but also true mathematically, i.e. 24 = 24.

Upon further analysis of various verses, he discovered that this is
consistent throughout the whole Qur'an, where it says one thing is like
another. See below for astonishing result of the words mentioned number of
times in Arabic Qur'an:

Dunia (one name for life) 115. Aakhirat (one name for the life after this
world) 115
Malaika (Angels) 88 . Shayteen (Satan) 88
Life 145 .... Death 145
Benefit 50 . Corrupt 50
People 50 .. Messengers 50
Eblees (king of devils) 11 . Seek refuge from Eblees 11
Museebah (calamity) 75 . Thanks 75
Spending (Sadaqah) 73 . Satisfaction 73
People who are mislead 17 . Dead people 17
Muslimeen 41 . Jihad 41
Gold 8 . Easy life 8
Magic 60 . Fitnah (dissuasion, misleading) 60
Zakat (Taxes Muslims pay to the poor) 32 . Barakah (Increasing or blessings
of wealth) 32
Mind 49 . Noor 49
Tongue 25 .. Sermon 25
Desite 8 . Fear 8
Speaking publicly 18 . Publicising 18
Hardship 114 .... Patience 114
Muhammed 4 . Sharee'ah (Muhammed's teachings) 4
Man 24. Woman 24

And amazingly enough have a look how many times the following words appear:

Salah 5, Month 12, Day 365,
Sea 32, Land 13

Sea + land = 32+13= 45

Sea = 32/45*100=71.11111111%
Land = 13/45*100 = 28.88888889%
Sea + land =100.00%

Modern science has only recently proven that the water covers 71.111% of the
earth, while the land covers 28.889%.

Is this a coincidence?

Question is that Who taught Prophet Muhammed (PBUH) all this?

Reply automatically comes in mind that ALMIGHTY ALLAH taught him this. As
the Qur'an also tells us this.

Aayah 87 of Suraa (Chapter) Al-Anbia \ para 17:
LA ILAHA ILA ANTA SUBHANAKA INI KUNTU MINA ZALIMEEN.

Load Balancing Two MySQL Servers for PHP Applications

My "research" on clustering and replication was just timely. I had to find a fix for an overloaded server. I could've just rewritten the code but I wanted to try something new first. I found out that a MySQL cluster needs to have at least three servers to get full redundancy. Replication was my only choice because I only have two servers for this application and the queries that are producing the most load are select queries.

MySQL replication works by having a master server where all the inserts, updates and deletes (basically any writing done) and one or more slave servers that polls the master server to replicate the database. You can only issue select queries to the slave server. You can also have multiple master servers but it won't be covered here. You can follow this article to setup replication.

I'll be using Round Robin to balance the load since I'll be load balancing for a separate portion only where the same queries are used. This will equally split the load to each server (…almost). To do this in PHP, I wrote a very simple script that opens a socket. Once a host connects, it tells which database server to connect to and immediately terminates the connection.


#!php -q
<?php
// Bind and listen
$stream = socket_create(AF_INET, SOCK_STREAM,  SOL_TCP);
socket_bind($stream, "127.0.0.1",3307);
socket_listen($stream, 100);


// Define DB login credentials in an array
// host|user|passwd
$hosts = array(
0 => array('localhost','someusr','
somepasswd'),
1 => array('192.168.1.149','somereusr','
somerepasswd')
/***** if you add another host (just follow the drift) *****/
// 2 => array('db3.dbservers.net','yetanotheruser','yetanotherpass')
);


// Loop forever
while(true)
{
    // Accept anyone
    $client = socket_accept($stream);
    $key = key($hosts);
    $reply = implode($hosts[$key], "|");
    // Move internal pointer to next host
    if(next($hosts) === FALSE)
        reset($hosts);

    // Push response then kill the connection
    socket_write($client, $reply);
    socket_close($client);
$flg=true;   
}
?>

This script should be called from the command line and run like a daemon. Then we modify how we connect to the database. We connect to the "daemon" and catch the login information.

<?php
// Connect to load balancer daemon
$fp = fsockopen("localhost", 3307);

// Fallback and use some host in case of failure
if(!$fp)
{
    $host = "localhost";
    $user = "someusr";
    $pass = "somepasswd";
}
else
{
    // Get DB login information
    $packet = fgets($fp);
    $account_details = explode("|", $packet);
    $host = $account_details[0];
    $user = $account_details[1];
    $pass = $account_details[2];
}

// Connect
$link = mysql_connect($host,$user,$pass);
if(!$link)
{
    die("Fatal Error: Can't connnect to database\n");
}

?>


The code above can be improved further to check if a host is still up, give weights on the server depending on its hardware and other bells and whistles.

The beauty of this is you can safely change to another algorithm like Weighted Round Robin or Job Informed and all of the code that has to be changed is in the daemon. You may learn more on other algorithms from the paper by Dennis Haney and Klaus S. Madsen.

I'm looking into venturing to a Job Informed algorithm once the whole application uses load balancing. Queries will have weights then some form of load estimation can be achieved. Query analysis is also a possibility (based on subqueries, query type, constraints ,etc).


Original Source :: http://blog.jploh.com/2007/06/18/load-balancing-two-mysql-servers-for-php-applications/


Tuesday, October 21, 2008

ffmpeg option

usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...
Hyper fast Audio and Video encoder

Main options:
-L show license
-h show help
-version show version
-formats show available formats, codecs, protocols, ...
-f fmt force format
-img img_fmt force image format
-i filename input file name
-y overwrite output files
-t duration set the recording time
-fs limit_size set the limit file size
-ss time_off set the start time offset
-itsoffset time_off set the input ts offset
-title string set the title
-timestamp time set the timestamp
-author string set the author
-copyright string set the copyright
-comment string set the comment
-album string set the album
-v verbose control amount of logging
-target type specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", "ntsc-svcd", ...)
-dframes number set the number of data frames to record
-scodec codec force subtitle codec ('copy' to copy stream)
-newsubtitle add a new subtitle stream to the current output stream
-slang code set the ISO 639 language code (3 letters) of the current subtitle stream

Video options:
-vframes number set the number of video frames to record
-r rate set frame rate (Hz value, fraction or abbreviation)
-s size set frame size (WxH or abbreviation)
-aspect aspect set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)
-croptop size set top crop band size (in pixels)
-cropbottom size set bottom crop band size (in pixels)
-cropleft size set left crop band size (in pixels)
-cropright size set right crop band size (in pixels)
-padtop size set top pad band size (in pixels)
-padbottom size set bottom pad band size (in pixels)
-padleft size set left pad band size (in pixels)
-padright size set right pad band size (in pixels)
-padcolor color set color of pad bands (Hex 000000 thru FFFFFF)
-vn disable video
-vcodec codec force video codec ('copy' to copy stream)
-sameq use same video quality as source (implies VBR)
-pass n select the pass number (1 or 2)
-passlogfile file select two pass log file name
-newvideo add a new video stream to the current output stream

Advanced Video options:
-pix_fmt format set pixel format
-intra use only intra frames
-vdt n discard threshold
-qscale q use fixed video quantizer scale (VBR)
-qdiff q max difference between the quantizer scale (VBR)
-rc_eq equation set rate control equation
-rc_override override rate control override for specific intervals
-me method set motion estimation method
-me_threshold motion estimaton threshold
-strict strictness how strictly to follow the standards
-deinterlace deinterlace pictures
-psnr calculate PSNR of compressed frames
-vstats dump video coding statistics to file
-vhook module insert video processing module
-intra_matrix matrix specify intra matrix coeffs
-inter_matrix matrix specify inter matrix coeffs
-top top=1/bottom=0/auto=-1 field first
-dc precision intra_dc_precision
-vtag fourcc/tag force video tag/fourcc
-qphist show QP histogram
-vbsf bitstream filter

Audio options:
-aframes number set the number of audio frames to record
-ab bitrate set audio bitrate (in kbit/s)
-aq quality set audio quality (codec-specific)
-ar rate set audio sampling rate (in Hz)
-ac channels set number of audio channels
-an disable audio
-acodec codec force audio codec ('copy' to copy stream)
-vol volume change audio volume (256=normal)
-newaudio add a new audio stream to the current output stream
-alang code set the ISO 639 language code (3 letters) of the current audio stream

Advanced Audio options:
-atag fourcc/tag force audio tag/fourcc
-absf bitstream filter

Subtitle options:
-scodec codec force subtitle codec ('copy' to copy stream)
-newsubtitle add a new subtitle stream to the current output stream
-slang code set the ISO 639 language code (3 letters) of the current subtitle stream

Audio/Video grab options:
-vd device set video grab device
-vc channel set video grab channel (DV1394 only)
-tvstd standard set television standard (NTSC, PAL (SECAM))
-ad device set audio device
-grab format request grabbing using
-gd device set grab device

Advanced options:
-map file:stream[:syncfile:syncstream] set input stream mapping
-map_meta_data outfile:infile set meta data information of outfile from infile
-benchmark add timings for benchmarking
-dump dump each input packet
-hex when dumping packets, also dump the payload
-re read input at native frame rate
-loop_input loop (current only works with images)
-loop_output number of times to loop output in formats that support looping (0 loops forever)
-threads count thread count
-vsync video sync method
-async audio sync method
-vglobal video global header storage type
-copyts copy timestamps
-shortest finish encoding within shortest input
-dts_delta_threshold timestamp discontinuity delta threshold
-ps size set packet size in bits
-muxdelay seconds set the maximum demux-decode delay
-muxpreload seconds set the initial demux-decode delay

Sunday, October 19, 2008

FFmpeg : Convert to 3gp file

ffmpeg -i inputfile.avi -s qcif -vcodec h263 -acodec aac -ac 1 -ar 8000 -r 25 -ab 32 -y outputfile.3gp

Thursday, October 16, 2008

Want to Lean Basic Japanese ?

Here:
http://web-japan.org/kidsweb/language/quickjapanese/

--
Knowledge is power. Power corrupts. You are now more corrupted.

MySQL Arbitrary Ordering

Arbitrary Ordering in MySQL

Note: The examples in this article use the world database which you can download from http://www.mysql.com

One frequent problem encountered in MySQL programming is how to get your data in the order that you want. Many times the simple ORDER BY clause is insufficient.

For example, let's say you know that you are interested in countries where the following languages are spoken: Urdu, Zulu, and Wolof. To find those countries you would be simple:

SELECT * FROM countrylanguage WHERE Language IN ('urdu', 'zulu', 'wolof');

This returns a table of the countries in no particular order.

What if you are most interested in Wolof? You would like country where Wolof is spoken to be returned first.

SELECT * FROM countrylanguage WHERE Language IN ('urdu', 'zulu', 'wolof') ORDER BY Language

This will return Urdu countries first, where ORDER BY Language DESC will return Zulu first.

How can this be done? Some suggest using a temporary table and a join, but I prefer a more elegant (and easier to program) solution. Drum roll please… The CASE statement.

SELECT *,
CASE Language
WHEN 'Wolof' THEN 1
WHEN 'Zulu' THEN 2
WHEN 'Urdu' THEN 3
ELSE NULL
END AS orderMe
FROM countrylanguage
WHERE Language IN ('Urdu', 'Zulu', 'Wolof')
ORDER BY orderMe;

Beautiful, ain't she? What is going on here?
First, SELECT * will select all columns.
Second, the CASE statement tests the "Language" column. Skip down to END, this is where the structure of the CASE statement ends. After that, AS sets a column name of "orderMe" for the output of the case statement. Back up to the WHERE clauses. In plain English, what happens is if the Language column has the value of 'Wolof' then set orderMe to be 1. If it's 'Zulu' orderMe will be 2, etc. If is none of these, make orderMe NULL.
It then limits the list to the three languages, and most importantly orders the list by the values of orderMe.

This statement first returns the countries that speak Wolof, then Zulu, the Urdu.

Great, you say, how about some practical applications? All right.
E-Commerce: feature certain products at the top of the page by ordering based on an arbitrary list of product IDs.
Document Management: Present the user with a document that matches the language preferences of the user's browser.
Non-supported languages: Sort using sort orders for language not natively supported by MySQL such as Klingon or that language you and your sister made up. (There are better ways to do this is you have control over your server.)

Knowledge is power. Power corrupts. You are now more corrupted.

Thursday, October 9, 2008

Image Cache Problem

Take me hours to googling around. Trying so many header suggestion, none of them work.

Here is my problem:
I have a page that upload picture.
After upload i display the new picture.
The picture name is the same before and after, ( rename the old one with new one ).
The picture on that page still referring to the old picture ....

The solution. Give the image src a random number .... (code it appropritely)

$randomnumber  = time();

<img src=myimage.jpg?$randomnumber >


This work immediatlly...

Centos 7 reset root/ any user lost password / lockout due to cant remember password

1. Need to be in front of the terminal. (Physically if not vm). 2. Reboot the server 3. Press 'e' in the GRUB2 boot screen. 3. bunch...