Archive for March, 2010
Using Delphi to quickly create applications
0This following article is a guest post by Sam Tyler
There are lots and lots of quick application builder programs that emerge constantly. Its hard to keep up with them all. You may have the need to create some great applications and then quickly package and turn them into a product that can be sold on a marketplace. In this regard, one software package that always hits the home run for me is Delphi. It first came out as the rapid application builder, then many early adopters were able to quickly see their returns investing on it. Creating a simple hello world is cheerful process that you can do it even on your first day programming delphi. Delphi to me is the visual pascal, or technically its the object pascal. Though a simple hello world application is around 300 kb, complex applications are much more less than what it would consume on other programming platforms.
So whenever i need a widget to promote and market my website, i resort to delphi, which is my fastest way of churning out applications. You may worry about the lack of extensions, never be. Delphi extensions or components by which they are called, are available in large. Those come with a package bundled together referred to as Visual component library. Now, you may have heard of VCL before in Visual C++, this is similar to that. If you can name a component you can get it online, for free or for a little price. One such freely available component is from a team, JEDI project. JEDI's Windows API library makes WinAPI much more accessible. Be it you need to fetch the multiple cpu's processing power or getting a bios version, its possible with a function, nothing could be better than this.
If you feel to try it out before you pay for it, get turbo delphi, which is free and let you see what delphi can really do for you. Like many programming packages, delphi progresses through versions. The one i have is Delphi 7, and still use it to date. Once you test drive with turbo delphi, you can confidently invest in the latest Delphi, which is Delphi 2010. After you have decided that delphi is for you, there are great places to learn this language completely. Places like delphi.about.com is all the meat and potatoes for learning the art of delphi with examples and free source code projects. Its when my learning curve picked up real quick and i became really better at this. Now after a month programming on delphi, im really excited to share my knowledge with you. Be it for creating a rapid application or just playing with it creating toys to expand my creative horizons i go to delphi. Oh i almost forgot, if you want to see the first application i created with delphi, just google, smartsys monitor and happy programming in delphi!
About author:
Sam Tyler is the founder of optimize-your-pc.org, the leading infopedia on computer errors such as ccsvchst, error code 39 and many more windows errors. If you find an error, the site has a solution to resolve it in a breeze!
Best website translation method
1Ok your website has grown. You want it in different languages but let's face it, it is a challenging task. I have worked on the process of translating several websites, ground up, and it really isn't hard. It is just quite boring, but easy after all.
My preferred method is by using PHP's built in function gettext(). If you are using a shared domain most chances are it is installed. If it isn't, or you run a VPS or dedicated hosting, ask your hosting administrator to install it.
To check whether you have the getttext module installed run the following script:
// Check if gettext is ready to use if(!function_exists("gettext")){ echo "gettext isn't installed"; }else{ echo "gettext is supported!"; }
Well once you see the message gettext is supported! you can carry on
Setting up localisation:
We need php to determine the current language. There are many many ways of doing so, however my preferred method is by using subdomains. From the point of view of a Search Engine, your content is new and it has it's own URL, and from your point of view it takes almost no extra effort.
So go to your website control panel if it is shared, if not simply create a new subdomain for each language and point it to the root. I recommend you use the standard two-letter code from the ISO 639 for each subdomain. For example if my website is http://djs-music.com, I would create the new subdomain for a Spanish version: http://es.djs-music.com (These links are from the latest website I developed, in different languages, so that you can see a working example)
If the default language is English, I wouldn't create a subdomain for that, I would simply leave it as default when there is no subdomain selected.
Now let's create a new php file called local.php, it will handle all this, at the top, we will set up an array with the available languages, the default one... etc
Inside local.php place the following code, it is ready to use so you shouldn't have to change anything:
<?php /* Localisation script by Alejandro U. Alvarez * http://urbanoalvarez.es * This has no license actually... But since I am sharing this please be kind, and link back* * -------------- CONFIGURATION ----------------- * */ // Write here all possible subdomains $langs = array('es','en','no'); // Defaults $defaultlang = 'en'; // Your website with no www // Place a \ before each . $webUrl = 'djs-music\.com'; // Your charset/codeset $codeset = "UTF8"; // Translations folder. // This is where you will have folders each named with the locale (i.e. en_EN) // It is recommended you put it in the root and name it locale $localePath = './locale'; // Translations files name // This is the name of the .mo files. It is recommended you name them messages.mo // Inside the localePath there should be one folder per translation // named with the locale (i.e. en_EN), and inside there should be a .mo file // preferably called messages.mo Place the name of the file here: $translationFile = 'messages'; /* ---------- NOW COMES THE ACTUAL CODE --------- */ // intial state $lang = false; $local = false; $defaultLocale = $defaultlang.'_'.strtoupper($defaultlang); // Get from domain: $url = parse_url($_SERVER["SERVER_NAME"]); if(!eregi('^(www\.)*('.$webUrl.')$',$url['path']) ){ $sub = substr($url['path'], 0, 2); //Returns lang code (2 letter) if(in_array($sub,$langs)){ $local = strtolower($sub).'_'.strtoupper($sub); $lang = $sub; } } if(!$local){ $local = $defaultLocale; } if(!$lang){ $lang = $defaultLang; } $_SESSION['lang'] = $lang; $_SESSION['locale'] = $local; // Set locale // Windows compatibility putenv('LANG='.$local.'.'.$codeset); putenv('LANGUAGE='.$local.'.'.$codeset); bind_textdomain_codeset($translationFile, $codeset); // Set locale putenv('LC_ALL='.$local.'.'.$codeset); setlocale(LC_ALL, $local.'.'.$codeset); bindtextdomain($translationFile, $localePath); textdomain($translationFile); ?>
Everything is explained in comments, so you shouldn't have any problems setting the file up. You should include this as high as possible in your code, but after you start a session with session_start();
Of course at the moment it will not work since we are missing all the important files! So let's move on.
Setting up our website for translation:
We now need to indicate which portions of our website are going to be translated. We will do this by wrapping the desired pieces of text in the gettext function, which has an abbreviated name _():
echo _('Text to be translated');
If you need more advanced strings, like text strings that contain variables inside them consider the following example:
I have in my website a text string that reads: echo "You are $years old"; This string is special, we cannot translate You are, and then old, because in other languages (Such as Spanish it wouldn't make sense). For cases like this we will use PHP's function sprintf:
(By the way, sprintf returns the string, printf prints the string, we use sprintf because we need the string returned in order to have it translated with gettext)
This function takes at least 2 parameters, the string, and one substitution. How it works is you place "Identifiers" inside the string, that sprintf changes for the corresponding value: Take a look at the previous example with printf:
echo _(sprintf("You are %d old",$years));
Now we can have it translated with the age in the exact position in other languages
Creating the translation folders and files:
We now need the .mo files that php's gettext uses for the translations. It is very easy as you will see:
If you have already checked the configuration at the top of the local.php file, there were two variables called $localePath and $translationFile, leave these to the defaults for now.
Go to the root of your website and create a new folder called locale, inside this folder, you will have to create one new folder for each language except for the default. So if your website is already in English, and you are going to translate it to Spanish, you should create a new folder inside locale called es_ES.
Now inside each of these folders (In my example inside the folder es_ES) you will have to create another folder called LC_MESSAGES. So your folder structure for the example would look like this:
./
- locale
- es_ES
- LC_MESSAGES
- es_ES
- Other folders and files in your root...
Now that the folder structure is set up, we need to get a gettext translation program. Download and install Poedit (Note that it has Windows, Mac and Linux versions, and that it's free)
Once in Poedit, go to File -> Catalogs manager. A pop-up window will appear, in it click the blank page icon to create a New Translations Project. This is useful to have all your Catalogs for one website under the same project.
When you click on New Translation project, a new window appears, enter the name you desire, and in the directories, click on New Item, and once there enter the exact path to your project root (i.e. C:\Username\projects\DJs-Music ) And click Ok.
Now close that and go to File -> New Catalog, a new window will pop up, this is a very important window:
Start in the tab Project Info (Default tab)
- Project name and version: This is just to help track the translation. You can enter for now Your Website 1.0
- Team: Only useful for translations with multiple teams. For example Spanish 1
- Email address: Same as before... spanish@yourwebsite.com
- Language: Select the language you are going to translate now (For example Spanish)
- Charset: IMPORTANT Make sure it matches the charset in your website (Preferably UTF-8)
- Source code charset: Your code charset (It's in the configuration area, preferably UTF-8)
- Plural forms: Leave it blank for now, that is quite advanced for now)
Now click on the tab Paths: Here you will have to add the paths inside your project where the php files containing strings you want to translate are. Click on the New Item icon to add one. If you want to add your root folder for example type .
If you want all files inside a folder called /more-files/, enter more-files\.
Forget the tab keywords for now, it is also for more advanced translations.
Click Ok, and now click on the Earth icon, in the left column (Original string) you should see all the text strings you enclosed between the function _(), if you don't see them go back and check all the previous steps.
Now go on and translate all the strings. To translate simply click on a string on the left column and enter the translation on the box at the bottom of the screen. At the bottom left you will see the translated percentage.
When you are done go to File -> Save as, and save it as messages.po inside the LC_MESSAGES folder for the corresponding language locale (So if this was the Spanish translation you would save this file inside locale/es_ES/LC_MESSAGES/)
As well as the messages.po file, you will see if you go to that folder another file called messages.mo, that is the one that you have to upload to your server in order for this to work.
Check everything:
Alright so let me walk you through all the steps you should have taken:
- Create the file local.php and include it in every file you want to translate
- Create the subdomains and point them to the root
- Configure all the variables in local.php
- Wrap all the text you want to translate in _('Your text here')
- Create the folder structure and the messages.mo files using Poedit
- Upload everything to the server
If you did all of this, everything should work fine. You can see a working example of this in DJs Music for example: English version, Spanish version
How did this go? Tell me in the comments and ask me any doubt
Always find the best topics and ideas
0You probably struggle to find new topics, and once you do, it's really hard to know how to title them. We want them good, concise, and "juicy", and that is not easy.
Well, there are lot's of people that read guides on writing, that use this "amazing" titles that "grab" people's attention. But well, who wants to spend that much time only for that?
For us that write tech blogs, it's easy to find the right tools online, and we have them at our fingertips. Imagine I wanted to write an article about the iPhone, what should I write it about?
I will go to Google Insights and there I will be able to look at the trends for each topic. That is the real secret, what people are looking for, what the want, right now.
So in my example, I will search for iPhone, to see what people want to know about it. At a glance I can see the interest of people on that subject over time, the main world countries of interest, and the best of it all, the exact searches they make!
The top searches for iPhone are:
- Unlock iPhone 3.1.3
- TaskPaper for iPhone
- New iPhone Apps
- iPad
- ... etc
So these are the areas of interest I should focus on. That is what people want, so that is what I will be giving them.
Another example:
Now you can probably start to see the advantages of this method. Let's suppose another case scenario, where I am an iPhone App developer, and I have no idea what to develop!
Let's see what apps people want, so I go again to Google Insight, and search for iPhone Apps, download app, and other keywords that will reveal the top searches for new apps:
- PayPal App
- SURFit
- Spotify
- White House App
- Cracked Apps
So those are the top searches people make. Note that this are far from being the top apps, they are just what people are looking for. It's important that you distinguish this. When you develop something, it should be completely different from the top solutions that already exist. You must do what people need, and that is what they search. And once you have the idea, inspire its design and usability in the other top solutions for other problems.
Good luck with finding your perfect niches!
C++ Quick guide: STL Vector
0In C++ we have what's called the Standard Template Library (STL) which provides a lot of useful shortcut functions that will help us develop our code.
Today I wanted to show you the basics of the vector library. How arrays will go from being a nightmare to the easiest thing ever in our C++ applications. If you have ever programmed anything in PHP, you'll realize that with the vector template, arrays become something quite similar as those in PHP.
Usage:
First, include the vector file using a normal include:
#include <vector>
We now have access to all of its functions. Let's see them in a sort of logical order.
Constructors:
We will use these to create our arrays, the way they work is very simple, we will use the keyword vector, followed by the type of data it will hold placed between < and >, for example vector<int> and then the name of our array.
// Creates a new vector a vector<int> a; // Creates a new vector b, copy of a vector<int> b(a); // Creates a new vector c, with 4 elements vector<int> c(4); // Creates a new vector d, with 3 elements, each with a value of 10 vector<int> d(3,10);
Now that we have the vectors initialized, let's learn how to do stuff with them:
Basic operations:
Using our newly created vectors is very easy:
// I'll be using our previously created vectors // Check this out, a hadn't any space assigned, but C++ extends it so that I can do this! : a[0] = 4; b = a; // Now c[1] is 4! : c[1] = b[0]; // c[0] is now 8: c[0] = c[1]+b[0];
Well as you have seen it's very easy to operate with them, let's now move on to some more advanced stuff:
Adding elements to our vector:
Before getting into vector functions I want to explain the use of iterators. An iterator is a pointer to an element in an array. We use them to walk through the array, element by element. This is how we set an iterator up:
vector<int>::iterator ite
There are a number of functions for this task, let's see some of them:
insert()
The function insert adds elements to a vector. There are several ways of doing so, I will show you each commented below:
// Let's set iter to after the last element iter = v.end(); // Now insert a 5 at that position iter = v.insert(iter, 5); // We can also insert multiple elements: iter = v.insert(iter, 5, 3); // This inserts 5 integers of value 3 at iter position
push_back()
This is more common than insert, it adds an element at the end of our vector:
v.push_back(6); // This adds a 6 at the end of v, expanding it if necessary
assign()
assign replaces elements in a vector, returning their position:
iter = v.assign(4, 10); // This will replace all elements in v with 4 copies of the integer 10
Removing elements from our vector:
Remember that for all my examples I am using the previously created vector v and the iterator iter. Let's take a look now at some functions for removing elements from our vectors:
erase()
Probably the most used function for this task, it usually takes one argument, an iterator pointing to the element we want to remove. We can also pass directly the number of that element:
v.erase(2); // Removes element at position 2 iter = v.erase(iter); // Removes element at position iter and then returns the next positio
erase() can also be used with two iterators instead of one, to remove elements in that range, for example:
v.erase(0,3); // To remove elements from 0 to 3
The same could be done with two iterators pointing to different elements.
pop_back()
This function removes the last element of a vector.
v.pop_back();
clear()
Be careful with this function! As you can guess, it removes all elements from a vector,
v.clear();
A bit more information on iterators:
We also have some functions to work on iterators. I will keep on using the previously declared iterator iter for these examples, let's take a look at the basics:
iter = v.begin(); // Sets iter to first element iter = v.end(); // Sets it to the last element iter = v.rbegin(); //Sets it to the first element in reverse order (Same with rend() ) // After iter is set to the start or end, both in normal and reverse order, we can use...: iter++; iter--; // ...to increase or decrease the iterator // To get the value of the element the iterator is pointing to we can simply access the pointed memory spot: int value = *iter;
And this is the basics of the Vector STL, hope you enjoyed it
Sync issues: iPhone not detected by iTunes (Windows)
5Note that this is for Windows only!
Some people have been experiencing this problem lately: You plugin in your iPhone, the Camera detected window pops up, iTunes may even open, but the iPhone doesn't sync or even show in the sidebar!
Here is how to fix it:
- With the iPhone plugged it, close iTunes
- Go to your Control Panel
- Open up Administrative Tools (This name may vary depending on your language. The icon shows a folder, a computer and a hummer)
- Open up Services
- Locate the service "Apple Mobile Device"
Now open up iTunes, and your iPhone should show up! I have tested this on Windows XP only, if it works for you on other versions please let me know to update the post
