Tips for Optimizing MySQL Queries (That don’t suck)

The rule in any situation where you want to opimize some code is that you first profile it and then find the bottlenecks. Mr. Silverton, however, aims right for the tippy top of the trees. I’d say 60% of database optimization is properly understanding SQL and the basics of databases. You need to understand joins vs. subselects, column indices, how to normalize data, etc. The next 35% is understanding the performance characteristics of your database of choice. COUNT(*) in MySQL, for example, can either be almost-free or painfully slow depending on which storage engine you’re using. Other things to consider: under what conditions does your database invalidate caches, when does it sort on disk rather than in memory, when does it need to create temporary tables, etc. The final 5%, where few ever need venture, is where Mr. Silverton spends most of his time. Never once in my life have I used SQL_SMALL_RESULT.


Good problems, bad solutions

There are cases when Mr. Silverton does note a good problem. MySQL will indeed use a dynamic row format if it contains variable length fields like TEXT or BLOB, which, in this case, means sorting needs to be done on disk. The solution is not to eschew these datatypes, but rather to split off such fields into an associated table. The following schema represents this idea:

CREATE TABLE posts (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
author_id int UNSIGNED NOT NULL,
created timestamp NOT NULL,
PRIMARY KEY(id)
);

CREATE TABLE posts_data (
post_id int UNSIGNED NOT NULL.
body text,
PRIMARY KEY(post_id)
);

That’s just…yeah

Some of his suggestions are just mind-boggling, e.g., “remove unnecessary paratheses.” It really doesn’t matter whether you do SELECT * FROM posts WHERE (author_id = 5 AND published = 1) or SELECT * FROM posts WHERE author_id = 5 AND published = 1. None. Any decent DBMS is going to optimize these away. This level of detail is akin to wondering when writing a C program whether the post-increment or pre-increment operator is faster. Really, if that’s where you’re spending your energy, it’s a surprise you’ve written any code at all

My list

Let’s see if I fare any better. I’m going to start from the most general.

Benchmark, benchmark, benchmark!

You’re going to need numbers if you want to make a good decision. What queries are the worst? Where are the bottlenecks? Under what circumstances am I generating bad queries? Benchmarking is will let you simulate high-stress situations and, with the aid of profiling tools, expose the cracks in your database configuration. Tools of the trade include supersmack, ab, and SysBench. These tools either hit your database directly (e.g., supersmack) or simulate web traffic (e.g., ab).

Profile, profile, profile!

So, you’re able to generate high-stress situations, but now you need to find the cracks. This is what profiling is for. Profiling enables you to find the bottlenecks in your configuration, whether they be in memory, CPU, network, disk I/O, or, what is more likely, some combination of all of them.

The very first thing you should do is turn on the MySQL slow query log and install mtop. This will give you access to information about the absolute worst offenders. Have a ten-second query ruining your web application? These guys will show you the query right off.

After you’ve identified the slow queries you should learn about the MySQL internal tools, like EXPLAIN, SHOW STATUS, and SHOW PROCESSLIST. These will tell you what resources are being spent where, and what side effects your queries are having, e.g., whether your heinous triple-join subselect query is sorting in memory or on disk. Of course, you should also be using your usual array of command-line profiling tools like top, procinfo, vmstat, etc. to get more general system performance information.

Tighten Up Your Schema

Before you even start writing queries you have to design a schema. Remember that the memory requirements for a table are going to be around #entries * size of a row. Unless you expect every person on the planet to register 2.8 trillion times on your website you do not in fact need to make your user_id column a BIGINT. Likewise, if a text field will always be a fixed length (e.g., a US zipcode, which always has a canonical representation of the form “XXXXX-XXXX”) then a VARCHAR declaration just adds a superfluous byte for every row.

Some people poo-poo database normalization, saying it produces unecessarily complex schema. However, proper normalization results in a minimization of redundant data. Fundamentally that means a smaller overall footprint at the cost of performance — the usual performance/memory tradeoff found everywhere in computer science. The best approach, IMO, is to normalize first and denormalize where performance demands it. Your schema will be more logical and you won’t be optimizing prematurely.

Partition Your Tables

Often you have a table in which only a few columns are accessed frequently. On a blog, for example, one might display entry titles in many places (e.g., a list of recent posts) but only ever display teasers or the full post bodies once on a given page. Horizontal vertical partitioning helps:

CREATE TABLE posts (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
author_id int UNSIGNED NOT NULL,
title varchar(128),
created timestamp NOT NULL,
PRIMARY KEY(id)
);

CREATE TABLE posts_data (
post_id int UNSIGNED NOT NULL,
teaser text,
body text,
PRIMARY KEY(post_id)
);
The above represents a situation where one is optimizing for reading. Frequently accessed data is kept in one table while infrequently accessed data is kept in another. Since the data is now partitioned the infrequently access data takes up less memory. You can also optimize for writing: frequently changed data can be kept in one table, while infrequently changed data can be kept in another. This allows more efficient caching since MySQL no longer needs to expire the cache for data which probably hasn’t changed.

Don’t Overuse Artificial Primary Keys

Artificial primary keys are nice because they can make the schema less volatile. If we stored geography information in the US based on zip code, say, and the zip code system suddenly changed we’d be in a bit of trouble. On the other hand, many times there are perfectly fine natural keys. One example would be a join table for many-to-many relationships. What not to do:

CREATE TABLE posts_tags (
relation_id int UNSIGNED NOT NULL AUTO_INCREMENT,
post_id int UNSIGNED NOT NULL,
tag_id int UNSIGNED NOT NULL,
PRIMARY KEY(relation_id),
UNIQUE INDEX(post_id, tag_id)
);
Not only is the artificial key entirely redundant given the column constraints, but the number of post-tag relations are now limited by the system-size of an integer. Instead one should do:

CREATE TABLE posts_tags (
post_id int UNSIGNED NOT NULL,
tag_id int UNSIGNED NOT NULL,
PRIMARY KEY(post_id, tag_id)
);

Learn Your Indices

Often your choice of indices will make or break your database. For those who haven’t progressed this far in their database studies, an index is a sort of hash. If we issue the query SELECT * FROM users WHERE last_name = 'Goldstein' and last_name has no index then your DBMS must scan every row of the table and compare it to the string ‘Goldstein.’ An index is usually a B-tree (though there are other options) which speeds up this comparison considerably.

