Sep
30
2009
I recently had to move all my sites over to a new host due to Lunarpages basically kicking me off. I chose DreamHost because they were having a promotion where I get a full year for $10. One of my coworkers uses them with no complaints and they give free shell access.
Vim is my editor of choice but I hate coding without syntax highlighting and DreamHost doesn’t have Vim Syntax highlighting on by default. It is possible to type “:syntax enable” when already in the editor to enable syntax highlighting on the current file that you’re editing but after closing it and opening another file you will be forced to do it again.
To enable syntax highlighting forever I had to edit the .vimrc file which lives in my home directory. It didn’t exist so I had to create one. After I created this file I added the lines :
syntax enable
set background=dark
set nocompatible
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set showmatch
set ruler
set virtualedit=all
Alternatively you could put ‘background=light’ which will make the colors more readable if your console is black text on a white background. The rest of those lines are just personal preference and put there so I can copy and paste them elsewhere. More info and a great example can be found at
this vim site.
1 comment | tags: linux, syntax, syntax colors, syntax highlighting, vim, vimrc | posted in linux, reference
Sep
28
2009
I’ve been meaning to load XBMC on my xbox for awhile and use it for a media player in the bedroom but I never got around to it because all the instructional material that I had read said I would have to scour used game stores for a very specific version of MechAssualt or one of the other games that allow you to softmod the original xbox. Turns out I didn’t have to. I did some reading and found a way to mod my original Xbox without having to purchase anything at all. The technique is called hot swapping and it involves attaching the Xbox hard drive to a pc and overwriting the dashboard.
The only real problem with this method of modding the original Xbox is that the console’s drive is normally locked. If you just take the drive out of the Xbox and hook it up to your PC then the drive will not work. That is why it needs to be swapped when hot (powered up). When the Xbox is in the dashboard or running a game then the drive becomes unlocked. When I swapped my drive I was in the middle of a Chessmaster game. Apparently this can be dangerous to both the PC and the Xbox so it’s recommended to either jumper the two cases together or supply the Xbox drive with power from your PC’s power supply.
The entire process was surprisingly easy and once I had finished reading every thread I could find on the topic I had my Xbox streaming family guy with XBMC in about an hour or so. The only down side so far is that the fans in the Xbox seem to be on full output always and it’s really loud but apparently there is a fix for that.
Obviously I had to open up both the Xbox and my PC. There’s a very descriptive tutorial on how to open the Xbox at this Xbox site. I can’t really say that I didn’t buy anything because I did end up purchasing a #20 Torx Screwdriver. I only had to pop off the cover of the Xbox and take the harddrive section out. I did not remove the drive from it’s plastic enclosure. With the PC, I disconnected all drives and left only one DVD-ROM connected as the secondary master.
It was tedious to get the Xbox and PC close enough together to connect the power cable from the PC to the Xbox drive while having the Xbox drive still connected to the Xbox IDE cable but once it was close enough I had more than enough room to attach the master IDE cable from the PC to the Xbox drive when it was time to swap. Here’s a pic of my Xbox connected to one of my old computers:
As far as software and explicit instructional material go I loosely followed this Xbox hotswap guide. I used version 3.1 of Ndure as opposed to 3.0 like the guide suggests and the options were a little different but still pretty straightforward. I had a problem here where I got banned for the xbins IRC channel and couldn’t rejoin but I used a web based efnet client and managed to get back in. I also was unable to get any software from the xbins server unless I used FlashFXP. Other FTP clients wouldn’t let me download anything.
By default, after the installation, the new dashboard is UNLEASHX. The sounds are hideous and it looks really bad but it gave me ftp access and seeing it meant that I didn’t break anything. After putting everything back together the first thing I did was install XBMC.
9 comments | tags: games, hot swap, media player, original xbox, xbmc, xbox, xbox hot swap | posted in hardware, xbox
Sep
22
2009
If you spend a lot of time on the linux command line you quickly find that it requires a lot of typing and retyping commands. I used to find myself using the exact same lengthy command multiple times a day and to get there I would type “history | grep some_command” and then execute it from there. Since I knew enough to get the job done I hadn’t really tried to find more efficient ways of doing the same old thing. But when I found out about the Linux bang (!) commands I realized how wasteful what I was doing really was.
The exclamation mark, in this case, is referred to as a ‘bang’.
!!
This bang command, when entered into the bash shell will run the previous command. It basically does the same thing as hitting the up arrow to take you to the previous command and then hitting enter.
!ls
This will run the last command that started with ‘ls’. If you ran ‘ls -al /etc/init.d’ a few commands ago and then you type ‘!ls’ the full command will be run again, assuming that you haven’t used that command since then.
!ls:p
This will display the command instead of running it.
!$
This one will run the last word of the previous command. This one is mainly useful for substitutions.
!$:p
Instead of running the last word of the previous command this will print it out.
!*
This bang command will run the previous command without the first word. This one is also only really useful for substitutions as we see in the examples that follow.
!*:p
This will print the previous command without the first word.
Here are a few examples of how to use these bash bang commands in everyday command line usage :
For the purposes of these examples, every example will assume these are the last three commands you ran:
% which firefox
% make
% ./foo -f foo.conf
% vi foo.c bar.c
Getting stuff from the last command:
Full line: % !! becomes: % vi foo.c bar.c
Last arg : % svn ci !$ becomes: % svn ci bar.c
All args : % svn ci !* becomes: % svn ci foo.c bar.c
First arg: % svn ci !!:1 becomes: % svn ci foo.c
Accessing commandlines by pattern:
Full line: % !./f becomes: % ./foo -f foo.conf
Full line: % vi `!whi` becomes: % vi `which firefox`
Last arg : % vi !./f:$ becomes: % vi foo.conf
All args : % ./bar !./f:* becomes: % ./bar -f foo.conf
First arg: % svn ci !vi:1 becomes: % svn ci foo.c
I found those examples
here.
12 comments | tags: !, bang, bash, command line, commands, console, efficiency, linux | posted in linux, reference
Sep
21
2009
Spending a lot of time on the command line lately I noticed that Ubuntu does not come with Vim syntax highlighting by default. Apparently it installs a version of Vim called vim-tiny which doesn’t include any syntax highlighting.
There are two packages that you can install to get syntax highlighting to work in Vim: vim-full and vim-common. Because I didn’t have gnome installed vim-full was a very large download (like 50MB) and it errored out anyway. vim-common is definitely the way to go.
sudo apt-get install vim
The above line will replace vim-tiny with vim-common and will allow for syntax highlighting. A lot of the time you will have to enable syntax highlighting by editing the vimrc config file either in /etc/vim or in yur home directory. You will need to uncomment the line “syntax on”.
Comments Off on Vim Syntax Highlighting In Ubuntu | tags: linux, syntax, syntax highlighting, ubuntu, vim, vimrc | posted in linux, problems and solutions, programming, reference
Sep
20
2009
Today I created a simple shell script and I was getting a few odd errors:
cody@taylor:/var/some_folder/server$ ./process_xml.sh
-bash: ./process_xml.sh: /bin/sh^M: bad interpreter: No such file or directory
I figured it was probably a permissions error or an issue with the shebang (#!/bin/sh) line. I tried removing the shebang line, changing it to use dash or bash explicitly, chmoding to 777 and still no luck and another odd error.
cody@taylor:/var/some_folder/server$ sh process_xml.sh
: not found.sh: 4:
I then checked the log file that the commands were supposed to be writing to and it was filled with ‘^M’ on every line break and the log name itself was followed by a ‘?’. Took a minute or two but I finally clued in that I wrote that script on a windows machine and then exported it to an ubuntu linux server via subversion. It was just a basic text format issue.
Under DOS (Windows/PC) the end of a line of text is signalled using the ASCII code sequence CarriageReturn,LineFeed. Alternately written as CR,LF or the bytes 0x0D,0x0A. On the Macintosh platform, only the CR character is used. Under UNIX, the opposite is true and only the LF character is used.
After a quick :
cody@taylor:/var/some_folder/server$ apt-get install tofrodos
cody@taylor:/var/some_folder/server$ dos2unix process_xml.sh
Everything worked fine.
7 comments | tags: .ipa, bad interpreter, error, linux, Mac, problem, shell script, solution, ubuntu, wikipedia | posted in linux, problems and solutions, reference
Sep
14
2009
My webhost recently moved all my sites to a ‘stabilization’ server because my sites were using far to much CPU time and Memory. After reviewing the logs it looked like some bot from India decided to repeatedly scrape one of my sites in it’s entirety without any delays between requests. So the support team over there either requires me to correct the problem or upgrade to a dedicated server plan at ridiculous costs.
Since I didn’t really think that there was a problem I emailed back about the single IP address that was causing all the issues and took steps to prevent requests from that IP address from accessing the site. The support team replied saying that my usage was still high and that I still needed to correct the problem. A little frustrated, I did some research on how to improve my site’s load time and hopefully reduce CPU and memory usage.
Most of my sites use wordpress so I found a large number of articles geared specifically to optimizing wordpress blogs. Before I tried anything I backed up my entire public_html directory and did a dump of all my mySQL databases (took almost 20 minutes for the dump).
Dealing with Plugins
The first thing I did was upgrade all my plugins. Most wordpress plugins allow you to upgrade automatically so all you really have to do is click a button and all the work is done for you. I also deactivated and deleted a surprising number of plugins that I haven’t really had any use for recently. Apparently a lot of free plugins can cause large amounts of unneccesary load on your server due to the authors not really knowing or caring how well their software performs.
Dealing with spam bots
I have been using the Akismet plugin for awhile and it has been reporting large amounts of spam comments and pingbacks. It’s not really something that most people worry about because the spam is automatically deleted after a period of time. It does however increase server load, especially if it’s in the thousands of messages a day. I found this little mod_rewrite snippet to deny any blatent spammers that don’t have a proper referer :
RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*codytaylor.org.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule ^(.*)$ ^http://lemonparty.org//$ [R=301,L]
Cache and Compress
Since most of my pages rarely change it’s silly to generate every page for every request dynamically. After some reading I decided to use WP Super Cache to help optimize my WordPress sites. Of course just enabling Super Cache in the WP Super Cache plugin didn’t really improve load times for the end user but it should reduce server load immensely. What did improve load times drastically was the Super Cache Compression. This was a little more involved to get going but if you’re comfortable with copying and pasting code into a .htaccess file then it shouldn’t be difficult as long as your host supports mod_mime, mod_rewrite, and mod_deflate.
After going through all that, my sites now average at about half the load time they used to. Hopefully my web host feels that I’ve done enough to get off the ‘stabilization’ server so I don’t have to transfer all my stuff to another company.
3 comments | tags: database, databases, email, mysql, sql, web | posted in mod_rewrite, problems and solutions, reference, wordpress