Friday, June 20, 2014

Regex Regular Expressions – Find and Replace Text With Previous Matched Text That Regex Remembers with ( )

Using Regex to Replace Previous Matched Text

But even more useful is that you can use regex to help with replacing text as well. In the example above, you might want to keep the page numbers but replace the word "Page". You could use then use something like:
  • Find:
    Page (\d+)
  • Replace:
    This is page number \1
This will replace any occurrence of "Page" followed by a number with "This is page" followed by the same number:
  • Before:
    Page 418
  • After:
    This is page 418
The first point to note about this replacement is the use of the regex code (\d+) in the Find box. The \d+ code tells the search to look for numbers as above. But the use of parenthesis around the code tells the search to remember what those numbers were – to remember anything matched in the parenthesis. The other point to note is the use of the regex code \1 in the Replace box, which tells Replace to substitute the characters remembered in the Find statement for the string \1 wherever it finds it.

Using Regex to Change Formatting

As a further example of regex, this is how you might change the formatting of certain text into chapter headings.
Let’s say that you have an imported HTML file that contains lots of chapter headings, but none of them are marked using the h1 heading tag. Instead they are all marked as paragraphs like this:
<p>CHAPTER 7</p>
Assuming every paragraph like this is a chapter heading, you could use this regex:
  • Find:
  • Replace:
    <h1>Chapter \1</h1>
That’s quite a lot to digest, but if you look carefully you can see that it’s very similar to the Page number example above in that it’s remembering the digits in the chapter name and using them in the replace.
It's the Find that is the most interesting. It breaks down like this:
  • <p> – Look for a starting paragraph tag.
  • \s – Regex code to match any white space (blanks, tabs, etc.).
  • CHAPTER – Match the word CHAPTER (Regex is case-sensitive by default).
  • \s – Regex code to match any white space.
  • (\d+) – Regex code to match any number of digits in a row and remember them.
  • \s – Regex code to match any white space.
  • </p> – Look for an end paragraph tag.
You could just use a space instead of \s but \s is more flexible since it will match any number of blank spaces and tabs.
So the results of that search could be:
  • Before:
    <p>  CHAPTER    14</p>
  • After:
    <h1>Chapter 14<h1>

Installing and Configuring Subversion (SVN) on Ubuntu Linux

