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!)

About this user

http://installingcats.com

symbolically link entire directory contents

// description of your code here

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

Edit rc.d scripts (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 .


Removing script
update-rc.d -f tcpyspy remove

log to syslog

how to log something to syslog

logger This is my message to syslog

vim search and replace escape forward slash

Don't escape it, just use a different delimiter, such as single quote

:%s'replacethis'withthis'gc

git tutorial

// description of your code here

git init
git add .
git commit -a
git log (show previous commits and their unique ids)
git status (show whats changed, and which files are new and untracked)
git checkout [branch] (switch to [branch])
git checkout -b [new_branch_name] (creates branch and switches to it)
git checkout -b [new_branch_name] [commit_id] (ditto, from particular commit)
git pull . [branch] (merges [branch] into current branch)
git reset --hard HEAD^ (undo last merge)


Example of daily use.

Create new rails project
rails rproj
cd rproj
touch .gitignore
touch log/.gitignore
touch tmp/.gitignore
vim .gitignore


Add directories that you don't want git to track into .gitignore...
log/*.log
tmp/**/*
Capfile
doc/api
doc/app


Now start tracking with git...
git init
git add .
git commit -a


Master branch has been created and committed.

Now branch to work on a feature, say hours (automatically switches to it)...
git checkout -b hours


After adding some files, editing a few existing files
git add .
git commit -a


Happy with this branch's work, then merge it into the master branch...
git checkout master
git pull . hours


master branch now contains all changes from hours branch.

Not happy with the changes made in hours after all? Go back to last master commit...
git reset --hard HEAD^


That tells git to return to the previous commit on this current branch, which is master. the carat is what specifies "parent" or previous commit.

Let's go back to hours branch, make changes, then commit it, then merge it back into master.
git checkout hours
[do some changes, no new files]
git commit -a
git checkout master
git pull . hours


Satisfied with changes, lets delete the hours branch...
git branch -D hours


Now let's create a new branch, more_features, based off of the original master commit, containing none of the work from the hours branch of development...
git log
(copy the commit id for the first commit on master)
git checkout -b more_features [commit_id]


Make changes to more_features, commit them, then switch back to master, and merge it in...
git commit -a
git checkout master
git pull . more_features

Export mysql table into csv

Use /tmp, as mySql doesn't have write privileges everywhere.

select * into outfile '/tmp/outfile.txt' fields terminated by ',' from my_table_name;

gdb debug of mongrel rails ruby segfault

attach gdb to the running process of mongrel by running gdb against ruby, with the PID of mongrel as the second argument

gdb /usr/local/bin/ruby [PID]


After gdb has attached, be sure to run the "c" command to continue and allow mongrel/ruby to continue running until the segfault, whereupon you can use "whe" to get an extensive backtrace leading to the problem.

Normally coredumps are not shown in a terminal window. To enable core dumps for more information, run:
ulimit -c 512

which allows coredump's upto 512MB in size.

Remove sudo password request when deploying

Change the sudoers list by adding a NOPASSWD: [Cmnd_Alias] line.

In terminal: visudo

# Cmnd alias specification
Cmnd_Alias HTTPD = /usr/local/sbin/apachectl, /etc/init.d/apache2

# User privilege specification
[user] ALL = NOPASSWD: HTTPD


Be sure that the NOPASSWD line is last in visudo, else, it risks being overwritten by later specifications.

change mysql user password

From terminal (square brackets denote your input, do not actually include the brackets):

mysqladmin -u [user] -h localhost -p password '[new_password]'

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';}
?>