How to Make a Bash Script in Ubuntu

Written by admin on March 15th, 2011. Posted in Uncategorized

Write your script in the Text Editor of Your Choice.  The first line will be

#!/bin/sh

Then type your other commands.

When you’re done, save. then you’d need to make the script executable with

chmod +x SCRIPTNAME.

you’d execute it with

./SCRIPTNAME

If you have ever done a lot of repetitive tasks on a Ubuntu Linux machine, Im sure you’ve wondered if there is a better way of doing things. For example, say I need to run a dozen or more command line commands. I could enter them in one by one or I can put them all in a single file and run it as a script.

When you run it all as a script, you save a lot of time. Today, I am going to show you how to make the most simple Ubuntu script you can find. It doesn’t use any variables, it just helps you run several commands at once. for example, we are going to create a simple script to

First, just you need to create the script file. For this just open a terminal and type:

gedit samplescript.sh

This will open gedit with a blank file named samplescript.sh. In the file, type the following:

#!/bin/sh 

echo 'welcome'

firefox

Save this file. The first line identifies it as a shell script, the second line causes the script to print welcome on your screen when it’s run. After the echo, you can put in any command line you want to on the next line and it will run. For this example, we put the command firefox and when you run the file, it will open Firefox.

Next, run this command to make the file executable:

chmod 777 samplescript.sh 

Now, to run the script, type this:

./samplescript.sh

Popular Mistakes Made by Joomla Extension Developers

Written by admin on March 14th, 2011. Posted in Uncategorized

Here’s the presentation of my colleague at Dioscuri.com at Joomla and Beyond 2010 Conference about popular mistakes made by Joomla extension developers.

Remove NULL values from PHP arrays with 1 line

Written by admin on March 14th, 2011. Posted in Uncategorized

I had an array with something like the following:

<?php
$array_with_nulls = array ( [0] => [1] => test [2] => fun ).
?>

But I don’t want [0], the empty value in the array.

Remove NULL values only

<?php
$new_array_without_nulls = array_filter($array_with_nulls, 'strlen');
?>

Remove any FALSE values

This includes NULL values, EMPTY arrays, etc.

<?php
$new_array_without_nulls = array_filter($array_with_nulls);
?>

How to Check if an Image URL Exist with PHP

Written by admin on March 14th, 2011. Posted in Uncategorized

Quick and easy PHP script to determine if image exists. The image you are checking for can be hosted on your site or externally.

This script is useful to display an alternate image if the original one does not exist.

Note: This script uses GD, so you’ll need to have GD installed on your server for it to work.
<?php
if (@GetImageSize("http://www.gerald.comuf.com/wp-content/uploads/2011/03/toolbar_feed.png")) {
echo "image exists";
} else {
echo "image does not exist";
}
?>

Use this script instead if you don’t have GD installed:

