Extending Piston’s BaseHandler for ForeignKey support
Recently I've started working on an API using Django and Piston for an update to our internal timekeeping stuff (something I've been in charge of for most of the time I've been at VV). I quickly ran into a problem with Piston when trying to create or update models that have ForeignKeys in them. As it turns out, Piston does not support ForeignKey. What follows is my attempt at adding this support as well as support for better REST urls that allow for searching and such. I went this route after reading through this post's responses about this very problem.
A note of caution: I've only very recently started learning Python, Django, and Piston - so it's likely that this isn't the best approach... It's also pretty dirty as I'm currently using a combination of rc and {'status':0, 'statusmsg':'message here'} whenever errors happen... what would be better would be to always use rc.SOMETHING and throw errors that get caught and formatted correctly - I just haven't had time to clean this all up just yet...
Update: Creating a TrashCan for shell undelete
update: I updated this script so that it would put a number at the end of the file name if it already exists in the trash... it's a slow process (increment from 0 and test until you don't find an existing file) but it works
Original post follows:
so a couple of weeks ago I was up far later than I should have been and managed to run the following, as root, in the root directory /
rm -rf *
What I was trying to do is delete a bunch of backup files that my backup script had been sticking in the wrong location (the smart thing would have been to copy the wrongly placed backup files into the correct place, and also not use -rf, but i'm a noob)
So, as you can imagine, after about 2 seconds (the time it took me to realize what had just happened and instantly wake up) the server was foobared. Now that it's been a couple weeks I can actually marvel at how fast rm is, it literally deleted almost everything on the server (everything that wasn't running at least) in a matter of seconds, that's pretty impressive when you are use to deleting things in windows (and I almost always shift delete, a dangerous pattern emerges...)
Anyway, so I had to re-install the OS and everything else. Luckily I had a 5 day old backup of the web and svn contents, and some chrome caches of my blog (which had all of my instructions for getting the server back up and going) so I wasn't fully up a creek. After restoring everything I did some searching around and found a way to replace rm with a move to trash bash script which is complemented by a cron that runs to clean out old trash.
Here's how to get the same thing
New HD
The hard-drive on my desktop started having S.M.A.R.T. errors yesterday so I went and picked up a WD Caviar Black and threw 64 bit Win 7 on it. Turns out the HD I had was still under warranty, so there will be another 500gigs coming my way sometime in the future... I'll have to figure out what to do with it!
I have another tutorial on how to get the latest python running in CentOS 5.4 - hopefully I'll finish writing that this weekend.
I’m learning Python
As the subject of this post suggests, I'm learning python. I was going to go out to the local bookstore today to buy a book on python (I normally just try to learn things on my own, but I'm unfortunately in a bit of a hurry and am finding it difficult to find useful tutorials online) but it turned out I didn't need to. Dive Into Python is available free online, or in book form, as well as Python for Software Design - How to Think Like a Computer Scientist I'm midway through chapter 3 in Dive... and my inability to stay focused has caused me to write this post.
I love free
Yesterday I hooked up a post-commit script in my svn repository that automatically publishes the python code I'm currently trying to write. It's pretty cool as it allows you to source control your web(site/apps) I'll post later on how to do such a thing.
Serving ASP.NET pages in Apache on CentOS 5
I'm starting to love ASP.NET and the ability to do everything in C# (I'm currently working on an internal silverlight app at work and creating a RESTful API is more fun in C#). Anyway, you can do a yum install mod_mono, but it's a pretty old version so I did some research and found a guide on building it yourself along with two other guides that were roughly the same, but not as good... (1, 2) and somehow ended up with a working server. This is a companion to that guide with more up to date versions of things. (it took me SEVERAL trial and error attempts to get things working :/ so hopefully i didn't miss any steps)
Let me preface this with the fact that if you're running one of the already supported OSs (debian or unbuntu for instance) you shouldn't follow this guide - instead you should just look on the mono website for information.
Dynamic DNS support for WHM using ddclient
The server which I use to use to host my websites is now primarily used as my DNS and also a backup ftp space for this server to store backups (that way I don't have to buy some sort of tape backup thing). This is great except for the fact that my IP changes a couple of times a year. Up until now I was pushing requests from the webhost's DNS to dyndns and then to my home server running ddclient to update dyndns. Of course I could have paid around $30 a year per domain but I'm cheap.
So I modified ddclient so that it would update my host's DNS server. My host uses cpanel/WHM which luckily has a JSON API!
Here's how you can make the same modifications:
Installing Trac and Subversion on CentOS5
Installing Trac and Subversion on CentOS is pretty simple.
First, you need to install subversion - it was automatically installed for me already when I installed the OS, however I wanted to update it and found out that I couldn't do so until I deleted the i386 version.
Forwarding all mail to your ISP’s smtp server with postfix and CentOS 5.4
I needed to forward all server mails to external email addresses and I had to use my ISP's smtp to do it. This is because everything is blocked by my ISP to combat spammers just making their own smtp server at home and then running it all hours of the day. To do this, you should have postfix installed and running already.
Installing P5KPL-CM network drivers on CentOS 5.4
Once CentOS was installed, the first thing I had to do to make the server useful was to build and install the network drivers for myASUS P5KPL-CM Motherboard. Here's how to do it:
First, you're going to need the LinuxDrivers zip file. You'll need to unzip and then unrar l1e-l2e-linux-v1.0.0.4.rar (found in the LinuxDrivers/L1e_Lan directory in the zip). I had to do this on my Windows PC since I couldn't install unrar on the server (no network, remember?)
Once you're transfered the contents of l1e-l2e-linux-v1.0.0.4.rar to the server, follow these steps:
Server Specs
This a post from the old setup... but the server is still the same. There was a note about forgetting how I installed ReviewBoard, and how much of a pain in the ass it was - I havn't done that yet... OH BOY!
Here's the original post, minus the ReviewBoard comment:
Someone asked me last week what the specs of the server I put together were. Here’s the low down