# Dušan Jovanović

## Software & Web Development, Programming, Engineering, Graphic Design

Posts tagged tumblrize

# Insertion Sort, Algorithm Source Code for C/C++

Insertion sort is one of the most common sorting algorithms you’ll ever bump into. It is very simple and it takes time roughly equal to c*n2 to sort n items, where c is an undependable constant.

Input: a sequence of n unsorted numbers

Output: a sequence of permuted n numbers from the input such that those numbers are sorted in most of the time decreasing order.

Image source: “Introduction to Algorithms”, The MIT Press

The image above explains the process used on an array of six numbers, as you can see at the end the result is a sorted array.

### How it works

Indexes of numbers in this array are present above the rectangles, their connected values, on the other hand, appear in the rectangles. Have in mind that in C++ indexing starts at zero, and ends at length - 1.
In each iteration, the black rectangle represents the key taken from the current indexed number in for loop, which is being compared with all values in gray rectangles from it’s left. Gray arrows represent moving gray values one position to the right, and black arrow represent moving the key when appropriate.

### Code realization

void insertion_sort(int a[], int length){
int i, j, key;
for(i = 1; i = 0 && a[j] > key){
a[j + 1] = a[j];
j--;
}
a[j + 1] = key;
}
}

This function takes two parameters: the “a” array and the “length” integer that represent the number of it’s elements. It goes through the array as shown on the images and repositions it’s values so that you get a sorted array in decreasing order as an output which can be tested using printf function.

There is also a variant for getting the output in non-decreasing order:

void inverted_insertion_sort(int a[], int length){
int i, j, key;
for(i = length - 2; i >= 0; i--){
key = a[i];
j = i + 1;
while(j  key){
a[j - 1] = a[j];
j++;
}
a[j - 1] = key;
}
}

This algorithm is very popular in terms of sorting short arrays, but for more complex situations you should better check out my Algorithms category and find what you need. Also, make sure to understand the code completely buy following through the function with your own example and figuring it out. Good luck!

# Essential Firefox Add-Ons for Web Designers and Developers

Firefox is by it’s nature a web browser good for designers and developers, it’s collection of add-ons just makes it better. Here is the list of, in my opinion, must have and most useful Firefox add-ons for web designers and developers, both front-end and back-end.

### 1. Firebug

[caption id=”attachment_150” align=”alignnone” width=”700” caption=”Firebug Console”][/caption]

Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page. It is the world’s most popular front-end development (web design) add-on. In detail, you can see every element’s characteristics like width, length, type, etc.

### 2. Web Developer

[caption id=”attachment_151” align=”alignnone” width=”333” caption=”Web Developer”][/caption]

The Web Developer extension adds various web developer tools to a browser. By default, it is displayed as a toolbar in Firefox. It is a place containing all useful shortcuts and tools you could possibly need.

### 3. FireFTP

FireFTP is a free, secure, cross-platform FTP/SFTP client for Mozilla Firefox which provides easy and intuitive access to FTP/SFTP servers. With an add-on like FireFTP you don’t have to use other FTP Clients, but access your server without leaving your browser.

### 4. FirePHP

FirePHP enables you to log to your Firebug Console using a simple PHP method call.

### 5. HTML Validator

HTML Validator is a Mozilla extension that adds HTML validation inside Firefox and Mozilla. The number of errors of a HTML page is seen on the form of an icon.This is a must-have if you deal with the HTML code a lot, it will check everything for all possible errors like syntax mistakes for example.

### 6. CSS Usage

[caption id=”attachment_152” align=”alignnone” width=”700” caption=”CSS Usage”][/caption]

CSS Usage is made to be used with Firebug, that I mentioned earlier. This add-on uncovers unused CSS style rules. It is used for making your CSS files as light as possible.

### 7. SEO Doctor

Search Engine Optimization (SEO) is one of your website’s most crucial and most important parts if you would like to get some traffic. This is why this add-on is important. It gives you a score between 0% and 100% depending how good your site’s SEO is. It highlights mistakes and tells you how to repair them.

### 8. YSlow

YSlow analyzes web pages and why they’re slow based on Yahoo!’s rules for high performance web sites.

### 9. CollorZilla

[caption id=”attachment_153” align=”alignnone” width=”200” caption=”ColorZilla”][/caption]

Advanced Eyedropper, ColorPicker, Gradient Generator and other colorful goodies. You can actually get some of Photoshop’s most useful web design “features” right inside your browser. Like that color? Use CollorZilla and get the RGB code right this instant.

### 10. MeasureIt

[caption id=”attachment_154” align=”alignnone” width=”425” caption=”MeasureIt”][/caption]

Draw a ruler across any webpage to check the width, height, or alignment of page elements in pixels.

These are, in my opinion, must-have addons for every serious web designer or developer. If you think that the list is missing something, share it in the comments bellow!

Filed under tumblrize Firefox Web Design Web Development

# How To Make Mozilla Firefox Faster, More Responsive

Mozilla Firefox is my personal favorite web browser, and I use it as my default web browser on daily basis. I like it because of it’s many features and above all customizability allowing you to make your web browser your own. It is the only web browser with about:config page that allows you to control and change every bit of it’s core and make it the way you like it. This tutorial concentrates on making Firefox faster, more responsive, less hanging and smother.

First thing first, enter about:config into Firefox’s awesome bar and press enter…

[caption id=”attachment_149” align=”aligncenter” width=”568” caption=”Mozilla Firefox: about:config”][/caption]

Click “I’ll be careful, I promise!” button in order to continue. Now, you will enter Firefox’s about:config page where you can change all the options you possibly need, remember that you need to be careful doing this otherwise you could crush the browser if you don’t know what you are doing, so do this with caution. As you can see now, there are many preferences available, all these are variables including integers, booleans and strings, and these preferences have values that control how the browser works.

