Skip to content

Instantly share code, notes, and snippets.

View prestontimmons's full-sized avatar

Preston Timmons prestontimmons

View GitHub Profile
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
# Count lines in a Python file
find -name "*.py" | xargs cat | wc -l
@prestontimmons
prestontimmons / user_management.rst
Created March 29, 2010 17:39
Managing users in Linux

Add user:

/usr/sbin/useradd -gusers -Gmgmt -s/bin/bash -pxxxx -d/home/username -m username

Change username:

/usr/sbin/usermod -l <to> <from>

Delete a user and their home directory:

# Set up an ssh tunnel between to servers
ssh -f user@personal-server.com -L 2000:personal-server.com:25 -N
# From http://www.revsys.com/writings/quicktips/ssh-tunnel.html
@prestontimmons
prestontimmons / gist:348152
Created March 29, 2010 17:42
Search and Replace in Linux

Search and Replace Utilities

sed

The sed command makes it easy to modify text.

$ sed -i "s/django.conf.urls.defaults/django.conf.urls/g" urls.py
@prestontimmons
prestontimmons / gist:348153
Created March 29, 2010 17:42
Get unique apache errors and count
# Get unique apache errors and count
sudo tail -100 /var/log/httpd/error_log | cut -d']' -f 4-99 | sed -e "s/, referer.*//g"|sort|uniq -c
@prestontimmons
prestontimmons / gist:348156
Created March 29, 2010 17:43
Postgres Commands
Postgres
Drop index:
DROP INDEX title_idx;
@prestontimmons
prestontimmons / gist:348612
Created March 30, 2010 00:34
Restart Apache
Ubuntu:
/etc/init.d/apache2 restart
Redhat:
/etc/init.d/httpd restart
/usr/sbin/apachectl restart
#!/bin/bash
#
# supervisord This scripts turns supervisord on
#
# Author: Mike McGrath <mmcgrath@redhat.com> (based off yumupdatesd)
#
# chkconfig: - 95 04
#
# description: supervisor is a process control utility. It has a web based
# xmlrpc interface as well as a few other nifty features.
# Check MySQL storage engine
SELECT TABLE_NAME, ENGINE FROM information_schema.TABLES;