Archive

Archive for the ‘Uncategorized’ Category

PacketTerrier Twitter Bot

September 13th, 2011 No comments

Like any good nerd, I felt my dog needed a twitter. This is written in Python using the python-twitter library.

http://www.twitter.com/PacketTerrier


#!/usr/bin/env python
import time
import twitter
import math
import random
import threading
import logging

interface = twitter.Api(consumer_key='', consumer_secret='', access_token_key='', access_token_secret='')

def main():
	logging.basicConfig(filename='packetTwitter.log',level=logging.DEBUG)
	tt = TweeterThread(interface)
	ft = FrienderThread(interface)
	tt.daemon = True
	ft.daemon = True
	tt.start()
	ft.start()
	while True:
		time.sleep(1)
		pass

class TweeterThread(threading.Thread):
	def __init__(self,interface):
		self.interface = interface
		threading.Thread.__init__(self)

	def run(self):
		logging.info("Tweeter Start")
		message = None
		lastMessage = None
		status = None
		while True:
			nextSleep =  math.ceil(random.uniform(1800,7200))
			while message == lastMessage:
				message = chooseTweet(nextSleep)
				time.sleep(15)
			try:
				logging.info("Posting status update")
				status = self.interface.PostUpdate(message)
			except twitter.TwitterError, error:
				logging.error("Twitter API Error: '%s'  Trying again in 60 seconds." % error.message)
				nextSleep = 60
			logging.debug(message)
			lastMessage = message
			time.sleep(nextSleep)

class FrienderThread(threading.Thread):
	def __init__(self,interface):
		self.interface = interface
		threading.Thread.__init__(self)

	def run(self):
		logging.info("Friender Start")
		friends = self.interface.GetFriends()
		while True:
			logging.info("Checking for new friends")
			replies = self.interface.GetReplies()
			for r in replies:
				isFriend = False
				for f in friends:
					if f._screen_name == r._user._screen_name:
						isFriend = True
				if not isFriend:
					logging.info("Making friends with %s" % r._user._screen_name)
					self.interface.CreateFriendship(r._user._screen_name)
					self.interface.PostUpdate("Hai @%s! I like making new friends!  Did you bring me treats?!?!" % r._user._screen_name)
					friends = self.interface.GetFriends()
			time.sleep(600)

def chooseTweet(nextSleep):
    hour = time.strftime("%H")
    minute = time.strftime("%M")
    if hour >= 23 and (hour < = 6 and minute <= 59):
        messageFile = "sleepMessage.txt"
    elif hour >= 16 and hour < = 17 and (time.strftime("%w") >= 1 and time.strftime("%w") <= 5):
        messageFile = "homeSoonMessage.txt"
    else:
        messageFile = "dayMessage.txt"
    messages = list()
    mf = open(messageFile, "r")
    for line in mf:
        messages.append(line)
    mf.close()
    return random.choice(messages).strip()

if __name__ == '__main__':
	main()
Categories: Uncategorized Tags:

Proof That Fox News Sucks

December 4th, 2009 No comments

Doing my usual morning ritual of catching up on Google Reader I noticed something amusing…absolute proof that Fox News is inept and does not check their facts before finding some way to attack Obama. Oh no! If Fox News is wrong…where are closed minded people to get their information?!?!
fox_news_ineptitude
Fox: Where are the jobs?
AP: Unemployment rate fell in November.
Fox News FAIL!

Categories: Uncategorized Tags:

Back up a cPanel server via SSHFS

November 13th, 2009 No comments

So you have a cPanel server and want to set up automated, off-site backups, just in case anything should happen? This can be done easily with a FUSE (filesystem in userspace) module called SSHFS, and requires a minimum of setup. SSHFS allows one to mount any remote directory accessible via SFTP to a local filesystem. Cool, huh?

All you really need to accomplish this is access to a server via SSH with sufficient disk space to hold your backups, and the FUSE module available on your server. (Many VPS providers are willing to enable this for you if it is not already enabled)

Notice: The following howto assumes that you are a competent linux/unix administrator. I take no responsibility for any damage or data loss which may be caused by following these instructions.

Step one: Set up a passwordless SSH key on the cPanel server.

First, we need to generate an SSH key:
ssh-keygen
Be sure you leave the passphrase option blank, or the automatic part won’t work so well :) . The default options will work fine for this.

