Never been to CodeSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

vim backreference on search and replace

// description of your code here

Use \(\) to denote an atom.
Use \1 to specify the first atom.

<this is your search and replacement terms>

:%s'\(<stuff_to_find>\)'\1<new_stuff>'gc

symbolically link entire directory contents

// description of your code here

ln -s /full/dir/path/to_files /full/dir/path/destination

Run script just before linux reboot (runlevel 6 / rc6.d)

update-rc.d is the program (script) which creates the necessary symbolic links to the /etc/rcX.d directories.

Here we are running the script found at /etc/init.d/updatedb_start, within runlevel 6, which is reboot.

Running this will create a symbolic link to the actual script file which lives within /etc/init.d (as it always should).

So, within /etc/rc6.d/ we'll see a symbolic link to our script.

The period at the end of the command is required. Tells update-rc.d that we're finished with the command (no further runlevels to edit).

We're using "stop" instead of "start" because we want to run the script during the killing off scripts part of the rc6.d scripts.
This causes the script to be run with a "stop" parameter, for example: updatedb_start stop
We don't actually use the stop parameter in this case, it's just ignored.

update-rc.d updatedb_start stop 18 6 .

log to syslog

how to log something to syslog

logger This is my message to syslog

Test php mysql pdo_mysql

// description of your code here

<?php $link = mysql_connect('localhost','mydbuser','mydbpassword');
if (!$link) {
        die('Could not connect to MySQL: ' . mysql_error());
} echo 'mySql Connection OK';
mysql_close($link);

$dbh = new PDO('mysql:host=localhost;dbname=test','mydbuser','mydbpassword');
if ($dbh) {
        echo 'mysql_pdo CONNECTION OK';
}
else {echo 'mysql_pdo ERROR';}
?>

activate root in ubuntu after install

After this you can run su.

sudo passwd root

running scheduled programs in linux

use crontab

Edit the current configuration for crontab with:
crontab -e


Normally we'd created bash script files located in /usr/local/bin and have them specified for execution within our crontab configuration.

postfix - flush queues / logs

Using the program: postsuper

There are three queues (active, deferred, incoming) and four log directories (bounce, defer, trace, flush).

To remove all mails in the deferred queue:

postsuper -d ALL deferred


Note that all of the queues and log dirs are located in:
/var/spool/postfix

reboot or shutdown linux server

how to shutdown a linux box with -f skip fsck file system check, -r reboot.

You must always specify a time or the word: now. Give time in minutes by using: +m

shutdown -rf +1 "Scheduled test of system reboot"


Will reboot the server in one minute, skipping fsck on startup.

stop Apple Tiger dashboard advisory daemon

Useless daemon tries to contact Apple to make sure widgets installed in Dashboard are the right version (the fuck?)

udo mv /System/Library/LaunchDaemons/com.apple.dashboard.advisory.fetch.plist /System/Library/