You should probably create indices for any field on which you are selecting, grouping, ordering, or joining. Obviously each index requires space proportional to the number of rows in your table, so too many indices winds up taking more memory. You also incur a performance hit on write operations, since every write now requires that the corresponding index be updated. There is a balance point which you can uncover by profiling your code. This varies from system to system and implementation to implementation.

SQL is Not C

C is the canonical procedural programming language and the greatest pitfall for a programmer looking to show off his database-fu is that he fails to realize that SQL is not procedural (nor is it functional or object-oriented, for that matter). Rather than thinking in terms of data and operations on data one must think of sets of data and relationships among those sets. This usually crops up with the improper use of a subquery:

SELECT a.id,
(SELECT MAX(created)
FROM posts
WHERE author_id = a.id)
AS latest_post
FROM authors a
Since this subquery is correlated, i.e., references a table in the outer query, one should convert the subquery to a join.

SELECT a.id, MAX(p.created) AS latest_post
FROM authors a
INNER JOIN posts p
ON (a.id = p.author_id)
GROUP BY a.id

Understand your engines

MySQL has two primary storange engines: MyISAM and InnoDB. Each has its own performance characteristics and considerations. In the broadest sense MyISAM is good for read-heavy data and InnoDB is good for write-heavy data, though there are cases where the opposite is true. The biggest gotcha is how the two differ with respect to the COUNT function.

MyISAM keeps an internal cache of table meta-data like the number of rows. This means that, generally, COUNT(*) incurs no additional cost for a well-structured query. InnoDB, however, has no such cache. For a concrete example, let’s say we’re trying to paginate a query. If you have a query SELECT * FROM users LIMIT 5,10, let’s say, running SELECT COUNT(*) FROM users LIMIT 5,10 is essentially free with MyISAM but takes the same amount of time as the first query with InnoDB. MySQL has a SQL_CALC_FOUND_ROWS option which tells InnoDB to calculate the number of rows as it runs the query, which can then be retreived by executing SELECT FOUND_ROWS(). This is very MySQL-specific, but can be necessary in certain situations, particularly if you use InnoDB for its other features (e.g., row-level locking, stored procedures, etc.).

MySQL specific shortcuts

MySQL provides many extentions to SQL which help performance in many common use scenarios. Among these are INSERT ... SELECT, INSERT ... ON DUPLICATE KEY UPDATE, and REPLACE.

I rarely hesitate to use the above since they are so convenient and provide real performance benefits in many situations. MySQL has other keywords which are more dangerous, however, and should be used sparingly. These include INSERT DELAYED, which tells MySQL that it is not important to insert the data immediately (say, e.g., in a logging situation). The problem with this is that under high load situations the insert might be delayed indefinitely, causing the insert queue to baloon. You can also give MySQL index hints about which indices to use. MySQL gets it right most of the time and when it doesn’t it is usually because of a bad scheme or poorly written query.

And one for the road…

Last, but not least, read Peter Zaitsev’s MySQL Performance Blog if you’re into the nitty-gritty of MySQL performance. He covers many of the finer aspects of database administration and performance.

Source

Web Applications Security

At my present job I am responsible for web applications administration and security. I lead automation team in all implementation aspects, including project management, process analysis, workflow design, configuration data set-up, systems interface development, system installation, testing, training, go-live, and post-implementation monitoring. One of the major challanges in web applications domain is web development security.


There are lots of web applications security risks. This post summarizes top ten web applications security risks for the year 2010 identified by The Open Web Application Security Project (OWASP).

1. Injection
Injection flaws, such as SQL, OS, and LDAP injection, occur when untrusteddata is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing unauthorized data.

2. Cross-Site Scripting (XSS)
Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications that enables malicious attackers to inject client-side script into web pages viewed by other users. An exploited cross-site scripting vulnerability can be used by attackers to bypass access controls such as the same origin policy.

3. Broken Authentication and Session Management
Application functions related to authentication and session management are often not implemented correctly, allowing attackers to compromise passwords, keys, session tokens, or exploit other implementation flaws to assume other users’ identities.

4. Insecure Direct Object References
A direct object reference occurs when a developer exposes a reference to an internal implementation object, such as a file, directory, database record, or key, as a URL or form parameter. An attacker can manipulate direct object references to access other objects without authorization, unless an access control check is in place.

5. Cross-Site Request Forgery (CSRF)
Cross Site Request Forgery (also known as XSRF, CSRF, and Cross Site Reference Forgery) works by exploiting the trust that a site has for the user. Site tasks are usually linked to specific urls i.e. http://www.banksite.com/transfer.php?amount=100&account=12345) allowing specific actions to be performed when requested.

6. Security Misconfiguration
Good security requires having a secure configuration defined and deployed for the application, frameworks, application server, web server, database server, and platform. All these settings should be defined, implemented, and maintained as many are not shipped with secure defaults. This includes keeping all software up to date, including all code libraries used by the application.

7. Insecure Cryptographic Storage
Protecting sensitive data with cryptography has become a key part of most web applications. Simply failing to encrypt sensitive data is very widespread. Applications that do encrypt frequently contain poorly designed cryptography, either using inappropriate ciphers or making serious mistakes using strong ciphers. These flaws can lead to disclosure of sensitive data and compliance violations.

8. Failure to Restrict URL Access
Frequently, the only protection for a URL is that links to that page are not presented to unauthorized users. However, a motivated, skilled, or just plain lucky attacker may be able to find and access these pages, invoke functions, and view data. Security by obscurity is not sufficient to protect sensitive functions and data in an application. Access control checks must be performed before a request to a sensitive function is granted, which ensures that the user is authorized to access that function.

9. Insufficient Transport Layer Protection
Insufficient transport layer protection allows communication to be exposed to untrusted third-parties, providing an attack vector to compromise a web application and/or steal sensitive information. Websites typically use Secure Sockets Layer / Transport Layer Security (SSL/TLS) to provide encryption at the transport layer.