Now, you will need to get the public key from the cPanel server that you will be importing:
cat ~/.ssh/id_rsa.pub
The above assumes you did not choose a DSA key, or opt to store it in a location other than default. Copy the text that the above command outputs.

Now, move over to your remote/backup server, and run the following:
echo "text you copied from the cPanel server" >> ~/.ssh/authorized_keys
chmod 640 ~/.ssh/authorized_keys

Next, go back to the cPanel server and test to ensure that the public key login works:
ssh user@remote_server
If the public key is installed correctly, you will be logged into the remote server without any password prompts.

Step two: install SSHFS

For purposes of this howto, I’m assuming you are using CentOS, in which case you can install sshfs with the following command:
yum install sshfs
Say yes to any dependencies it may prompt you to install.

Step three: Configure the fstab on your cPanel server to mount a backup directory

Assuming you want your backups to go to /backup on the local cPanel server (replacing /path/to/storage with the appropriate path on the remote server):
mkdir /backup
echo "sshfs#user@remote_server:/path/to/storage /backup fuse noauto,compression=yes,nonempty" >> /etc/fstab

Test this mount with the command “mount /backup” If you receive no errors, the mount should be working correctly.

Step four: Configure the cPanel backup

Visit the address https://_your_cpanel_server_:2087/scripts/backupset
in your web browser, and configure the settings to your liking, making sure to select the following:
Backup Status: Enabled
Remount/Unmount backup drive: Enabled
Bail out if backup drive mount fails: Enabled
Backup destination: /backup

Step five: Profit

Now, every night at 1AM (server time) your server will automatically back up to the remote server via SSH.

Categories: Uncategorized Tags: , ,

Create Debian Lenny Xen VE

October 28th, 2009 No comments

I got sick of doing the same bunch of things every time I created a new VE so I wrote myself a script. It takes only one argument: The path to the lvm volume you want to use as the root device.


#!/bin/bash

mkfs.ext3 "$1"
mkdir -p /media/buildvetmp
mount "$1" /media/buildvetmp
debootstrap lenny /media/buildvetmp http://aptcache:3142/ftp.us.debian.org/debian/
sed -n '/########/,$p' /root/buildve.sh | sed -n '/bin\/bash/,$p' | sed -n '/########/,$p' | sed -n '/bin\/bash/,$p' > /media/buildvetmp/buildve.sh
chmod 700 /media/buildvetmp/buildve.sh
chroot /media/buildvetmp /bin/bash /buildve.sh
rm /media/buildvetmp/buildve.sh
umount /media/buildvetmp
rm -r /media/buildvetmp

exit

###################chroot starts here
#!/bin/bash

echo "/dev/sda2 / ext3 relatime,nodiratime 0 0
/dev/sda1 none swap sw" >> /etc/fstab
echo "APT::Default-Release \"stable\";" >> /etc/apt/apt.conf
rm -f /etc/apt/sources.list
echo "deb http://ftp.us.debian.org/debian lenny main contrib non-free
deb http://ftp.us.debian.org/debian testing main contrib non-free
deb http://packages.dotdeb.org stable all" >> /etc/apt/sources.list
echo "Acquire::http::Proxy \"http://aptcache:3142/\";" >> /etc/apt/apt.conf.d/80proxy
echo "127.0.0.1 localhost" >> /etc/hosts
rm /etc/hostname
echo "localhost" >> /etc/hostname
echo "
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 10.0.0.49
netmask 255.255.0.0
network 10.0.0.0
broadcast 10.0.255.255
gateway 10.0.0.1" >> /etc/network/interfaces

apt-get update
apt-get -y install linux-modules-`uname -r` libc6-xen vim

echo "#!/bin/bash
apt-get -y install udev openssh-server syslog-ng ntp
sleep 5
rm -f /etc/rc2.d/S20installpkgs
sleep 1
shutdown -r now" >> /etc/rc2.d/S20installpkgs
chmod +x /etc/rc2.d/S20installpkgs

exit
Categories: Uncategorized Tags:

Loan Payoff Calculator

September 5th, 2009 No comments

