Showing posts with label programing and coding. Show all posts
Showing posts with label programing and coding. Show all posts
Sunday, June 2, 2013
Friday, May 31, 2013
Introductions
Playing with images in VB6 can be much interesting if there is a useful source code id available. Today I’m going to share a very basic image viewer. While writing it I tried to avoid any complexities which might confuse the beginners. This is all fu so I named it FunPicViewer.Features
1. Zoom In2. Zoom Out
3. Best Fit of Image
4. Cut
5. Copy
6. Paste
7. Print
8. Drag and Drop feature to open Image
Download
File Format: .zipFile Download Size: 13.9 KB
Sunday, May 26, 2013
Introduction
Today I am going to share a basic/simple video player source code. This code is written in VB 6. I have named it TS Video Player. It uses the msdxm.ocx as the core component for the player. There are thousands of examples are available about this ocx over the internet, but mine is different as it unveils many unknown features of this component. Let’s see its features:- Custom Context Menu over Video!
- Custom Cursor over Video!
- Media Speed Control
- Custom Position Bar
- Custom Volume Bar
- Custom Balance Bar
- Custom File Title
- Custom Media Time/Duration
- Custom Media Control (Play, Pause, Stop, Mute, etc)
- Disabled appearance of Windows Media Player Help Menu when F1 key is pressed
Concluding Comments
This is just a rough version. I will share a much refined and complete version in future. Hopefully, later versions will contain much more features.Some Instructions
Note: You need to make sure that the msdxm.ocx and comdlg32.ocx exists in your system folder. If these are missing then you should copy them in the said folder. Alternatively you can also keep these files directly in your project’s folder, i.e. in TS Video Player’s folder.Requests
Your comments are always welcomed in this blog. Please let me know about the usability as well as weak points of this code. I shall try to develop/rectify it as per your proposals/suggestions. You can also suggest new features for further enrichment of this code.Download
File Format: .zipFile Download Size: 57.1 KB
Wednesday, March 27, 2013
How to create link to scroll to a certain part of the post
I haven't found a viable solution (for Blogger) anywhere else. So I have invented it by myself. And it does not corrupt the post when you switch between Compose and HTML mode. You can easily create such links that link to a certain part of a post to elaborate on the topic, without leaving/refreshing the page.
===================================================
===================================================
The HTML code of the above layout will be like this:
Note: replace [post_url] with the post's url/link to the post
The
The main trick lies in
Now we can make our url point to anchor "what". All we have to do is create an url and place a hash (#) and then the anchor name. In the compose mode select the text that you want a link of and then create a link with the:
Replace [post_url] with the url of the post where the anchor is.
So the final code is:
(Replace [posturl] with link of the post you have created.)
See this tip in action: http://lazplanet.blogspot.com/p/faq.html
Example Scenario:
You may have created a post like a question-answer one. And you want a contents at the top conataining only the questions and the answer is written below the contents. You want your questions to be clickable and when you click them you want to be scrolled to the answer.===================================================
- What is your name?
- Who are you?
What is your name? <---- you want a link to scroll down here
I am Adnan Shameem.
Who are you? <---- and here as well
I am a graphics designer and a programer.===================================================
The HTML code of the above layout will be like this:
Solution
So what you can do is, create an anchor to set the position where to scroll down to. Edit the HTML of the post and add the code where you want your anchor to be placed (in our case the answer):Note: replace [post_url] with the post's url/link to the post
The
name="what" means that the anchor name is "what".The main trick lies in
href="[post_url]#". According to this page if you only use the usual anchor code (that is <a name="what"></a>), then when you go back to Compose mode it will be replaced by (<a href="" name="what"></a>) and in the post a weird url will appear. When you link the current page with only a # afterwards (href="[post_url]#"), nothing happens except the browser scrolls to the top of the page. It is like dummy link that does nothing. We specify href="..." part in order to stop blogger from automatically adding href="" to our code. This method is logical cannot be corrupt when you switch between Compose and HTML mode.Now we can make our url point to anchor "what". All we have to do is create an url and place a hash (#) and then the anchor name. In the compose mode select the text that you want a link of and then create a link with the:
Replace [post_url] with the url of the post where the anchor is.
So the final code is:
(Replace [posturl] with link of the post you have created.)
See this tip in action: http://lazplanet.blogspot.com/p/faq.html
Saturday, March 23, 2013
Sometimes in life, you just want to change! You want to change your dresses, your friends, your job, your furniture and what not. When designing a webpage it is normal that you have coded your webpage with many fonts. This is normal when you have pasted many codes from various websites.
In the above scenario, it may be possible that you want uniform font faces in all of your page elements. The truth is, you can do that with CSS and more surprisingly with one line of code.
So without further ado, here is the code:
In the code above, we set Arial and other fonts as the font of all the elements. The browser will look for the fonts one after another. If the Arial font is not present in the computer then Helvetica will be used and so forth.
Remember, if you use a font which has a space ( ) in its name, you will have to enclose the name in single quotes (').
In the above scenario, it may be possible that you want uniform font faces in all of your page elements. The truth is, you can do that with CSS and more surprisingly with one line of code.
So without further ado, here is the code:
In the code above, we set Arial and other fonts as the font of all the elements. The browser will look for the fonts one after another. If the Arial font is not present in the computer then Helvetica will be used and so forth.
Remember, if you use a font which has a space ( ) in its name, you will have to enclose the name in single quotes (').
Wednesday, March 6, 2013
TTS or Text-To-Speech is a technology which allows the speech synthesis or artificial speaking of computers. Another way to explain it is that it says what you write. You can write whatever text you want and it will say it! It can read poems or essays or even say bad words to someone if you wish! It is a technology which, well, speaks for itself! ;-)
eSpeak is a command line TTS tool which is almost useless when used alone. But it seems like a powerful and flexible TTS engine when used in your software through command line calls. eSpeak is open source and a better option than Festival (according to me). eSpeak supports Windows/Linux/Mac platforms. The windows version uses Microsoft SAPI5.
http://sourceforge.net/projects/lazarus/files/
(Choose Windows 32bit if you are not sure about your processor architecture.)
http://espeak.sourceforge.net/download.html
The file should be named something like: espeak-1.46.02-win.zip
Create a directory where you will save the source code for the program. For example, D:\LazarusCodes\TTS-eSpeak-Test
Assuming that you installed eSpeak in the default installation directory C:\Program Files\eSpeak , now copy the installation folder to D:\LazarusCodes\TTS-eSpeak-Test. Thus you will have a D:\LazarusCodes\TTS-eSpeak-Test\eSpeak\command_line directory.
You may now uninstall eSpeak (we will use --path parameter to specify espeak-data directory which will allow us to use eSpeak in the stand alone mode, which will allow the user to use eSpeak even when it is not installed! It is a rather portable option. Cool, right?!)
2. Create a new Project, type of Application.
3. Toggle to form design mode (F12). Drop a TMemo and a TButton in the form.
4. Also go to System tab and add a TProcess in the form. Set the Options to [poUsePipes] (Click the arrow/plus on the left and set poUsePipes to true). Also set Show Window to swoHIDE. (swoHide option hides the console window when running the command line tool.)
5. Write the following code:
procedure TForm1.Button1Click(Sender: TObject);
begin
// We will call the eSpeak command line exe
Process1.CommandLine:= ExtractFilePath(Application.ExeName) + 'eSpeak\command_line\espeak.exe' +
' --path=eSpeak ' +
' "' + Memo1.Text + '"';
Process1.Active:=True;
end;
6. Click File -> Save All and save your project in the directory D:\LazarusCodes\TTS-eSpeak-Test.
When you want to distribute the code don't forget to Strip and upx the exe to reduce its size. You will need to distribute the exe and the eSpeak directory to show off your skills to your friends or your keen users!
Sometimes when the user enters large text often there is need to stop the speaking. You can drop another TButton (or TSpeedButton or TBitButton .... ) and double click it. Then write the command:
Process1.Terminate(0);
You can also drop a TEdit on the form and use it to specify further parameters to modify speed, pitch, volume, word gap and many other options of the spoken text. Now the Button1 command may change like this (or anything else, come on you are the programer!):
// We will call the eSpeak command line exe
Process1.CommandLine:= ExtractFilePath(Application.ExeName) + 'eSpeak\command_line\espeak.exe' +
' --path=eSpeak ' + Edit1.Text + ' ' +
' "' + Memo1.Text + '"';
Command line parameters and explanations are available here:
http://espeak.sourceforge.net/commands.html
Reference:
http://www.rolfware.de/delphi/espeak_example.html
http://www.freepascal.org/docs-html/rtl/sysutils/executeprocess.html
http://www.mail-archive.com/lazarus@lists.lazarus.freepascal.org/msg26498.html
eSpeak is a command line TTS tool which is almost useless when used alone. But it seems like a powerful and flexible TTS engine when used in your software through command line calls. eSpeak is open source and a better option than Festival (according to me). eSpeak supports Windows/Linux/Mac platforms. The windows version uses Microsoft SAPI5.
Step 1: Download and Install Lazarus
We will use Lazarus as our IDE (Integrated Development Environment) which is powered by Free Pascal. If you haven't installed it yet then you can download it for free from here:http://sourceforge.net/projects/lazarus/files/
(Choose Windows 32bit if you are not sure about your processor architecture.)
Step 2: Download and install eSpeak (we'll use as stand alone later)
Download and install eSpeak from here:http://espeak.sourceforge.net/download.html
The file should be named something like: espeak-1.46.02-win.zip
Create a directory where you will save the source code for the program. For example, D:\LazarusCodes\TTS-eSpeak-Test
Assuming that you installed eSpeak in the default installation directory C:\Program Files\eSpeak , now copy the installation folder to D:\LazarusCodes\TTS-eSpeak-Test. Thus you will have a D:\LazarusCodes\TTS-eSpeak-Test\eSpeak\command_line directory.
You may now uninstall eSpeak (we will use --path parameter to specify espeak-data directory which will allow us to use eSpeak in the stand alone mode, which will allow the user to use eSpeak even when it is not installed! It is a rather portable option. Cool, right?!)
Step 3: Code in Lazarus
1. Open Lazarus.2. Create a new Project, type of Application.
3. Toggle to form design mode (F12). Drop a TMemo and a TButton in the form.
4. Also go to System tab and add a TProcess in the form. Set the Options to [poUsePipes] (Click the arrow/plus on the left and set poUsePipes to true). Also set Show Window to swoHIDE. (swoHide option hides the console window when running the command line tool.)
5. Write the following code:
procedure TForm1.Button1Click(Sender: TObject);
begin
// We will call the eSpeak command line exe
Process1.CommandLine:= ExtractFilePath(Application.ExeName) + 'eSpeak\command_line\espeak.exe' +
' --path=eSpeak ' +
' "' + Memo1.Text + '"';
Process1.Active:=True;
end;
6. Click File -> Save All and save your project in the directory D:\LazarusCodes\TTS-eSpeak-Test.
Step 4: Run and test
Press F9 to compile and see the program how it works. Write something in the Memo and press the button. You will hear your words spoken. You may customize the interface (add images, speedbuttons, change captions etc.) and Run (F9) again.When you want to distribute the code don't forget to Strip and upx the exe to reduce its size. You will need to distribute the exe and the eSpeak directory to show off your skills to your friends or your keen users!
Step 5: Enhance the code (Optional)
Sometimes when the user enters large text often there is need to stop the speaking. You can drop another TButton (or TSpeedButton or TBitButton .... ) and double click it. Then write the command:
Process1.Terminate(0);
You can also drop a TEdit on the form and use it to specify further parameters to modify speed, pitch, volume, word gap and many other options of the spoken text. Now the Button1 command may change like this (or anything else, come on you are the programer!):
// We will call the eSpeak command line exe
Process1.CommandLine:= ExtractFilePath(Application.ExeName) + 'eSpeak\command_line\espeak.exe' +
' --path=eSpeak ' + Edit1.Text + ' ' +
' "' + Memo1.Text + '"';
Command line parameters and explanations are available here:
http://espeak.sourceforge.net/commands.html
Reference:
http://www.rolfware.de/delphi/espeak_example.html
http://www.freepascal.org/docs-html/rtl/sysutils/executeprocess.html
http://www.mail-archive.com/lazarus@lists.lazarus.freepascal.org/msg26498.html
Saturday, August 11, 2012
Now, it is the Ramadan season, the month-long fasting for the Muslims. Everyday their start and ending time for fasting (Sahri and Iftar, respectively) is not the same. It changes due to the change in sunrise and sunset time. It is something that is impossible or somewhat illogical to remember. So for the users' convenience I have created a code which will automatically give users the time of Sahri and Iftar for that day. And moreover, it does not require you to mumble with the MySQL databases or tables. It works based on a CSV file which we use to store the times for everyday.
Step 1: Create the data (but no database!)
Let's say, we are a little bit lazy for creating a database for this widget sort of thing. And besides, it is for one month only. So, we are going to store our time data in a .csv file. .csv files are easy to edit with any spreadsheet editor such as, Microsoft Office Excel, LibreOffice Calc, OpenOffice.org Calc etc. You are required to start your spreadsheet program then create a sheet like as follows (if you can't make this, download the source zip and get a copy of it):We have 6 columns: roza, day, month, year, sahri, iftar
roza: the serial number for the roza.
day, month, year: the date to which the roza is for.
sahri: time for Sahri.
iftar: time for Iftar.
Now that the csv file (or in our case the flat-file database) is ready, we can move on to the next part.
Step 2: Download CSV parser class
You can google for a php csv parser class, but mine seems to be working fine. So I am going to use "parseCSV" for getting our data from the csv file.- Go to http://code.google.com/p/parsecsv-for-php/
- Go to Downloads link and download the class package.
- Extract the package and copy parsecsv.lib.php file to your working folder/directory
Step 3: Write code
We are using PHP for coding. So here is an example php file for simple usage.<html>
<body>
<?php
require_once 'parsecsv.lib.php';
$csv = new parseCSV();
$csv->auto('timesdb.csv');
$search_day = date('j');
$search_month = date('n');
$data = $csv->data;
for ($i = 0; $i <= count($data) - 1; $i++) {
if ($data[$i]['day'] == $search_day && $data[$i]['month'] == $search_month) {
echo '<h3>Today ('.date('d-m-y').'):</h3>';
echo '<p>Sahri: ' . $data[$i]['sahri'] . ', Iftar: ' . $data[$i]['iftar'].'</p>';
echo '<h3>Tomorrow:</h3>';
echo '<p>Sahri: ' . $data[$i+1]['sahri'] . ', Iftar: ' . $data[$i+1]['iftar'].'</p>';
}
}
?>
</body>
</html>
Conclusion
Well, there you have it! A Sahri and Iftar widget for your website which requires no database. We use 3 files: (1) the CSV file, (2) CSV Parser, (3) PHP file. You may store the class file and the data file in separate directories for the sake of clarity in your project's directory structure.Here is the download link to the source files: http://www.divshare.com/download/19329139-21d
Feel free to comment in case you need any help or have a way to improve it.
Sunday, February 5, 2012
Thursday, February 2, 2012
Saturday, November 28, 2009
We sometimes see that page loading time is mentioned at the bottom. For example, "Page loaded in x.xx seconds." Below is the method for showing that in your php pages.
1. Add the following code at the top of the .php file:
2. Add the following code at the end of the .php file:
After this code is installed you may see something like this:
Page loaded in 0.65 seconds.
1. Add the following code at the top of the .php file:
function utime (){
$time = explode( " ", microtime());
$usec = (double)$time[0];
$sec = (double)$time[1];
return $sec + $usec;
}
$start = utime();
?>
2. Add the following code at the end of the .php file:
$end = utime(); $run = $end - $start; echo "Page loaded in " . substr($run, 0, 5) . " seconds.";
?>
After this code is installed you may see something like this:
Page loaded in 0.65 seconds.
Subscribe to:
Posts (Atom)











