Category Archives: Configurations

Setting your git username and email address

Single Repo

If you need to quickly set the user and email address for a single git repo, you can do this:


git config user.email john.doe@example.com
git config user.name "John Doe"

If you want to modify the .git/config file directly, you can add in this block:


[user]
name = John Doe
email = john.doe@example.com

All Repos


git config --global user.email john.doe@example.com
git config --global user.name "John Doe"

Using xcopy to safely copy (and verify) files from one drive to another

I recently upgraded my “data” drive from a 3TB to a WD Black 6TB Performance Desktop Hard Disk Drive – 7200 RPM SATA 6 Gb/s 128MB Cache 3.5 Inch drive.

Once I had both drives installed in the computer, it was time to copy data.

Head over to: Start Menu -> All Programs -> Accessories -> Command Prompt. Right click on it, and choose “Run as administrator”


xcopy f:\ e:\ /f /h /i /j /o /s /v /x 1>>c:\xferlog.txt 2>&1

Continue reading Using xcopy to safely copy (and verify) files from one drive to another

Apache and mod-rewrite – redirecting a folder to new server

If you ever need to move one (or more) subdirectories, but not an entire site over to a new webserver, and you want to redirect the traffic, here’s how you can do it:


RewriteEngine On
RewriteRule ^directory_name(.*)$ http://www.example.com/directory_name [R=301,NC,L]

If you have multiple virtual hosts on the site, you might want to specify which host name’s directory_name should get sent to new server www.example.com

RewriteEngine On
RewriteCond %{HTTP_HOST} ^markcerv.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.markcerv.com$
RewriteRule ^directory_name(.*)$ http://www.example.com/directory_name [R=301,NC,L]

My favorite way to run screen

First, make sure you have screen installed:

[bash]
$ sudo apt-get install screen
[/bash]

Then, create a .screenrc file with the following in it:
[bash]
screen -t root sudo su –
screen -t bash2
screen -t bash3

select 0
startup_message off

caption always "%{= kw}%-w%{= bw}%n %t%{-}%+w %-= @%H – %c – (%l)"
#
# Call via: screen -R -e^Hh -d
#
# to change the strings, look at:
# http://www.gnu.org/software/screen/manual/screen.html#String-Escapes
#
# to test your changes, you can either copy the above line, the do
# CTRL-H : and then paste in the line above
#
# or, CTRL-H :source ~/.screenrc
[/bash]

Lastly, start up screen:
[bash]
screen -R -e^Hh -d
[/bash]

This let’s you switch screens by pressing CTRL-H and then SPACEBAR. (I found that I use CTRL-A far too much to let that be the standard screen key binding)

Stash your mysql password in the .my.cnf file

Hopefully you are using usernames and passwords when accessing your MySQL databases. Security can make it hard to quickly jump in and start working in the MySQL shell if your password is quite complicated.

Here’s the solution:

create a ~/.my.cnf file and fill it with:

[client]
database=yourDBname
user=yourDBusername
password=yourSuperSecretPassword

Next, make sure that only you can read it:

chmod 600 ~/.my.cnf

Lastly, test it out:

user@host:~$ mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 65863
Server version: 5.5.31-0ubuntu0.12.04.2 (Ubuntu)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show tables;
+-----------------------+
| Tables_in_yourDBname |
+-----------------------+
| wp_commentmeta |
| wp_comments |
| wp_links |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_terms |
| wp_usermeta |
| wp_users |
+-----------------------+
11 rows in set (0.00 sec)

mysql>

 

Voila! In there without having to worry about needing to look up your password.

Force all web traffic to redirect to SSL (https) web server using .htaccess file

Here is the minimum amount of configuration needed to force all web traffic (port 80, http) over to https (port 443 via SSL).

1) Create a .htaccess file that looks similar to this one:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*) https://www.example.com/$1 [L]

and place it at the root of the web server directory where you want to redirect the traffic. Restart apache.

2) If that doesn’t work, you might need to modify your apache config file’s AllowOverride setting. If you were trying to use a .htaccess file just inside of the /var/www directory, you might need to edit /etc/apache2/sites-enabled/[name-of-your-site]

...
   <Directory /var/www/>
        ...
        Options FollowSymLinks
        AllowOverride FileInfo
        ...
   </Directory>

NOTE: Your web site might have other directives for Options and AllowOverride, but the 2 that I have show are the bare minimum to get the .htaccess file working.

Changing the default editor from pico to vim

On new (or new to me systems) I find it annoying to use a program like git, or crontab -e and find myself in the pico editor.  🙁

So, here’s how to change it:

[bash]
sudo update-alternatives –config editor

There are 4 choices for the alternative editor (providing /usr/bin/editor).

Selection Path Priority Status
————————————————————
* 0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
3 /usr/bin/vim.basic 30 manual mode
4 /usr/bin/vim.tiny 10 manual mode

Press enter to keep the current choice[*], or type selection number: 3
update-alternatives: using /usr/bin/vim.basic to provide /usr/bin/editor (editor) in manual mode.
[/bash]

and to confirm your selection, run the same command again, and check out the item that has the asterisk next to it:

[bash]
sudo update-alternatives –config editor
There are 4 choices for the alternative editor (providing /usr/bin/editor).

Selection Path Priority Status
————————————————————
0 /bin/nano 40 auto mode
1 /bin/ed -100 manual mode
2 /bin/nano 40 manual mode
* 3 /usr/bin/vim.basic 30 manual mode
4 /usr/bin/vim.tiny 10 manual mode

Press enter to keep the current choice[*], or type selection number:
[/bash]

If that still doesn’t work, try this instead:

[bash]
export EDITOR=/usr/bin/vim.basic
[/bash]