This has probably been done before, but this script fixes two problems I’ve noticed with loan calculators:

  1. They assume monthly interest compounding (most loans are compounded daily)
  2. They don’t allow you to calculate the payments if you’re splitting your payment (eg: paying $200 twice a month instead of $400 once a month)
  3. 
    #/usr/bin/env python
    import math
    
    # Remaining amount on the loan
    toPayOff = 12345.67
    # Interest rate
    intRate = 12.34
    # Amount of your payment
    payAmt = 200
    # Making the payment every x days
    payEvery = 15
    # Maximum amount you're willing to pay extra to just "pay it off"
    balloonMax = 200
    # Days til the next payment
    runUpDays = 15
    
    # Do not edit below this line
    days = 0
    pmtNum = 0
    dailyInt = (intRate / 100) /365
    origToPayOff = toPayOff
    totalPaid = 0
    while (runUpDays > 0):
        toPayOff = (math.ceil((toPayOff * (1 + dailyInt))*100))/100
        runUpDays -= 1
    while (toPayOff > 0):
        days += 1
        toPayOff = (math.ceil((toPayOff * (1 + dailyInt))*100))/100
        if (days % payEvery == 0):
            toPayOff = (math.ceil(toPayOff * 100))/100
            if (toPayOff < (payAmt + balloonMax)):
                payAmt = toPayOff
            toPayOff -= payAmt
            pmtNum += 1
            totalPaid += payAmt
            print "Payment #%s\tPayment Amt: $%s\tBalance:%s" % (pmtNum,payAmt,toPayOff)
    print "Over %s payments, you will pay a total of $%s ($%s in interest)" % (pmtNum,totalPaid,(totalPaid-origToPayOff))
    
Categories: Uncategorized Tags:

SCO isn’t dead yet?

August 26th, 2009 No comments

Why the F*** hasn’t SCO died yet? They’ve gotten slapped around in court by IBM’s attorneys, declared bankruptcy, shed most of their staff… If not for the utter ignorance of the courts, they’d be gone. Now today, I read that a judge overturned the ruling that Novell owns the Unix copyright? C’mon…this is ridiculous. SCO is only suing because UNIXware is dead. If they DARE to take IBM back to court, I pity them for what they’ve got coming.

ref: http://www.networkworld.com/news/2009/082409-sco-unix-copyright-decision-overturned.html

Categories: Uncategorized Tags:

LGBT Rights Arguments

June 21st, 2009 No comments

Reading an article at http://www.dowhatsrightohio.com/ my eyes landed on what’s probably the best simple breakdown of all of the arguments people are using to try to strip rights from the LGBT community. I felt compelled to take the time to challenge their logic flaws:

a.) homosexuality is a choice so it shouldn’t be protected;

  • To this, I’d simply like to ask…what person would choose a more difficult life. If it was simply a matter of choice, I don’t think you’d have so many people making the same choice for a more difficult life.

b.) homosexuality is a behavior so it shouldn’t be protected;

  • Protesting is a behavior, yet that right is protected. Saying something shouldn’t be protected because it’s a behavior just makes no sense…look how many “behaviors” are already protected.

c.) homosexuals don’t meet the 3 three Supreme Court criteria for civil rights protection so they shouldn’t be protected (economically disadvantaged, immutable characteristic, politically powerless);

  • By limiting the rights of the LGBT community, including restricting their ability to legally marry, you create a situation of economic disadvantage as the LGBT couples are no longer able to receive the same work and tax benefits as their straight counterparts. This becomes increasingly exacerbated as you look at all of the places today where one can have their employment terminated for no other reason.
  • There has been no solid proof that one’s sexual orientation can be changed either willingly or forcibly. In fact there’s been a fair bit more research that suggests that this is indeed an immutable characteristic.
  • The article itself states that the LGBT community is approximately 3% of the population. How does this not equate to being politically powerless?

d.) protections for homosexuals violate my religious freedoms so they shouldn’t be protected

  • Someone needs to go back to high school and study the bill of rights again. People do not have unlimited rights, and their rights end where others’ begin. Your right to religious freedom CAN NOT override the rights to legal protections for LGBT persons.

I would like to see the conservatives fighting against the rights of their fellow man have a solid argument for what they’re doing. This isn’t because I believe that there IS a solid argument, just because I’d like to think that they have a reason aside from hatred and bigotry for what they’re doing.

Categories: Uncategorized Tags:

Hello world!

March 18th, 2009 No comments

Hello world.  The default post title on WordPress, but still fitting.  Sometimes I want to rant.  Sometimes I have profound thoughts.  Other times still, I may have randomness to throw around.  I’m going to do that here.  Well, that’s the plan anyway.  Let’s see how well it works out this time :)

Categories: Uncategorized Tags:

dork-e.com is Stephen Fry proof thanks to caching by WP Super Cache