Archive for the ‘System Administration’ Category

Code formating script

No Comments »
#!/usr/bin/perl -w
 
my $ifile = shift;
my $blank = 0;
my $indent = 2;
open(IFILE, "$ifile") or die "Cannot open $ifile\n";
while(my $line = ) {
  if($line =~ /^\s*else/i
     or $line =~ /^\s*end/i
    ) {  #reduce indent before xxx
    $blank = $blank - 2;
  }
  if($blank > 0) {
    print " " x $blank;  #print several blanks
    print "$line";
  } else {
    print "$line";
    $blank = 0;
  }
  if($line =~ /^\s*if/i
     or $line =~ /^\s*else/i
     or $line =~ /^\s*loop/i
    ) {  #increase indent after xxx
    $blank = $blank + 2;
  }
}

MySQL replication – How-to

No Comments »

MySQL replication is quite straight forward. Here are the setup steps: Read the rest of this entry »


Growl Notifications for MSOutlook (Any Version)

8 Comments »

Growl is very good tool for local and remote notifications, we can compare it with libnotify in Linux plus growl is already available on multiple platforms, So now I want to use it with Microsoft Outlook to notify me when new email arrives, but unfortunately there is no Add-on available for growl after Outlook 2007 onwards, so I did the work for myself, basically it is too simple to write a procedure in VBA for Office (Macros) but the only drawback is that you need to allow macros (security involved) OR sign it with Digital Certificate (money involved) Read the rest of this entry »


Find and Replace Text in MySQL Database using SQL REPLACE

No Comments »

MySQL database has a handy and simple string function REPLACE() that allows table data with the matching string (from_string) to be replaced by new string (to_string). This is useful if there is need to search and replace a text string which affects many records or rows, such as change of company name, postcode, URL or spelling mistake.

The syntax of REPLACE is REPLACE(text_string, from_string, to_string)

MySQL reference describes REPLACE as function that returns the string text_string with all occurrences of the string from_string replaced by the string to_string, where matching is case-sensitive when searching for from_string. text_string can be retrieved from the a field in the database table too. Most SQL command can be REPLACE() function, especially SELECT and UPDATE manipulation statement.

For example:

update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'find this string', 'replace found string with this string');

update jos_docman set dmurl = replace(dmurl, 'click.net', 'm4u.com.pk')

The above statement will replace all instances of ‘click.net’ to ‘m4u.com.pk’ in the field of dmurl of jos_docman table.

Enjoy!


How to enable WebSocket in Firefox

No Comments »

WebSockets
WebSockets is an advanced technology that makes it possible to open an interactive communication session between the user’s browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.

As you might know, WebSocket is disabled in Firefox due to security issues (This was fixed in Firefox 6+ by implementing a newer version of the protocol that corrects the problem.) while it’s being supported in Chrome and Safari. However, you can still enable WebSocket in Firefox by opening

about:config and setting the network.websocket.enabled preferences to true

That’s it, Enjoy

Refrence: https://developer.mozilla.org/en-US/docs/WebSockets


Secure browsing, How to use SSH (encrypted tunnel) for browsing

2 Comments »

Using ssh as a proxy or encrypted tunnel to browse the web can sometimes be necessary:

  1. When you’re at some public place but need to login securely to your work place.
  2. When local access restrictions make life really difficult.

I use SSH for the security reasons. I want to make sure that my security and login information will remain secure:

ssh -D 12345 myuser@remote_ssh_server

Replace myuser with your user account and remote_ssh_server with the IP or Hostname of your server.

The above command will do all, but if you want to add more options, you can add other options like:-

-D 12345: This does the dynamic stuff and makes it behave as a SOCKS server.
-f : This will fork the process into the background after you type your password (for Linux only, on windows skip that).
-C : Turns on compression.
-q : Quiet mode. Since this is just a tunnel we can make it quiet (for Linux only, on windows skip that).
-N : Tells it no commands will be sent. (the -f will complain if we don’t specify this)

Next, set up your browser to use the proxy server. Most browsers include proxy support. For Firefox, go to Edit→Preferences→Advanced→Network→Settings, and specify that you want to use a Manual Proxy, localhost, port 12345 and SOCKS v5 (although OpenSSH supports both versions 4 and 5).

HTTP Proxy (The first input). Must be left blank and add this config to SOCKS only.

Now your browser is using a secure tunnel to your remote SSH server, Enjoy