10. Unvalidated Redirects and Forwards
Web applications frequently redirect and forward users to other pages and websites, and use untrusteddata to determine the destination pages. Without proper validation, attackers can redirect victims to phishing or malware sites, or use forwards to access unauthorized pages.

Structure of a program C++





Probably the best way to start learning a programming language is by writing a program. Therefore, here is our first program: 

1
2
3
4
5
6
7
8
9
10
// my first program in C++

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World!";
  return 0;
}
Hello World!


The first panel (in light blue) shows the source code for our first program. The second one (in light gray) shows the result of the program once compiled and executed. To the left, the grey numbers represent the line numbers - these are not part of the program, and are shown here merely for informational purposes.

The way to edit and compile a program depends on the compiler you are using. Depending on whether it has a Development Interface or not and on its version. Consult the compilers section and the manual or help included with your compiler if you have doubts on how to compile a C++ console program.

The previous program is the typical program that programmer apprentices write for the first time, and its result is the printing on screen of the "Hello World!" sentence. It is one of the simplest programs that can be written in C++, but it already contains the fundamental components that every C++ program has. We are going to look line by line at the code we have just written:

// my first program in C++
This is a comment line. All lines beginning with two slash signs (//) are considered comments and do not have any effect on the behavior of the program. The programmer can use them to include short explanations or observations within the source code itself. In this case, the line is a brief description of what our program is. 
#include <iostream>
Lines beginning with a hash sign (#) are directives for the preprocessor. They are not regular code lines with expressions but indications for the compiler's preprocessor. In this case the directive #include <iostream> tells the preprocessor to include the iostream standard file. This specific file (iostream) includes the declarations of the basic standard input-output library in C++, and it is included because its functionality is going to be used later in the program. 
using namespace std;
All the elements of the standard C++ library are declared within what is called a namespace, the namespace with the name std. So in order to access its functionality we declare with this expression that we will be using these entities. This line is very frequent in C++ programs that use the standard library, and in fact it will be included in most of the source codes included in these tutorials.
int main ()
This line corresponds to the beginning of the definition of the main function. The main function is the point by where all C++ programs start their execution, independently of its location within the source code. It does not matter whether there are other functions with other names defined before or after it - the instructions contained within this function's definition will always be the first ones to be executed in any C++ program. For that same reason, it is essential that all C++ programs have a main function. The word main is followed in the code by a pair of parentheses (()). That is because it is a function declaration: In C++, what differentiates a function declaration from other types of expressions are these parentheses that follow its name. Optionally, these parentheses may enclose a list of parameters within them. Right after these parentheses we can find the body of the main function enclosed in braces ({}). What is contained within these braces is what the function does when it is executed.
cout << "Hello World!";
This line is a C++ statement. A statement is a simple or compound expression that can actually produce some effect. In fact, this statement performs the only action that generates a visible effect in our first program. cout is the name of the standard output stream in C++, and the meaning of the entire statement is to insert a sequence of characters (in this case the Hello Worldsequence of characters) into the standard output stream (cout, which usually corresponds to the screen). cout is declared in the iostream standard file within the std namespace, so that's why we needed to include that specific file and to declare that we were going to use this specific namespace earlier in our code. Notice that the statement ends with a semicolon character (;). This character is used to mark the end of the statement and in fact it must be included at the end of all expression statements in all C++ programs (one of the most common syntax errors is indeed to forget to include some semicolon after a statement).
return 0;
The return statement causes the main function to finish. return may be followed by a return code (in our example is followed by the return code with a value of zero). A return code of 0 for the main function is generally interpreted as the program worked as expected without any errors during its execution. This is the most usual way to end a C++ console program.

You may have noticed that not all the lines of this program perform actions when the code is executed. There were lines containing only comments (those beginning by //). There were lines with directives for the compiler's preprocessor (those beginning by #). Then there were lines that began the declaration of a function (in this case, the main function) and, finally lines with statements (like the insertion into cout), which were all included within the block delimited by the braces ({}) of the main function.

The program has been structured in different lines in order to be more readable, but in C++, we do not have strict rules on how to separate instructions in different lines. For example, instead of 

1
2
3
4
5
int main ()
{
  cout << " Hello World!";
  return 0;
}


We could have written:

int main () { cout << "Hello World!"; return 0; }


All in just one line and this would have had exactly the same meaning as the previous code.

In C++, the separation between statements is specified with an ending semicolon (;) at the end of each one, so the separation in different code lines does not matter at all for this purpose. We can write many statements per line or write a single statement that takes many code lines. The division of code in different lines serves only to make it more legible and schematic for the humans that may read it.

Let us add an additional instruction to our first program:

1
2
3
4
5
6
7
8
9
10
11
12
// my second program in C++

#include <iostream>

using namespace std;

int main ()
{
  cout << "Hello World! ";
  cout << "I'm a C++ program";
  return 0;
}
Hello World! I'm a C++ program


In this case, we performed two insertions into cout in two different statements. Once again, the separation in different lines of code has been done just to give greater readability to the program, since main could have been perfectly valid defined this way:

int main () { cout << " Hello World! "; cout << " I'm a C++ program "; return 0; } 


We were also free to divide the code into more lines if we considered it more convenient: 

1
2
3
4
5
6
7
8
int main ()
{
  cout <<
    "Hello World!";
  cout
    << "I'm a C++ program";
  return 0;
}


And the result would again have been exactly the same as in the previous examples.

Preprocessor directives (those that begin by #) are out of this general rule since they are not statements. They are lines read and processed by the preprocessor and do not produce any code by themselves. Preprocessor directives must be specified in their own line and do not have to end with a semicolon (;).

Comments


Comments are parts of the source code disregarded by the compiler. They simply do nothing. Their purpose is only to allow the programmer to insert notes or descriptions embedded within the source code. 

C++ supports two ways to insert comments: 

1
2
// line comment
/* block comment */ 


The first of them, known as line comment, discards everything from where the pair of slash signs (//) is found up to the end of that same line. The second one, known as block comment, discards everything between the /* characters and the first appearance of the */ characters, with the possibility of including more than one line.
We are going to add comments to our second program: 

1
2
3
4
5
6
7
8
9
10
11
12
/* my second program in C++
   with more comments */

#include <iostream>
using namespace std;

int main ()
{
  cout << "Hello World! ";     // prints Hello World!
  cout << "I'm a C++ program"; // prints I'm a C++ program
  return 0;
}
Hello World! I'm a C++ program


If you include comments within the source code of your programs without using the comment characters combinations //, /* or */, the compiler will take them as if they were C++ expressions, most likely causing one or several error messages when you compile it.

Free Download Source Code Visual Basic

All the files are zip files so you require a version of Winzip before you can load them up.
Inside the zip you will find *.vbp , *.frm , *.bas these can just be loaded in Visual Basic.


New Source Code:


Easy Source Code:

Typing and display text in reverse at real time
Yet another tic tac toe program
Copying files from one place to another showing the windows move box
Letting the user click to draw with another line joining them together
Shows the memory available with additional information
Moves the form to the position clicked
Shows whether the user is connected by the internet not using a modual
Shows the amount of space avalible on the system in percentages
Detects which color mode the computer is in eg High color.
Delete a sub directoryThis is a simple scribbler!
A better Version of tic tak a toe
Requested about 90 + times finally here
Tic tak a toe
Resizing forms
This is an advanced scroll system
Advanced password system including countdown.
Gradually changing text from blue -> Black 
Finding text in a text box
What is in your clipboard text or picture
Deleting files
The program beeps if you go past a line
Formatting numbers so eg before 12345678 now 123,456,678.
Moving a form
A Visual Basic Game which uses random numbers
Loading multi entries from a file
Playing AVI Video's
Hatching
Pop up box after 10 sec's (V.simple)
Dragging files onto form
Store some information to a file
Close another application
Make a program that senses any key presses
Tell the percentage of power in a battery
Make the computer shutdown log off etc
A very simple password checker
Load another application

Harder Source Code:

A complete game of pacman including level editor and other options
More developed alladvantage program has more options and works better.
Simular to the windows based clock. ( Analog )
3D maze game - has amazing graphical display
Makes Alladvantage think you are active and only
3D line drawrings moving
Removes the icon on the toolbar of the form
Replace the text from one letter to another
Scroll though picture boxe using scroll bars
Query excel in to doing a sumConvert Visual Basic code into HTML code.Copying files from one place to another showing the windows move boxLetting the user click to draw with another line joining them togetherShows the memory available with additional informationCreates Windows shortcutsDetects how long windows has been running forGet the build of your windows and your operating system details.Is user connected to internet?
Simplified version of VBMail sends email
A Visual Basic FTP Program
Get your current ip address
Any Internet Based Chat System
Virtual Pinball source code
How to browse though dial up connection details or stealing dial up passwords
Space invaders
Rotating some text
This program notes what programs are running
This tells the user what the mouse's status is
Where is your Cd rom drive located?
Quick view of clipart files
Counting down in hour's, min's and second's
Mapping NETWORK drives
Opening the Start bar
Have a calendar for life!
This program watches directories and reports if they have been changed in any way
Make the computer open the cd-rom drive
This makes Windows registry keys!
Time Expired Program
Show an icon on the systray
Show what all the fonts installed on your computer look like!
Make a picture box move with the press of a button
Save images, edit images etc etc a complete utility! 
Add some text to a file
Maximize another application
Disable CTRL + ALT + DEL
Move mouse to position
Set Wallpaper of Background
Get current exe loaded on computer.
Colour calculator
An example of a 3d object movement strings
Get Microsoft Word to spell check textboxes
Have a form with a hole in it
Get your windows password username
Tool Bar, Status Bar, Menu bars, Examples
Phone Book
Make a form have no close button
Make a form ONTOP
Hide the task bar
Make a popup application box
Moving the mouse and recording the exact height and width it was clicked on

Development Environment Visual Basic

Learning the ins and outs of the Development Environment before you learn visual basic is somewhat like learning for a test you must know where all the functions belong and what their purpose is. First we will start with labelling the development environment.




The above diagram shows the development environment with all the important points labelled. Many of Visual basic functions work similar to Microsoft word eg the Tool Bar and the tool box is similar to other products on the market which work off a single click then drag the width of the object required. The Tool Box contains the control you placed on the form window. All of the controls that appear on the Tool Box controls on the above picture never runs out of controls as soon as you place one on the form another awaits you on the Tool Box ready to be placed as needed.

Tool box Visual Basic


You may have noticed that when you click on different controls the Properties Window changes slightly this is due to different controls having different functions. Therefore more options are needed for example if you had a picture then you want to show an image. But if you wanted to open a internet connection you would have to fill in the remote host and other such settings. When you use the command () you will find that a new set of properties come up the following will provide a description and a property.

6 Ways to Speed up your PC

By following a few simple guidelines, you can maintain your computer, help increase your PC speed, and help keep it running smoothly. This article discusses how to use the tools available in Windows 7, Windows Vista, and Windows XP Service Pack 3 to help make your computer faster, maintain your computer efficiently, and help safeguard your privacy when you're online.


Note: Some of the tools mentioned in this article require you to be logged on as an administrator. If you aren't logged on as an administrator, you can only change settings that apply to your user account.

1. Remove spyware, and help protect your computer from viruses

Spyware collects personal information without letting you know and without asking for permission. From the websites you visit to user names and passwords, spyware can put you and your confidential information at risk. In addition to privacy concerns, spyware can hamper your computer's performance. To combat spyware, you might want to consider using the PC safety scan from Windows Live OneCare. This scan is a free service that helps check for and remove viruses.

Download Microsoft Security Essentials for free to help guard your system in the future from viruses, spyware, adware, and other malicious software (also known as malware). Microsoft Security Essentials acts as a spyware removal tool and includes automatic updates to help keep your system protected from emerging threats.

The Microsoft Windows Malicious Software Removal Tool is another utility that checks computers running Windows 7, Windows Vista, Windows XP, Windows 2000, and Windows Server 2003 for infections by specific, prevalent malicious software, including Blaster, Sasser, and Mydoom, and helps remove any infection found.

2. Free up disk space

The Disk Cleanup tool helps you to free up space on your hard disk to improve the performance of your computer. The tool identifies files that you can safely delete and then enables you to choose whether you want to delete some or all of the identified files.

Use Disk Cleanup to:

Remove temporary Internet files.

Delete downloaded program files, such as Microsoft ActiveX controls and Java applets.

Empty the Recycle Bin.

Remove Windows temporary files, such as error reports.

Delete optional Windows components that you don't use.

Delete installed programs that you no longer use.

Remove unused restore points and shadow copies from System Restore.

Tip: Typically, temporary Internet files take the most amount of space because the browser caches each page you visit for faster access later.


3. Speed up access to data

Disk fragmentation slows the overall performance of your system. When files are fragmented, the computer must search the hard disk as a file is opened (to piece it back together). The response time can be significantly longer.

Disk Defragmenter (sometimes shortened to Defrag by users) is a Windows utility that consolidates fragmented files and folders on your computer's hard disk so that each occupies a single space on the disk. With your files stored neatly end to end, without fragmentation, reading and writing to the disk speeds up.

When to run Disk Defragmenter
In addition to running Disk Defragmenter at regular intervals (weekly is optimal), there are other times you should run it, too, such as when:

You add a large number of files.

Your free disk space totals 15 percent or less.

You install new programs or a new version of the Windows operating system.


Running Disk Cleanup and Disk Defragmenter on a regular basis is a proven way to help keep your computer running quickly and efficiently. If you'd like to learn how to schedule these tools and others to run automatically, please read Speed up your PC: Automate your computer maintenance schedule.

4. Detect and repair disk errors

In addition to running Disk Cleanup and Disk Defragmenter to optimize the performance of your computer, you can check the integrity of the files stored on your hard disk by running the Error Checking utility.

As you use your hard drive, it can develop bad sectors. Bad sectors slow down hard disk performance and sometimes make data writing (such as file saving) difficult or even impossible. The Error Checking utility scans the hard drive for bad sectors and scans for file system errors to see whether certain files or folders are misplaced.

If you use your computer daily, you should run this utility once a week to help prevent data loss.
Run the Error Checking utility:

5. Learn about ReadyBoost

If you're using Windows 7 or Windows Vista, you can use ReadyBoost to speed up your system. A new concept in adding memory to a system, it allows you to use non-volatile flash memory—like a USB flash drive or a memory card—to improve performance without having to add additional memory.


6. Upgrade to Windows 7

If you try all the previous remedies and your computer still isn't as fast as you would like it to be, you may want to consider updating to Windows 7.

Find out if your computer can run Windows 7 using the Upgrade Advisor.

Compare Window 7 editions.

Read a third-party review of Windows 7 by David Pogue of The New York Times.

If the Windows 7 Upgrade Advisor determines that your computer can't run Windows 7 and you still have the need for speed, it might be time for a new computer. There are some great deals on new computers right now:

MySQL Programming Languages

The most popular relational database manager is installed on 11 million servers in 2009.
Acquired by Sun in 2008 he became after the takeover by Oracle of Sun, ownership of the former, and one wonders about its future.




Brief history

MySQL was created in 1995 by David Axmark, Allan Larsson and Michael Widenius who founded the company MySQL AB to market it.
In June 2000 it passed under the GPL.

The company was acquired by Sun on February 26 2008. Which was itself acquired by Oracle on 20 April 2009.

Design

MySQL is optimized for reading, it is well suited for the Web where viewing pages is more frequent than their creation or update.
It supports concurrent requests for multiple users (unlike for example, SQLite which can process only one at a time).
It is compatible with SQL2 and the procedural language PL/SQL since version 5.

Licensing

It is an open source software under GPL 2, but it is dual-licensed. Using it is free except when choosing to purchase a proprietary license.
These other licenses allow you to integrate it in various software whose license is not compatible with GPL.

Programming

Most programming languages can be used to access the DBMS, so to make requests. The most commonly used languages are PHP and Java.
The M first letter MySQL gives a letter to LAMP (Linux Apache MySQL PHP), a popular server system of websites.

Database engines

Lot of engines may be used by the system. Including:
- MyISAM. The default engine.
- InnoDB. More powerful.
- BerkeleyDB.
And many others.

The future of MySQL

After the acquisition of Sun by Oracle, a database company that has in MySQL, which is a free product, a competitor to its paid products, how can be the future of MySQL?

Here is the opinion of the creator of MySQL on the subject ...

Creators of MySQL are no longer at Sun says Michael Widenius, the creator of MySQL. He proposed the creation of a "Fedora" for MySQL, an independent project free of any commercial attaches.

Site

MySQL



Forks

Being an open source software it can be distributed and modified by other sources. Examples:

OurDelta. A superset of MySQL.
MariaDB. From the creator of MySQL.
Drizzle.

PHP Programming Languages

PHP was designed in 1995 by Rasmus Lerdorf because it needs a free tools to program Web pages and released under the name PHP/FI, (Personal Home Pages / Form Interpreter),.
He has developped it further with the help of other programmers and made it open source for the community of users. A new engine was created for PHP 3 and a new name given: PHP Hypertext Preprocessor in 1997. The Zend engine was created in 1999 for PHP 4.
PHP 5 was released in 2004, it is more object-oriented and supports XML.
A PHP script produces web pages, and may be embedded inside HTML code as JavaScript but works server side. It is similar to C, but dynamic variables and more prototype based. A server must be configured to execute the interpreter on pages with .php extensions, and to send resulting modified HTML pages on the network.
PHP is the P of LAMP, a popular architecture that includes the Linux operating system, the Apache server and the MySQL database manager.
A project to port PHP to .NET exists and is named Phalanger.


Features

- All those of C, but typed variables, plus:
- Object oriented.
- Dynamic untyped variables prefixed by $.
- Associatives arrays (tables with keys).
- A foreach construct to scan arrays and iterators.
- Lot of APIs dedicated to the standard of the web and databases.

The language

Syntax

The langage is not case-sensitive.
Floating point numbers are denoted by a dot followed by a number or zรฉro.
Variables are prefixed with a $ symbol and no type is specified in advance.
Literal string which use the "" notation are evaluated for variables and numbers.
Some symbols:

must enclose a PHP program.
# or // starts a comment.
array( "1" =>" "a, ...) is a dictionary.

Control structures

The if structure has elsif and else options.
if(x < 10)
{
   echo "$x less than 10\n";
}
else
{  
   echo 'etc...\n'
}
The while structure:
while(expr)

{
    ... 
} 

Function or method

The definition starts with the function keyword, followed by the name and the list or arguments separated by commas, and the body is enclosed between { and }. 
The return keyword in the body of the definition allows to return one value.
function funcname( arguments )
{
   ...statements...
   return(x);
}

Class

class name

{
    ...
}

The body is similar to the global code.

Why use PHP?

PHP is an Internet tool, running server side, it is a scripting language that may be embedded into web pages. It is usable for processing large data and build a HTML page that display the results. (JavaScript is convenient for dynamic change of HTML pages.)
PHP 5 is a simpler concurrent to Java as an application server and a platform for web applications and web services. It eases the use of XML, MySQL, SQLite, SOAP and many database systems.
PHP is the most used language to build a CMS, content management system.

See also

  • PHP 6. Differences with the versions 4 and 5.
PHP 6 with Unicode support is abandoned.PHP Editors

Includes a PHP editor. (Windows)Extension to Eclipse for a PHP development interface.IDE from Sun written in Java for PHP and other languages.Online editor.

Development tools

The official website, home of the interpreter and the language.
Windows Apache Linux PHP local server. Put your PHP script in the www sub-directory at root of the Wamp directory and they can run as on a true server, with MySQL requests and PhpMyAdmin or SQLite Manager to manage the databases!
Extension to build graphical user interfaces for Windows. Demo.

Scripts and tutorials

Learn with examples to make PHP scripts for using SQL on a website.
Directories of sites and scripts (mainly HotScript, Scriptsearch, NeedScript et Scripts).
Sample code

Displaying chars of a string.
$str = "demo";
$len = strlen($str);
for($i = 0; $i < $len; $i++) 
{ 
  echo $str[$i];
} 
Displaying elements of a list.
$arr = array(1,2,3 );
$arr = array_merge($arr, array( 4,5));
$sub = array_slice(|$arr, 1,3);
foreach($sub $as $num) 
{
  echo $num;
} 
>> should display:  234

Pascal Programming Languages

Pascal was designed in 1970 by Nicklaus Wirth to impose programmers a structured programming style. Pascal has successors, Modula and Oberon, which add module and access to system resources. But because these features has been added to Pascal itself by implementors, mainly Borland, the successors have not succeded. Pascal is used to teach programming. The main commercial port is Delphi, followed by Kylix.



Features

- strictly structured programming.
- imports allows including functions from external modules, with no headers required as in C.
- procedures and functions, the formers returning values.
- objects added further.

Why use Pascal?

It is often used for teaching. This is a classical language (more is not possible) that imposes a rigourous programming. The Delphi version is a specialized client-server programming tool and its IDE allows to build easily applications

Sites and tools

Visual development environment by Borland. Free to build commercial products.
An object oriented port of Pascal, near the Turbo Pascal 7 from Borland. Free and open source.
Another open source compiler.
Resources.
  • Kylix. Cross-platform IDE.

Sample code
Merging and displaying lists.
cont str = 'demo';
var i:int; len:int;
begin
      len:= length(str);
      for i:=0 to len do
      begin 
         write(str[i]);
      end; 
end;

Free Download C to C++ Converter

Made in 2001 by Denis Sureau, convert sources of a C project to C++. Written in Python, it runs on any system.

GNU GPL license. Requires Python 2.x.





Features

Script that translates C to C++ in some steps:
  1. generating classes,
  2. converting functions to methods,
  3. replacing calls to functions by references to methods.
The main script calls other specialized ones but you can also proceed step by step and modify manually the results of a step before to start the next one.
This tool is not easy to use. It is for experienced programmers.

Why use it?

Converting your project to C++ prevent conflits in identifiers, and ease to reuse your code.

Requirements

  • You need for Python to run the scripts.
  • The converter works better with a well formatted and indented source. C, C++ formatters are available on the net.
  • You need for makeinfo to rebuild the doc.
Before to start the scripts, you should print the CTOCPP.INFO manual,
and read carefully the step by step chapter.

Included tools

  • Search Performs search / replacement in a file.
  • Mover Move a whole project from one or more directories to a single or several differents directories. Of course, the "#include" statements are updated...
  • Mklist Given the name of the file that holds the main function, recursively make a list of all files in a projet.
Documentation
  • Manual.

Download

Free Download Borland C++ Compiler version 5.5

Borland C++ Compiler version 5.5 Free Download - AVAILABLE NOW
Our classic ANSI C/C++ compiler technology, the Borland. C++ 5.5 Compiler and associated command line tools, is now available for free download on our Web site.


Before you download the free C++ compiler, we encourage you to download a trial of C++Builder, our latest C++ development environment for Windows. C++Builder includes our newest C++ compiler with new C++0x support and Boost Libraries, code editor, local and remote debugging, visual designers, database connectivity, Windows 7 and touch/gesture support, and much, much more.

The Borland C++ 5.5 Compiler is the high performance foundation and core technology of Inprise/Borland's award-winning Borland C++Builder product line and is the basis for Inprise/Borland's recently announced C++Builder(TM) 5 development system for Windows 95, 98, NT, and Windows 2000.

"Over the past 11 years, millions of developers have relied on the speed and quality of the Borland C/C++ compiler technology. Beginning this month, every developer will have free access to the latest Borland C/C++ compiler for building high quality Windows, Internet, and distributed applications," said Michael Swindell, director of product management at Inprise/Borland. "With Open Source development exploding on all platforms, developers can now rely on a leading commercial ANSI C++ compiler to be available for any Windows based Open Source project. In addition, with our forthcoming Linux C++ tools, development with Borland C++ tools today is an investment in Linux development for tomorrow."

"Since many programmers learned how to develop using Borland tools, it's great to see Inprise/Borland offer its widely-used compiler free of charge," said Sally Cusack, an analyst and research manager at International Data Corporation. "Developers who download this compiler will subsequently have a seamless path to the rich tools and capabilities of Borland C++Builder 5 for RAD, Internet, User Interface, database, and distributed solutions."

About Borland C++ Compiler 5.5

The Borland C++ Compiler 5.5 (BCC) is the foundation and core technology of C++Builder 5. Borland C++ Compiler 5.5 is a blazingly fast 32-bit optimizing compiler. It includes the latest ANSI/ISO C++ language support including, the STL (Standard Template Library) framework and C++ template support and the complete Borland C/C++ Runtime Library (RTL). Also included in the free download are the Borland C/C++ command line tools such as the high performance Borland linker and resource compiler.

The free download includes:

Borland C++ Command Line Tools

  • Borland C++ Compiler v5.5 (bcc32)
  • Borland Turbo Incremental Linker (tlink32)
  • Borland Resource Compiler / Binder (brc32, brcc32)
  • C++ Win32 Preprocessor (cpp32)
  • ANSI/OEM character set file conversion utility (fconvert)
  • Import Definitions utility to provide information about DLLs (impdef)
  • Import Library utility to create import libraries from DLLs (implib)
  • Borland Turbo Dump to structurally analyse EXE, OBJ and LIB files (tdump)
  • Librarian for symbol case-conversion, creating extended libraries and modifying page size (tlib)
Included Libraries
  • Borland C/C++ Runtime Library
  • ANSI/ISO Standard Template Library (STL)

Download the free compiler now

About Borland C++Builder 5
Borland C++Builder 5 is the most powerful ANSI C++ visual development environment for rapidly building Internet, desktop, Client/Server, and distributed applications with middleware flexibility and open standards.

C++ For system programming

C++, created in 1981 by Bjarne Stroutstup, adds object features to C, while remaining compatible with it.
The goal of C++ goals was to be portable.

C++ is an ISO standard named C++ 98. A new version will succeed in 2009, it will be C++ 09 and its main features are defined.




Features

C++ describes classes into header files, and body of methods into source files. By declaring instances of classes you can reuses set of variables and methods without to define them again.
Memory management is unchanged.
Overloading allows to declare a method with different parameters.
Classes inherits one from other and share their methods.

Why use C++?

I think that C++ it will be replaced by C# in the near future. It remains the best tool for system programming.

Sites and tools

Visual Studio Express by Microsoft. Free IDE for C++ developement with ou without .NET.
Cross-platform IDE based on the Qt framework. A graphical user interface designer is embedded (click on .ui files).
IDE and tool integrator with a plugin for C++. (Java)
This is the Windows version of GCC, the free compiler from the Free Software Fondation. The Linux version is available from the gnu site.
Fast C, C++ and Objective C compiler, frontend to LLVM that produces intermediate code. May be integrated into an IDE.
Another C and C++ compiler, with a useful doc on C. (Windows)
  • C to C++
Converts a C project to C++. (Python 2)
A complete tutorial on C++ with sources of examples.

Libraries

Boost. Open source libraries for C++.

Objective C sites

Objective C is another object oriented version of the C language, simpler than C++.
  • GnuStep
A free IDE for objective-C. For Linux and Windows.

Sample code

Merging and displaying lists.
string s = "demo" + "trail";
int l = s.length();
for(int i = 0; i < l; i++)
{
   char c = s[i];
   printf("%c\n", c);
} 

HTML (hypertext markup language)

HTML, the hypertext markup language is a subset of SGML, (invented by IBM in 1969) defined by the W3C consortium. It is a document description language, that uses tags for properties. This is the format recognized by web browsers.
DHTML, dynamic HTML, is the combination of HTML and JavaScript. The CSS, cascading style sheet, adds the style sheet feature of word processor to HTML.


Features
- Tag based, uses < > for delimiters.
- Unrecognized statements are ignored.
- Unlimited embedding of constructs.


Why use HTML?

Writing web pages, but is also a standard format for any documents displayable locally by a web browser or a recent word processor.

Sample Code

The Pascal Architecture

Pascal is a strongly typed, block structured programming language. The "type" of a Pascal variable consists of its semantic nature and its range of values, and can be expressed by a type name, an explicit value range, or a combination thereof. The range of values for a type is defined by the language itself for built-in types, or by the programmer for programmer defined types. Programmer-defined types are unique data types defined within the Pascal TYPE declaration section, and can consist of enumerated types, arrays, records, pointers, sets, and more, as well as combinations thereof. When variables are declared as one type, the compiler can assume that the variable will be used as that type throughout the life of the variable (whether it is global to the program, or local to a function or procedure). This consistent usage of variables makes the code easier to maintain. The compiler detects type inconsistency errors at compile time, catching many errors and reducing the need to run the code through a debugger. Additionally, it allows an optimizer to make assumptions during compilation, thereby providing more efficient executables. As John Reagan, the architect of Compaq Pascal, writes, "it was easy to write Pascal programs that would generate better code than their C equivalents" because the compiler was able to optimize based on the strict typing.

Declaring variables in Pascal is straightforward. The Pascal VAR declaration section gives the programmer the ability to declare strings, integers, real numbers and booleans (to name a few built-in types), as well as to declare variables as records or other programmer defined types. A variable defined as a RECORD allows a single variable to track several data components (or fields).

Type
Employee_type = (Hourly, Salary, SalaryExempt);
InputRec = RECORD
emp_name: packed array[1..30 ] of char;
social: packed array[1..9] of char;
salary: real;
emp_type: Employee_type;
end;

Var
index: integer;
ratio: real;
found: boolean;
inpf: file of InputRec;

Figure 1: Sample Code - Types and Records

Pascal also supports recursion, a powerful computing tool that allows a function or procedure within a program to make calls to itself. This allows for elegant and efficient coding solutions, eliminating the need for tedious loops. A good example of recursion is the following Pascal solution to the classic Towers of Hanoi puzzle (see Figure 2). The puzzle is to take a stack of disks in increasing sizes from top to bottom, and move them from the first peg to the second peg, with the rule that a disk must always be placed on a disk larger than itself, and only one disk can be moved at a time.


Program TowersOfHanoi(input,output);

Var
disks: integer;

Procedure Hanoi(source, temp, destination: char; n: integer);

begin
if n > 0 then
begin
Hanoi(source, destination, temp, n - 1);
writeln('Move disk ',n:1,' from peg ',source,' to peg ',destination);
Hanoi(temp, source, destination, n - 1);
end;
end;

begin
write('Enter the number of disks: ');
readln(disks);
writeln('Solution:');
Hanoi('A','B','C',disks);
end.

Figure 2: Sample Recursive Code รณ Towers of Hanoi Solution

The solution to the Towers of Hanoi puzzle involves moving all but one disk from peg to peg, repeatedly, until the entire stack has moved from one peg to the other. The elegance of recursion is that this solution is illustrated clearly, without mundane loops and logic checks. The three steps of the solution are depicted by three lines of code. The movement of a stack, regardless of size, is always done by a call to Hanoi, thus ensuring that the rules are adhered to.

Pascal eliminates the need for clumsy "goto" statements by supporting REPEAT/UNTIL, WHILE/DO, and FOR loops; by providing an intelligent CASE statement; and by providing a means to consolidate common lines of code into PROCEDUREs and FUNCTIONs. Using the English words of BEGIN and END to delimit blocks of code within a clause, enforcing strong typing, providing ordinal-based arrays, and other useful linguistic features, Pascal facilitates the production of correct, reliable, and maintainable code. Any language can be commented and indented for better readability, but Pascal, by the nature of its syntax and architecture, encourages structured programming practices and allows the programmer to focus on developing solutions. It's important to emphasize this element of Pascal. Even programmers with the most sophisticated and disciplined of programming styles will find themselves in a time crunch. With deadlines quickly approaching, it's likely that a programmer will focus more on achieving a result and less on making the code understandable for future maintenance. The key to Pascal is that a programmer tasked with maintaining Pascal code will be able to make the same assumptions that the compiler makes about program flow and data usage. This gives the maintenance programmer a fighting chance of figuring out the behavior, purpose, and operating conditions of the code, even if itรญs poorly-written.

Block Structure

In An Introduction to Programming and Problem Solving with Pascal, the author writes,
"A block is a sequence of declarations, a begin, a sequence of statements that describes actions to be performed on the data structures described in the declarations, and an end." A Pascal program consists of a PROGRAM heading, which names the program, followed by a block. Within that main program block, there exist subprograms, each of which have their own heading followed by a block. Within each block, there can be inner blocks, and within each inner block there can exist further inner blocks. In essence, a Pascal program is a hierarchical construction of blocks ; hence, Pascal is a block-structured programming language.

All data values declared at the beginning of a block are accessible to the code within the block, including inner blocks, but not to any others. The usefulness of a block-structured language, therefore, is not only the modularization of the program, but also the protection of data that is exclusive to one set of modules within a program from compromise by other modules.

Style

The flow of Pascal code often reads like plain English, with code indentation playing a crucial role in visualizing conditional clauses. The BEGIN and END statements are key elements of Pascal's architecture. These clause delimiters are often misunderstood and misused, leading even the most avid Pascal programmers to question their usefulness. Used properly, however, they are a vital to visualizing code clauses within a program. Take, for example the Towers of Hanoi solution (see Figure 3 below).

Program TowersOfHanoi(input,output);

Var
disks: integer;

Procedure Hanoi(source, temp, destination: char; n: integer);

begin
if n > 0 then
begin
Hanoi(source, destination, temp, n - 1);
writeln('Move disk ',n:1,' from peg ',source,' to peg ',destination);
Hanoi(temp, source, destination, n - 1);
end;
end;

begin
write('Enter the number of disks: ');
readln(disks);
writeln('Solution:');
Hanoi('A','B','C',disks);
end.

Figure 3: Indentation Style & Block Structured Code

The BEGIN and END statements are colored in Figure 3 to illustrate a point. While these words are not typically colored as such in an editor, when a programmer is trained on these words, they are just as visually apparent. Further, when setting the indentation of the clause to match the BEGIN and END statement, a virtual line of sight is established. When clauses are imbedded within other clauses, sometimes several layers deep, these lines of sight become very helpful in deciphering the hierarchy of clauses and flow of execution. Less work is required to understand and rediscover the flow of a program and the programmer can therefore focus on the logic and algorithms.

In a small program with very few lines of code, this advantage is not quite as apparent. The usefulness, however, increases exponentially as complexity and size increase. For example, take an extensive program of several pages, with long clauses that may pass through several page breaks (see Figure 4 below).




Figure 4: Indentation of Block Structured Code รณ At A Glance

The virtual lines of sight are illustrated in Figure 4 with blue lines, and the code itself is purposely blurred to focus attention on the indentation. In a large program, determining the program flow is required each time the programmer attacks the code. The quicker that flow is apparent, the sooner the programmer can get to work at updating the code.

Manageability

Programmers at the beginning of a project face creating a solution to a real world problem using computer code. Over time, however, programmers face the ongoing problem of maintaining and enhancing the computer code as the users needs change and grow. Increasing the manageability of code, both for initial implementation and for long term maintenance, decreases the amount of effort required to work the problem.

Pascal increases manageability of code by enforcing strong typing, supporting block structured programming, and providing a syntax which is easy to read. These aspects of Pascal provide both immediate and long-term benefits to the programmer. Strong typing removes much of the guess work from interpreting data structures. Block structured programming breaks down a program into a hierarchy of tasks. The decomposition of a programming problem into a hierarchy of tasks enhances the manageability of the problem. Finally, the more visually apparent the blocks are within a program, and the more the code reads like English, the easier it is to interpret the program flow, thereby further increasing manageability.

These aspects of Pascal provide the programmer tools for long term manageability in supporting legacy code as well. Each time a programmer attacks legacy code, the logic flow and data structures must be understood before any work can be done efficiently. Guessing incorrectly at what the code or data structures were designed to do can lead to costly bugs in the software. The sooner the programmer can understand the code clearly and with confidence, the quicker the programmer can get "into the groove" of debugging or enhancing the code. Each block, variable, and line of code may represent only seconds of time saved using Pascal, but these seconds add up. A penny saved may not seem like much, but a penny saved every second, 60 hours a week, 50 weeks a year is over $100,000. Moreover, when it takes a very long time to find the groove, the effort to understand the code becomes so frustrating that it impedes creativity and productivity.

Related Posts Plugin for WordPress, Blogger...
 
Design by Kholid Al Fakhry | Bloggerized by Lasantha - Premium Blogger Themes | Kholid Al Fakhry