Step 1
Make sure that svn is installed on your web host.  Just ssh into your account and type
which svn
Step 2
Create your repository. Once svn is installed on your host, you can proceed with the repository set up.  Just ssh into your server and create a repository wherever you'd like it.  In my case I put my repository in my user directory.  I would've preferred to have it in the root directory, but because it's a shared host, I don't have write access to anything outside of my user directory.  To create the repository, issue the following command:
svnadmin create ~/myrepository
Step 3
Create your SVN user: Now that your repository is successfully set up, you'll need to create an svn user.  Simply open the svnserve.conf file in the editor of your choice:
pico ~/myrepository/conf/svnserve.conf
anon-access = none
auth-access = write
password-db = passwd
pico ~/myrepository/conf/passwd
exampleuser = examplepassword
Step 4
Create a hierarchy for your repository:
This Step is optional.  It's not needed in order to get svn to work properly, but if you're planning on keeping multiple projects under revision control, then it's a good idea to get organized before you start importing those projects.  In my case, I'll be working on upgrading one of my sites from Drupal 5 to Drupal 6 soon (yes, I know...  I've been putting that off too.), so I wanted a trunk for the Drupal 5 project and a trunk for the soon-to-be-upgraded Drupal 6 project.  You can create directories in your repository in almost the same way you create them on your file system, using mkdir.  You'll need to use svn's mkdir command though like so: NOTE: Relative paths don't seem to work here.  svn doesn't seem to like '~', so remember to start with the root directory (so it'll look like 'file:///root/rest/of/path...'.  With three forward slashes.
svn mkdir file:///path to your repository/myrepository/d5
svn mkdir file:///path to your repository/myrepository/d6
svn import /path to your project/myD5project file:///path to your repository/myrepository/d5
svn import /path to your project/myD6project file:///path to your repository/myrepository/d6
Step 5
Run the svn server as daemon:
svnserve -d
Step 6
Check out your repository onto your local machine: Back on your local machine, go to where you keep your nerd stuff.  In my case it's in ~/workspace.  Then use the svn co command to check out a copy of your project.
cd ~/workspace
svn co svn+ssh://username@hostname/path to repository/myrepository/d6
Step 7
Go get a tasty beverage and rest comfortably in the knowledge that you'll never have to scp another file again.  Well, except for maybe the occasional mysqldump file...

Install and Enable CGI-BIN on Apache Server for Ubuntu

It's time to go a little old-school and lay out how to enable the Common Gateway Interface (CGI) for your Apache server. You might be wondering why we need CGI. It's simple: CGI allows the web server to interact with external programs. These programs can range in purpose and scope, but primarily they help to add dynamic content to a website. Most often these applications are Perl programs with the extension .pl, but CGI execution is not limited to Perl.

Get started with CGI

One of the stumbling blocks most people come up against with CGI is getting their Apache server to recognize the CGI directory and to allow for the execution of commands from within that directory. I will demonstrate this process on a Ubuntu 11.04 server running the latest LAMP stack. For the most part, this LAMP stack is default, so a fresh install of LAMP will do just fine.
Let's first talk about the directories. If you look in the /var/www (the document root of Apache), you will find a sub-directory called cgi-bin. This is not where your Perl programs and other various files will be placed. Within the /usr/lib/ directory, you will find another cgi-bin directory; it is the repository for your executables. If that directory does not exist, create it with the command: 

$ sudo mkdir /usr/lib/cgi-bin.

Now, make sure the permissions look like this:
drwxr-xr-x  3 root root         4096 2011-11-23 09:08 cgi-bin
Issue the command ls -l /usr/lib | less and scroll to check your directory's permissions. If it's not as you see above, issue the following commands:
$ sudo chmod 755 /usr/lib/cgi-bin

$ sudo chown root.root /usr/lib/cgi-bin

Now that your directory is ready, it's time to configure Apache. Remember, this is Ubuntu, so you will have to make a few simple modifications if you're using a different distribution with a different take on the Apache web server.

Configure Apache

A directive must be created so Apache knows about CGI -- where its directories are located and what it can do. In some Apache configurations, this is done within the httpd.conf file. Because this is Ubuntu, we are going to add the directive to /etc/apache2/apache2.conf
$ sudo nano /etc/apache2/apache2.conf
Open that file with your favorite text editor and, before you add anything, search for this section:
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
If the above section does not exist, add it in the <Virtualhost *:80> section just above the line:
ErrorLog ${APACHE_LOG_DIR}/error.log
Save that file and be ready to restart Apache. To restart the server, issue the command:
$ sudo service apache2 restart

Test it out

Now it's time to test this baby out. Let's create a file (call it, and the file's contents should be:
#!/usr/bin/perl -w
print "Content-type: text/html\r\n\r\n";

print "Hello there!<br />\nJust testing .<br />\n";

for ($i=0; $i<10; $i++)


    print $i."<br />";

Save that file in /usr/lib/cgi-bin and give it 755 permissions. Now open that file in your web browser (point the browser to http://IP_OF_SERVER/cgi-bin/ where IP_OF_SERVER is the address of the server), and you should see the following:
Hello there!
Just testing .

If you see that, CGI is working. You can dump your programs into the /usr/lib/cgi-bin/ directory and start using them It's simple and effective.

Thursday, June 19, 2014

Linux: Howto Make a Directory Command

How do I make directory under Linux operating systems using the command prompt or bash shell?

You need to use the mkdir command to create new folders or directories under Linux operating systems. A directory (also known as folder in MS-Windows/OS X) is nothing but a container for other directories and files.

mkdir command Syntax

The mkdir command has the following syntax:
mkdir dirname
mkdir dirname1 dirname2
mkdir [option] dieNameHere
mkdir -p dir1/dir2/dir3


Open a terminal and use the mkdir command to create empty directories. The following command would create a directory called foo:
$ mkdir foo
To list directories, enter:
$ ls
$ ls -l

The following command would create two directories within the current directory:
$ mkdir tom jerry
$ ls -l

The -p option allows you to create parent directories as needed (if parent do not already exits). For example, you can create the following directory structure:
$ mkdir -p ~/public_html/images/trip

Sample mkdir demo

Animated gif 01: mkdir in action under Linux / Unix like operating systems
Animated gif 01: mkdir in action under Linux / Unix like operating systems

How To Use chmod and chown Command

How do I use chmod and chown command under Linux / Unix operating systems?
Use the chown command to change file owner and group information. Use the chmod command to change file access permissions such as read, write, and access.

chown command

chown command changes the user and/or group ownership of for given file. The syntax is:
chown owner-user file
chown owner-user:owner-group file
chown owner-user:owner-group directory
chown options owner-user:owner-group file


First, list permissions for demo.txt, enter:
# ls -l demo.txt
Sample outputs:
-rw-r--r-- 1 root root 0 Aug 31 05:48 demo.txt
In this example change file ownership to vivek user and list the permissions, run:
# chown vivek demo.txt
# ls -l demo.txt

Sample outputs:
-rw-r--r-- 1 vivek root 0 Aug 31 05:48 demo.txt
In this next example, the owner is set to vivek followed by a colon and a group onwership is also set to vivek group, run:
# chown vivek:vivek demo.txt
# ls -l demo.txt

Sample outputs:
-rw-r--r-- 1 vivek vivek 0 Aug 31 05:48 demo.txt
In this example, change only the group of file. To do so, the colon and following GROUP-name ftp are given, but the owner is omitted, only the group of the files is changed:
# chown :ftp demo.txt
# ls -l demo.txt

Sample outputs:
-rw-r--r-- 1 vivek ftp 0 Aug 31 05:48 demo.txt
Please note that if only a colon is given, or if NEW-OWNER is empty, neither the owner nor the group is changed:
# chown : demo.txt
In this example, change the owner of /foo to "root", execute:
# chown root /foo
Likewise, but also change its group to "httpd", enter:
# chown root:httpd /foo
Change the owner of /foo and subfiles to "root", run:
# chown -R root /u
  • -R - Recursively change ownership of directories and their contents.

chmod command

The information about the chmod command is covered in our previous tutorial - "how to use change user rights using chomod command".

How to Reinstall apache2 properly in linux

If you have issues with apache2 and you want to reinstall it but you are getting errors,then here it isthe solution for you.

For example, me i had an issue with apache, when i tried to start it i got this error message  :

root@pirat9-desktop:/etc/apache2# /etc/init.d/apache2   start
.: 45: Can't open /etc/apache2/envvars
Now i want to reinstall apache, but first i need to remove it completely  (If you currently have it removed improperly, reinstall it by “sudo apt-get install apache2″ before to use the command bellow). To do that i will use this command :
 sudo apt-get remove --purge apache2 apache2-utils
This command will completely remove all apache2 configuration files and directories.
- Reinstall again apache using the normal command
sudo apt-get install apache2

Now your config files and directories in /etc/apache2 all be back and at their defaults as well as the “apache2-utils previously removed.

root@pirat9-desktop:/etc/apache2# /etc/init.d/apache2   start
 * Starting web server apache2                                  using for ServerName
httpd (pid 7235) already running   [ OK ]

How to take a screen shot on the Samsung Galaxy S III

Capturing the screen is a great way to save something for posterity and show it off to your friends.

You just got your brand new Galaxy S III and you want to capture some of the cool stuff you can do with a screen shot, but it doesn’t work the same way as other Android phones, does it?
If you came to the Galaxy S III from a prior Android phone, you are most likely familiar with the “Android way” of capturing a screen; you hold down the Power button and the Volume down button simultaneously and the screenshot is captured and saved.

Saving a screenshot on the Galaxy S III: Method #1

There are two ways to capture a screenshot on the Galaxy S III; neither of them are the same as previous Android devices. For method #1, think iPhone – that is the button combination that will work on the Galaxy S III.
  1. Find the screen that you want to  capture
  2. Press and holdboth the Power button and the Home button together
  3. Screenshot will be captured and saved to the Gallery app

gallery albums  screen shot

Saving a screenshot on the Galaxy S III method #2

Samsung has built a bunch of innovative “motions” into the Galaxy S III – we will cover them all in time here on Android Central
One of the innovative motions is the ability to use your palm to swipe over the screen to capture a screen shot. This just needs to be enabled in your Settings app.
NOTE: This might already be enable on your Galaxy S III, if not, follow the steps below:
  1. Pull down the Notifications tray and touch the Settings icon or simply go to the Settings app on the Home screen
  2. Scroll down to the Motion tab and tap it
  3. Make sure there is a check mark in the top Motion activation box
  4. Scroll down to Hand motions
  5. Make sure there is a check mark in the Palm swipe to capture box
settings app  hand motions enabled
That’s all there is to it.   From any screen, use the side of your palm and just swipe across the screen.  It doesn’t matter if you go from right to left or left to right – either way will work just fine.
Go to your Gallery app and look in the Screenshots album and you will find the screenshots you just captured.
From there, you can email them, post them to Facebook, send via messaging, upload to Dropbox – whatever works best for you

Wednesday, June 11, 2014

Find Lost Installed Adobe Flash Serial

For a quick and dirty method, try running the Belarc Advisor

Adding Blogger Search Bar Form To Blogspot

Add a search engine in the sidebar of your blogger blog. This searches all the posts on your blog, and displays them by latest posts first. Inside the search bar you will find the text "Search this Site", this can easily be changed to any text you desire. Such as "Search my Site", "Search", "Type and Hit Enter", etc. Just simply replace the code. You can also change the text "Go" on the button to something like "Search", "Find", etc.

Thursday, June 5, 2014

Resetting Your Wordpress Password

To Change Your Password

To change your password in current versions:
  1. In the Admin Panel menu, go to USERS
  2. Click on your username in the list to edit
  3. In the Edit User screen, scroll down to the New Password section and type in a new password in the two boxes provided. The strength box will show how good (strong) your password is.
  4. Click the UPDATE PROFILE button
Your new password takes effect immediately.

Through the automatic emailer

If you know your username and the email account in your profile, you can use the "lost password" feature of WordPress.
  • Go to your WordPress Login page (something like
  • Click on lost password
  • You will be taken to a page to put in some details. Enter your user name and the email address on file for that account.
  • Wait happily as your new password is emailed to you.
  • Once you get your new password, login and change it to something you can remember on your profile page.

Through MySQL Command Line

  1. Get an MD5 hash of your password.
    • Visit md5 Hash Generator, or...
    • Create a key with Python. or...
    • On Unix/Linux:
      1. Create file wp.txt with the new password in it (and *nothing* else)
      2. md5sum wp.txt
      3. rm wp.txt
    • On Mac OS X:
      1. Create file wp.txt with the new password in it (and *nothing* else), then enter either of the lines below
      2. md5 -q ./wp.txt; rm ./wp.txt (If you want the MD5 hash printed out)
      3. md5 -q ./wp.txt | pbcopy; rm ./wp.txt (If you want the MD5 hash copied to the clipboard)
  2. "mysql -u root -p" (log in to MySQL)
  3. enter your mysql password
  4. "use (name-of-database)" (select WordPress database)
  5. "show tables;" (you're looking for a table name with "users" at the end)
  6. "SELECT ID, user_login, user_pass FROM (name-of-table-you-found)" (this gives you an idea of what's going on inside)
  7. "UPDATE (name-of-table-you-found) SET user_pass="(MD5-string-you-made)" WHERE ID = (id#-of-account-you-are-reseting-password-for)" (actually changes the password)
  8. "SELECT ID, user_login, user_pass FROM (name-of-table-you-found)" (confirm that it was changed)
  9. (type Control-D, to exit mysql client)
Note if you have a recent version of MySQL (version 5.x?) you can have MySQL compute the MD5 hash for you.
  1. Skip step 1. above.
  2. Do the following for step 7. instead.
    • "UPDATE (name-of-table-you-found) SET user_pass = MD5('"(new-password)"') WHERE ID = (id#-of-account-you-are-reseting-password-for)" (actually changes the password)
Note that even if the passwords are salted, meaning they look like $P$BLDJMdyBwegaCLE0GeDiGtC/mqXLzB0, you can still replace the password with an MD5 hash, and WordPress will let you log in.

Through phpMyAdmin

This article is for those who have phpMyAdmin access to their database. Note: use phpMyAdmin at your own risk. If you doubt your ability to use it, seek further advice. WordPress is not responsible for loss of data.
Begin by logging into phpMyAdmin and click databases.
Image #2
  • A list of databases will appear. Click your WordPress database.
Image #3
  • All the tables in your database will appear. If not, click Structure.
  • Look for wp_users.
  • Click on the icon for browse.
  • Locate your Username under user_login
  • Click edit (may look like a pencil icon in some versions of phpMyAdmin)
Image #4
  • Your user_id will be shown, click on Edit
  • Next to the user_pass is a long list of numbers and letters.
  • Select and delete these and type in your new password.
  • Type in the password you want to use. Just type it in normally, but remember, it is case-sensitive.
  • In this example, the new password will be 'rabbitseatcarrots'
  • Once you have done that, click the dropdown menu indicated, and select MD5 from the menu.
Image #5
  • Check that your password is actually correct, and that MD5 is in the box.
  • Click the 'Go' button to the bottom right.
  • Test the new password on the login screen. If it doesn't work, check that you've followed these instructions exactly.

Other Tutorials using phpMyAdmin

Through FTP

There is also an easy way to reset your password via FTP, if you're using the admin user.
1. Login to your site via FTP and download your active theme's functions.php file.
2. Edit the file and add this code to it, right at the beginning, after the first <?php:
wp_set_password( 'password', 1 );
Put in your own new password for the main admin user. The "1" is the user ID number in the wp_users table.
3. Upload the modified file back to your site.
4. After you then are able to login, make sure to go back and remove that code. It will reset your password on every page load until you do.

Through WP CLI

WP CLI is a command line tool for managing your WordPress installation.
1. Move into the /wordpress directory and type
$ wp user list
to see all users. Find the ID of the user you'd like to update.
2. Then, update the user
$ wp user update 1 --user_pass=$UP3RstrongP4$$w0rd
replacing "1" with the id of the user you want to update.

Using the Emergency Password Reset Script

If the other solutions listed above won't work, then try the Emergency Password Reset Script. It is not a Plugin. It is a PHP script.
  1. Requires you know the administrator username.
  2. It updates the administrator password and sends an email to the administrator's email address.
  3. If you don't receive the email, the password is still changed.
  4. You do not need to be logged in to use it. If you could login, you wouldn't need the script.
  5. Place this in the root of your WordPress installation. Do not upload this to your WordPress Plugins directory.
  6. Delete the script when you are done for security reasons.
Directions for use 
  1. Copy the emergency script from Emergency Password Script and put into a file called emergency.php in the root of your WordPress installation (the same directory that contains wp-config.php).
  2. In your browser, open
  3. As instructed, enter the administrator username (usually admin) and the new password, then click Update Options. A message is displayed noting the changed password. An email is sent to the blog administrator with the changed password information.
  4. Delete emergency.php from your server when you are done. Do not leave it on your server as someone else could use it to change your password.

Changing your password in older versions

To change your password in WordPress v1.2:
  1. In the Admin Panel, go to PROFILE
  2. Scroll down to the bottom and type in the new password in the two boxes provided
  3. Click the UPDATE PROFILE button
Your new password takes effect immediately.
To change your password in WordPress v1.5:
  1. In the Admin Panel, go to USERS
  2. From the "Your Profile" tab, scroll to the bottom and type in the new password in the two boxes provided.
  3. Click the UPDATE PROFILE button
Your new password takes effect immediately.
To change your password in WordPress v2.0:
  1. In the Admin Panel, go to USERS (or Profile)
  2. From the "Your Profile" tab, scroll down to the Update Your Password section and type in a new password in the two boxes provided.
  3. Click the UPDATE PROFILE button

Your new password takes effect immediately.