<?php
if (@fclose(@fopen("http://www.gerald.comuf.com/wp-content/uploads/2011/03/toolbar_feed.png", "r"))) {
echo "image exists";
} else {
echo "image does not exist";
?>

How to Install Tripwire on Ubuntu

Written by admin on March 14th, 2011. Posted in Uncategorized

If you’re interested in Tripwire then let me be the first to welcome you to the world of paranoid system admins. Tripwire can be a vital tool in detecting a compromise of your system.

Tripwire generates a database of the most common files and directories on your system. Once it is generated, you can then check the current state of your system against the original database and get a report of all the files that have been modified, deleted or added.

This comes in handy if you allow other people access to your machine and even if you don’t, if someone else does get access, you’ll know if they tried to modify files such as /bin/login etc.
So lets install Tripwire. First you need to download it from

http://sourceforge.net/project/showfiles.php?group_id=3130&release_id=26024.

At the time of this update the current version is 2.3.1-2.

Once you’ve downloaded it move the tarball to /usr/local/src (I like to store all my source code there) and untar it by running the following command:

tar -zxvf tripwire-2.3.1-2.tar.gz

Change into the newly created directory and edit the install.cfg with your favorite text editor (nano, pico, joe vi etc). script. You’ll want to edit the following:

# The root of the TSS directory tree.
	TWROOT="/usr/TSS"

Change this to

TWROOT="/usr/local/src/tripwire-2.3.1-2" 

# This sets the default text editor for Tripwire.

TWEDITOR="/bin/vi"

You can change this to whatever editor you prefer.

Once you have those changed, save the file and exit. Then run the ./install.sh script. It will list the OSes that Tripwire supports and will ask you if you want to continue with installation. Next up is the License Agreement. Read it and if you accept, type accept.

It will then list all the settings and ask you if you would like to continue, answer yes. Then it installs the files and prompts you for a passphrase to password protect the database. Choose it wisely. It will now generate your keyfile and then prompt you for a local passphrase and a site passphrase.

Once that is done, tripwire will be installed and you’re ready to customize the format of the database and finally create it. To customize the database, you will need to edit the /usr/local/src/tripwire-2.3.1-2/policy/twpol.txt file. Make sure you back it upbefore you start changing things in it.

What I would recommend doing is first generating the database using the default policy file. Once the database is generated, use tripwire to check against it and you will get a report of what is missing on your system, for example it checks for /lib/modules/preferred and if you don’t have that file it will let you know in the report. If you don’t remove useless items from the policy file, you’re report will be long and full of garbage that you don’t need to look at everyday and you will probably miss the things you should be looking for.

So to generate the database, run:

/usr/local/src/tripwire-2.3.1-2/bin/tripwire --init 

It will ask you for your passphrase and once you enter it, it will start to generate the database. This will vary in time depending on how big your installation is, how fast your CPU is etc. Once the database is generated, you will want to check it to find out what you can remove from the policy file. To check the database and have it output to a file, run:

/usr/local/src/tripwire-2.3.1-2/bin/tripwire --check > /tmp/report.txt 

It will then proceed to check your filesystem against the database and will create a file called report.txt in /tmp which will contain information on what Tripwire discovered.

Open up this file and look for anything that it said it couldn’t find. Log into another terminal and open up the twpol.txt policy file. Compare the two and remove anything not found one by one. Once you are done editing, you have to recreate the policy file, to do this run:

/usr/local/src/tripwire-2.3.1-2/bin/twadmin --create-polfile ../policy/twpol.txt 

It will ask you for your passphrase, once you enter it, tripwire should create a new policy file. You can then go ahead and update and then check your filesystem once more to see if you got everything. If you install alot of things, you will probably want to update the database on a regular basis.

You can also set up a cronjob to check the filesystem every night or whenever you feel like it and it will email you the report. Here is the line in my /etc/crontab file for Tripwire:

03 2 * * * /usr/local/src/tripwire-2.3.1-2/bin/tripwire --check | /usr/bin/mail root -s "Tripwire Check" 2>&1

All in all Tripwire is a handy utility to have and I feel some sort of relief reading the report every morning.

8 Ways to Make Firefox Ridiculously Fast

Written by admin on March 14th, 2011. Posted in Uncategorized

Firefox has been outperforming IE in every department for years, and version 3 is speedier than ever.

But tweak the right settings and you could make it faster still, more than doubling your speed in some situations, all for about five minutes work and for the cost of precisely nothing at all. Here’s what you need to do.

1. Enable pipelining

Browsers are normally very polite, sending a request to a server then waiting for a response before continuing. Pipelining is a more aggressive technique that lets them send multiple requests before any responses are received, often reducing page download times.

To enable it, type about:config in the address bar, double-click network.http.pipelining and network.http.proxy.pipelining so their values are set to true, then double-click network.http.pipelining.maxrequests and set this to 8.

Keep in mind that some servers don’t support pipelining, though, and if you regularly visit a lot of these then the tweak can actually reduce performance. Set network.http.pipelining and network.http.proxy.pipelining to false again if you have any problems.

2. Render quickly

Large, complex web pages can take a while to download. Firefox doesn’t want to keep you waiting, so by default will display what it’s received so far every 0.12 seconds (the “content notify interval”). While this helps the browser feel snappy, frequent redraws increase the total page load time, so a longer content notify interval will improve performance.

Type about:config and press [Enter], then right-click (Apple users ctrl-click) somewhere in the window and select New > Integer. Type content.notify.interval as your preference name, click OK, enter 500000 (that’s five hundred thousand, not fifty thousand) and click OK again.

Right-click again in the window and select New > Boolean. This time create a value called content.notify.ontimer and set it to True to finish the job.

3. Faster loading

If you haven’t moved your mouse or touched the keyboard for 0.75 seconds (the content switch threshold) then Firefox enters a low frequency interrupt mode, which means its interface becomes less responsive but your page loads more quickly. Reducing the content switch threshold can improve performance, then, and it only takes a moment.

Type about:config and press [Enter], right-click in the window and select New > Integer. Type content.switch.threshold, click OK, enter 250000 (a quarter of a second) and click OK to finish.

4. No interruptions

You can take the last step even further by telling Firefox to ignore user interface events altogether until the current page has been downloaded. This is a little drastic as Firefox could remain unresponsive for quite some time, but try this and see how it works for you.

Type about:config, press [Enter], right-click in the window and select New > Boolean. Type content.interrupt.parsing, click OK, set the value to False and click OK.

5. Block Flash

Intrusive Flash animations are everywhere, popping up over the content you actually want to read and slowing down your browsing. Fortunately there’s a very easy solution. Install the Flashblock extension (flashblock.mozdev.org) and it’ll block all Flash applets from loading, so web pages will display much more quickly. And if you discover some Flash content that isn’t entirely useless, just click its placeholder to download and view the applet as normal.

6. Increase the cache size

As you browse the web so Firefox stores site images and scripts in a local memory cache, where they can be speedily retrieved if you revisit the same page. If you have plenty of RAM (2 GB of more), leave Firefox running all the time and regularly return to pages then you can improve performance by increasing this cache size. Type about:config and press [Enter], then right-click anywhere in the window and select New > Integer. Type browser.cache.memory.capacity, click OK, enter 65536 and click OK, then restart your browser to get the new, larger cache.

7. Enable TraceMonkey

TraceMonkey is a new Firefox feature that converts slow javascript into super-speedy x86 code, and so lets it run some functions anything up to 20 times faster than the current version. It’s still buggy so isn’t available in the regular Firefox download yet, but if you’re willing to risk the odd crash or two then there’s an easy way to try it out.

Install the latest nightly build (ftp://ftp.mozilla.org/pub/firefox/nightly/latest-trunk/), launch it, type about:config in the address bar and press Enter. Type JIT in the filter box, then double-click javascript.options.jit.chrome and javascript.options.jit.content to change their values to true, and that’s it – you’re running the fastest Firefox javascript engine ever.

8. Compress Data

If you’ve a slow internet connection then it may feel like you’ll never get Firefox to perform properly, but that’s not necessarily true. Install toonel.net (toonel.net) and this clever Java applet will re-route your web traffic through its own server, compressing it at the same time, so there’s much less to download. And it can even compress JPEGs by allowing you to reduce their quality. This all helps to cut your data transfer, useful if you’re on a limited 1 GB-per-month account, and can at best double your browsing performance.

How to Make Super Hidden Files or Folders

Written by admin on March 14th, 2011. Posted in Uncategorized

1. Open a command prompt

Click Start button-> select Run -> type “cmd” ( Windows XP )

Click Start button-> type “cmd” in the seach box ( Windows 7 )

2. Press Enter
3. Type “cd path_of_your_file” to go to place of your file
4. Type “dir” to view content of folder
5. Type “attrib +s +h file’s_name” then press Enter
6. View again with “dir” command

50 Tips To A User Friendly Website

Written by admin on March 13th, 2011. Posted in Uncategorized

Here is a list of 50 things that WE should keep in mind on every website that WE build to will improve our visitors experience on our website.

1. Clicking on the logo should take you to the home page;
2. Your logo/site title should be positioned in the top left of the page;
3. Duplicate your main navigational links in the page footer with links to additional, but less prominent pages;
4. Keep your navigation positioning consistent from page to page;
5. Don’t open links in a new tab/window, except PDF’s and embedded documents;
6. Highlight your current location in your navigation bar;
7. Use reasonable sized fonts (12px or larger);
8. Make sure font sizes are flexible (Use em’s or %, not px);
9. Sans-serif fonts are easier to read at small sizes;
10. Serif fonts are easier to read at large sizes;
11. Center your layout on the screen;
12. Use a page width appropriate for your audience (Older people use lower resolutions, tech saavy people use higher resolutions);
13. Use whitespace to logically group related items on the page;
14. Use font sizes, colors and styles to prioritize content;
15. Use 1.4 or 1.5em line height;
16. Use line lengths of 45 – 60 characters, the same as a paperback book;
17. Link to related content within the context of your page content;
18. Make sure your links change color/style when visited;
19. Always underline links, except some navigational cases;
20. Do not make important parts of the website look like an advertisement;
21. Use pull quotes to highlight important content in a lengthy article;
22. Text should be concise and scannable;
23. Use dark gray text instead of black text on a white background;
24. Break long pages into multiple pages;
25. Do not use all uppercase words, word shape helps word recognition;
26. Divide text into sections and use sub headlines to make content more easily scanned;
27. Keep a consistent layout, colors and typography throughout the whole site;
28. Print friendly automatically with print stylesheets;
29. Use buttons to submit forms (Some images which look like buttons are ok);
30. Don’t disguise or over-style inputs;
31. Don’t redesign standard UI elements, like scrollbars (this means you, flash people!);
32. Use breadcrumb navigation for hierarchical content;
33. Search results page should reiterate the phrase you searched for;
34. Do call your homepage “home” – not “welcome,” “front page,” “your company name” or anything else;
35. Use short and easy to read URL’s;
36. Give links to other content on your site related to their current page;
37. Optimize images for fast downloading;
38. Publish new content regularly, don’t “set it and forget it;”
39. Test in all browsers and OS’s, and different versions – IE, Firefox, Safari, Opera and Chrome;
40. Listen to your users and let them dictate changes (user centered design);
41. Avoid using jargon in page copy unless absolutely necessary;
42. Keep forms short, only ask for what you absolutely need;
43. Encourage conversation around your content. Comments, forums, etc…;
44. Include a text only sitemap;
45. Use the title attribute on links to add more context;
46. Never use “click here” as the text on a link;
47. Write in a inverted pyramid style;
48. Create friendly 404 pages which help people find content;
49. Create incentive to come back later;
50. Connect information via hyperlinks, dont force navigational channels;

Adapted from: http://www.designinginteractive.com/design/50-tips-to-a-user-friendly-website/

How to Speed Up Internet by 20% in Windows

Written by admin on March 12th, 2011. Posted in Uncategorized

Microsoft reserves 20% of your available bandwidth for their own purposes like Windows Updates and interrogating your PC etc..

You can get the 20% to speed up internet by:

1. Click Start then Run and type “gpedit.msc” without quotes.This opens the group policy editor.
2. Go to Local Computer Policy > Computer Configuration > Administrative Templates > Network then QOS Packet Scheduler  > Limit Reservable Bandwidth.
3. Double click on Limit Reservable bandwidth

It will say it is not configured but the truth is under the ‘Explain’ tab i.e.”By default, the Packet Scheduler limits the system to 20 percent of the bandwidth of a connection, but you can use this setting to override the default.”.
3. Enable Reservable bandwidth

So the trick is to ENABLE reservable bandwidth, then set it to ZERO. This will allow the system to reserve nothing, rather than the default 20%.It works on Win 2000 as well.

How to Speed Up Folder Browsing in Windows XP

Written by admin on March 12th, 2011. Posted in Uncategorized

You may have noticed that every time you open my computer to browse folders that there is a slight delay. This is because Windows XP automatically searches for network files and printers every time you open Windows Explorer. To fix this and to increase browsing significantly:

1. Open My Computer
2. Click on Tools menu
3. Click on Folder Options
4. Click on the View tab.
5. Uncheck the Automatically search for network folders and printers check box
6. Click Apply
7. Click Ok
8. Reboot your computer