Never been to TextSnippets 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!)

« Newer Snippets
Older Snippets »
Showing 21-29 of 29 total

mysql add user

// description of your code here

mysql> GRANT ALL PRIVILEGES ON *.* TO 'monty'@'localhost'
    ->     IDENTIFIED BY 'some_pass' WITH GRANT OPTION;

change mysql root password

// description of your code here

mysql -h localhost -u root
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('root-pwd') WHERE user='root';
mysql> FLUSH PRIVILEGES;
mysql> EXIT

filesharing between linux and windows

In Redhat EL WS 4 (which has Samba pre-installed and running)

become superuser then create a device to mount to
mkdir /mount/<linx_share>


Add an entry to the /etc/hosts for the windows box, with its IP and a hostname
192.168.80.1 DL1


Then create the share in the windows box (in Windows, using normal file sharing.
We'll call it win_share

Then mount the device in Linux
mount -t smbfs ///win_share /mnt/linx_share


eg.
mount -t smbfs //DL1/sshare /mnt/share


Linux should ask for a password (windows password). This assumes that the username between linux and the windows boxes are the same!

After that, you should be able to view the win_share directly from linux and have access to all its files.

one rails app, multiple domains (via alias domains)

Short version:
Is there any problem with serving a rails app from multiple domain names by simply creating an Alias Server and adding another $HTTP["host"] entry to your rails/lighttpd conf file (in ~/etc/lighttpd/vhosts.d/APPNAME.conf)?

Long version:
Here's the deal:
on the default virtual server created when you purchase a shared webhosting plan (USERNAME.textdrive.com) I've got a rails app installed and running off of fcgi.

Here's the .conf file for my particular rails app that gets included into the main lighttpd.conf file:

$HTTP["host"] =~ "(www\.)?(hatepad|sexymsg)\.(com|net)" {
  server.document-root        = base + "/domains/sexymsg.com/web/public/"
  server.error-handler-404 = "/dispatch.fcgi"
  fastcgi.server = (
        ".fcgi" => ( "localhost" => ( "socket" => base + "/var/run/sexymsg-0.socket" ) )
        )
}



After that, simply kill and restart the lighttpd process
kill -9 <lighttpd PID>
. ~/etc/rc.d/lighttpd.sh start

recursively find (and delete) files and directories in linux (and svn)

This example looks in the current directory for directories named .svn

That isn't the best way to do it. It will break if you have lots of .svn directories. Then the command line will be too long and you will get 'argument list too long'. Recent bash have enormous buffers so this is less of a problem. xargs solves this problem.

The other problem is any file with spaces in the name will cause bash to treat it as two arguments. Which could give an error or could delete the wrong file. find -print0 and xargs -0 solve this problem.

find . -type d -name .svn

find . -name .svn -print0 | xargs -0 rm -rf



OR make an alias to an egrep command and go nuts

alias g='egrep --color=auto -i -r'


from here on out, just type g "" *

case insensitive
recursive
colored results

unpacking gzip'd tar'd files

// description of your code here

gunzip -c <tgz file> | tar xvf -

using tar to archive files



tar -czf <tar file> <file to archive>[...]

Clear a log file

Run at prompt, replacing development.log with the name of the log file

echo -n > development.log

mysql backup / restore

// description of your code here
exports given database to a textfile which can then be zipped and downloaded or sent somewhere (mailing pending)
mysqldump -u <username> -p -q --single-transaction <db_name> > <backup_filename>


To restore the database (be sure to create the target DB before running this)
mysql -u <username> -p <db_name> < <backup_filename>


To backup and restore data only, use -t, no table data
mysqldump -u <username> -p -q --single-transaction -t <db_name> > <backup_filename>


Then restore from command line as usual.
mysql -u <username> -p <db_name> < <backup_filename>
« Newer Snippets
Older Snippets »
Showing 21-29 of 29 total