[message class=yellow-message ]In order to changes some preference’s value you need to double click on it and then set the value if it is the integer type, if it is a boolean just double click the value to toggle it.[/message]

In order to make Firefox faster and more responsive you need to do the following tweaks:

### Enable pipelining

Normally, browsers send a request to a web server and then wait for a response in order to continue, enabling pipelining lets your browser send multiple requests even before one response is received. This feature will speed up the total download time of webpages in most cases.

#### How to enable it?

Firstly, make sure that booleans network.http.pipelining and network.http.proxy.pipelining are set to true. Then set network.http.pipelining.maxrequests integer’s value to 8, you can put even more if you have a faster Internet connection, but setting it to 8 is enough in most cases.

### Get the most of rendering speed

When you are downloading a web page Firefox will show what has been downloaded so far every 0.12 seconds. This is too frequent and it will increase the total download time of a web page. Increasing the value that controls this solves the problem.

#### How to enable it?

You will need to create a new integer (Right click -> New - > Integer) called content.notify.interval which is the preference name, and put a value of 600000. You will also need to create a new boolean (Right click -> New - > Boolean) called content.notify.ontimer set to true.

If you don’t do anything in 0.75 seconds while the Firefox’s loading process is active, Firefox will enter so called low-frequency mode. It means that Firefox will become less responsive, but your page will load more quickly. Reducing the value of content switch threshold will improve performance, but make Firefox a little less snappier, so don’t overdo it. You can also make Firefox ignoring all user interface request while downloading a page, it will definitely make it faster, but I wouldn’t recommend that since it will make Firefox non-responsive too often.

#### How to enable it?

You will need to create a new integer (Right click -> New - > Integer) called content.switch.threshold which is the preference name, and put a value of 250000, which stands for quarter of a second. I’m using this value since I want faster loading, if you would like to make Firefox more responsive then use a greater value like 1000000+ which stands for 1+ second. In order to make Firefox ignoring all user interface requests (which I don’t recommend) create a new boolean called content.interrupt.parsing and set it’s value to false.

### Other useful tweaks

The tweaks above are the most important in making you web browser Firefox faster, if you would like to go one step ahead apply these quick changes:

• Make sure that network.http.keep-alive is set to true.
• Create new integer named nglayout.initialpaint.delay and set it’s value to 0.
• Create new integer named content.notify.backoffcount and set’s it’s value to 5.
• Create new integer named browser.cache.memory.capacity and set’s it’s value to 4096.
• Create new boolean named browser.cache.memory.enable and set it’s value to true.
• Create new boolean namedÂ browser.cache.disk_cache_ssl and set it’s value to true.
• Create new boolean namedÂ plugin.expose_full_path and set it’s value to true.
• Create new boolean named config.trim and set it’s value to true.

[message class=yellow-message ]Have in mind that if you change the value you need to restart Firefox in order for it to take effect. However, for some preferences this is not the case.[/message]

### Maintaining Firefox on daily basis

All these tweaks will make you browser run better, but there are also some things that you can do to prevent Firefox hanging or feeling slow like updating your addons and plugins regularly, clearing history every once in a while, deleting bookmarks and search engines you don’t use, disabling some features you don’t use and so on. If you have a useful tip or tweak make sure to share it in the comments bellow!

Filed under tumblrize Firefox Web Browsers

# How To Make WordPress Blog More Secure

Security of your website is very important. You should always check your server’s settings, backup your website or blog, update plugins, manage all permissions well, and all in all be very careful since some people can easily crush or hack your website in minutes and destroy your long term work and effort. This is why I’m writing this article, to show you how to make you WordPress blog more secure and all in all take the security to the next level.

#### 1. Moving your wp-config.php file

This is one of WordPress’s best features without a doubt, but not known to many people. WordPress can look for it’s wp-config.php file in a directory one level above your public_htm or a subfolder, basically that means that you can move your wp-config.php file in your home directory which will double your security level since wp-config.php is the most important file of your whole WordPress installation. If someone gets it it’s basically game over, so make sure to move it right away, the best way is to use FTP client provided in your cPanel.

#### 2. Force SSL (Encrypted connection) on your Dashboard

If you want all transfered data to be secured while you are administrating the site make sure to force SSL, but also first make sure to check if your hosting provider supports that. If you are onÂ HostGator or Wp WebHost you are good to go. It’s quite simple just add this line of code to your wp-config.php file:

#### 3. Protect yourself form Script Injections

The lines of code below will protect your blog from Script Injections when added to your .htaccess file:

RewriteEngine On
RewriteCond %{QUERY_STRING} (|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} GLOBALS(=|[|%[0-9A-Z]{0,2}) [OR]
RewriteCond %{QUERY_STRING} _REQUEST(=|[|%[0-9A-Z]{0,2})
RewriteRule ^(.*)\$ index.php [F,L]

#### 4. Protect important files

WordPress’s most important files are a key to your website’s functioning and represent a core of the whole platform, that’s why you need to protect them. As you can notice you can protect you wp-config.php file by moving it one level up, other files sadly don’t have that option, which is why you need to add the following lines of code to your .htaccess file in order to protect them:

Order allow,deny
Deny from all

Order allow,deny
Deny from all

Order allow,deny
Deny from all

Order allow,deny
Deny from all

#### 5. Remove WordPress version number info

If you have an old version of WordPress(which I strongly don’t recommend) you should at least hide the version number, if on the other hand you run the latest version do so as well! It reveals a very important information to the potential attacker who can use it to go through some know bugs in that version. In order to remove it just add this line of code to functions.php file: