Told ya so…

Computers, Internet No Comments »

3 months ago I wrote about how Yahoo would never be taken over by Microsoft. Now at the end of a lengthy process involving many offers, threats, and attempts at hostile takeovers, Microsoft have eventually given in.

In case any of you weren’t aware, I use Yahoo Search as my main search engine after I became disillusioned with Google’s “PageRank” system and their general way of going about business. After about 6 months with Yahoo, I can definitely say that I see no obvious advantages to using Google as a search engine. I find all the same info I need in the same time I would have taken if I did use the big G.

People say that Google is more useful because it has more pages saved, but what they forget is that a lot of those pages will be useless dead ends, and some won’t even be properly entered into the online search (I’ve had enough problems finding things on my own sites to know this is the case). when it comes to actual useful content, both Google and Yahoo come out top.

Popularity: 2% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

A few zsh tricks

Computers, Linux, Ubuntu 1 Comment »

I’ve started playing around with the zsh shell, and I like it a lot more than bash. A few weeks ago I participated in the “history meme” where I used this command in zsh:

cat ~/.histfile|awk '{a[$1]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

to print out my top 10 used commands.

A slightly shorter command in zsh is:

history 1|awk '{a[$2]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

which works for anyone, even if they have their history file in a different location. The command “history 1″ prints all commands in the history from the 1st one.

Everyone, whether they are new to Linux or a guru forgets to put “sudo” in front of system commands once in a while. I often forget when I want to edit a file in /etc or need to use apt-get. Typing out the command again can be long-winded, as can pressing up to get the command again, and then reverse tabbing to the beginning of the line to type “sudo “. zsh gives an easier way:

sudo !!

Adding “!!” after anything will simply put whatever you type before the !! at the beginning of the last used command, and then execute it. It’s much faster. Additionally, just executing “!!” on the command line will execute the last command, without any prefix. You can use !! to prefix any command you want.

Finally, if you use a lot of terminals at once (like myself) it will be useful to share the history across them. Usually only the most recently opened terminal saves history. Adding these to your .zshrc file will enable all instances of zsh to store history, and update their history every time a command is executed.

setopt EXTENDED_HISTORY
setopt SHARE_HISTORY
setopt APPEND_HISTORY
setopt INC_APPEND_HISTORY

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

Shell History

Computers, Linux, Ubuntu No Comments »

Seems like a lot of Linux bloggers have been doing this recently so I thought I’d follow suit! The following command (in bash) will print the top ten commands in your shell history:

history|awk ‘{a[$2]++ } END{for(i in a){print a[i] ” ” i}}’|sort -rn|head

Of course, since I use zsh instead of bash, I had to make a few changes:

cat ~/.histfile|awk '{a[$1]++ } END{for(i in a){print a[i] " " i}}'|sort -rn|head

And my results:

88 ls
70 cd
64 sudo
64 petris
36 plato
30 vim
29 cat
26 echo
20 wine
20 make

ls, cd, and sudo are pretty standard commands that are used so it’s not surprising they come first. I clearly play petris (a tetris clone) way too often. “plato” is a custom command to connect me to my university servers. vim, cat, and echo are also pretty standard commands. I have recently begun using wine a lot to play PC games, and make to compile a load of programs :D

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

BlogShares - The fantasy blog stock market!

Atheism, Computers, Gaming, Internet 3 Comments »

I’ve recently discovered quite an interesting real time game on the internet, and one that is blog related. “BlogShares” takes information regarding incoming and outgoing links from a lot of blogs on the internet, and then calculates their “net worth” (excuse the pun). Users can then buy shares in any number of blogs, and sell them if the blog starts doing badly (i.e. less links are found going to it). I thought this was quite a clever idea so I registered, and low and behold found The Atheist Blogger (my other blog) on there…and doing rather well.

I told the system that I owned the blog, proved it with some html on the main page, and was given 1000 shares that were being reserved for the owner. These shares (thanks to the massive amount of people visiting and linking to my blog) were worth $15,000,000 each at the time, so I’ve now got a nice net worth of $15 billion. I’m unfortunately not majority owner of the “company”. That honour goes to a fellow by the name of “The Undertaker”, who has a net worth of $2,248,152,639,818,087.00. Yes, I worked it out…that’s 1000 trillion (or a quadrillion).

Anyway, it’s quite a fun game, and since it’s in real time you only need to spend a few minutes on it every day trading stocks…that is, until you start earning big!

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

3D Tetris - XNA Gaming Heaven

Computers, Gaming, Programming, Student, University, Xbox 360 8 Comments »

3 weeks ago, we were given an assignment to work on in small groups. The assignment was to make a game for the Xbox 360 in XNA Game Studio Express, which could either be 2D or 3D. The possibilities were endless, and so me and my partner Conrad decided to go all out and port one of the most popular 2D games (Tetris) to a 3D environment.

When our lecturer first heard about this, he was concerned that it might be a bit too much work for 3 weeks, and that we should start out small, perhaps trying to make 2D Tetris, and then if we thought we could port it across, start to make it in 3D. Fuck that we thought, and started planning a 3D game engine.

Of course, being lazy students, we didn’t do much but plan for the first 1.5 weeks, and then realised we had so much to do in very little time. So we started out by building an environment, which had a rotatable platform, and an array of booleans that would act as the movable area for the blocks. We then decided that even if Tetris 3D was even possible to play in 3D, it would be the hardest game ever…and so we did what any irrational programmer would do…make it harder. We renamed out project “3D Psychedelic Techno Tetris”, applied a spinning background with awful clashing colours, and added the aptly named “Logical Song” by German techno band Scooter…on and infinite loop.

Programming went better than we had ever expected, and we soon had a fully playable game that used a multitude of clever and intuitive methods to move and detect blocks. Without intending to do so, we had inadvertently created the first fully operational 3D Tetris Engine, which could be easily modified, and content (such as new bricks) easily plugged in. Since everything in controlled by a series of constants and calculations, you can easily change the size of the platform, the shapes of the blocks, and even the way the camera moves around the grid, and the game will work out how to make it playable. As so many people have claimed for so many different products: “It just works”.

So I guess I should get down to features:

- Blocks spawn at the top of the environment and move down until they either hit the platform or another block.
- Blocks can be rotated about the X, Y, and Z axis.
- A “shadow” block predicts where the block will come to rest if you were to do nothing further to it.
- Lines and columns that are “complete” will disappear and blocks above will move down to fill the gaps.
- The next block is displayed in the top right corner, and score / level system components are kept track at the bottom.
- The camera can be moved 360 degree around the platform, as well as up above the platform for a birds-eye view, and down the bottom for a normal tetris view.

Some pictures:

The game when you have just started. The first brick is floating above the platform, whilst the shadow brick predicts where it will fall. Both the current brick and the next brick are the same, and examples of the new types of brick we created in the game for the 3D version. Other than the standard bricks, there are 5 extra bricks to make the game more challenging.
Tetris Start

An alternate view is gained by rotating the camera.
Tetris Alternate View

An example of how things can rapidly build up if you don’t play well enough.
Tetris Build

What happens if you really mess up…
Tetris Fail

I should point out that all images above were prepared by myself in the game, and I am really not as bad at this game as it appears. I am in fact the current world champion at 3D Tetris, with a score of 3800 at level 8, and I welcome anyone who reckons they can score more than me.

Popularity: 4% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

Spore finally has a release date!!!

Computers, Gaming 1 Comment »

A date for every gamers diary: 7th September

A day when the most incredible, most sophisticated, most complex game in the entire history of gaming will be released. Spore has been in development since early 2000, and 8 years of work can really be felt in all the video demos that have been released. Will Wright has used procedural generating, and taken it to a whole new level. He has made his career off of so called “God games”, but I think Spore will be the ultimate achievement. You actually play God to an entire universe of life, creating, maintaining, and destroying.

All I need now is a time machine so I can actually play it…

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

Yahoo will stay well away from Microsoft…

Internet 1 Comment »

Ever since the news came that Microsoft were offering to buy out Yahoo, I was waiting for the day when Yahoo would turn round and say (albeit quite politely) “fuck off”. Although that day has yet to come, it seems that the outcome of the proposal will be negative (for Microsoft obviously).

A lot of people said they were a match made in heaven, especially in the battle to take down Google, but they obviously failed to realise that a buyout of Yahoo worth $44.6bn is akin to going to a Ferrari car dealership and trying to get a top range model for a few thousand. Yahoo have a massive presence on the web, maybe not in terms of searching, but they have a whole range of services available, including mail, stock exchange, news, weather, and many many more. A deal worth $44.6bn is, in all fairness, an insult to a company like Yahoo, who are one of the oldest companies on the web.

So, assuming Yahoo reject the offer (which is the current likelihood), what will the next move be? Well, the offer has already increased the share price of Yahoo, possibly due to the large percentage of people who thought they would accept, and on the other side of the court, Microsoft’s shares have dropped by a staggering 12%, a drop that is thought to have been caused by the amount of Microsoft supporters who rejected the initial bid, saying that the company offered too much money.

Essentially, we have Yahoo on one side wanting more for their company, and Microsoft on the other, with most of their supporters saying they should have offered less. I can’t see a viable business solution any time soon, so it’s probably accurate to say that Yahoo won’t be going anywhere with Microsoft yet.

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

MyBB 1.4 Admin Control Panel Revealed!

MyBB No Comments »

Yesterday, Chris Boulton (the project leader of MyBB) posted the first part of a “Complete Overview” series of blogs on the new ACP. It is very detailed, and contains a load of screenshots of the new features.

Check it out at the Official MyBB Blog

Popularity: 6% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

Removing Google’s hold on Firefox

Internet 1 Comment »

If you are a Firefox user, you will undoubtedly know that Google has paid Mozilla for precedence in both the Search Box, and the Location Bar Search. Google is the default search engine used if you just type a bunch of keywords in the Location Bar instead of a URL. Firefox takes those keywords, sends them to Google, and if the top result has a high enough page rank, it sends you to the page itself (much like I’m feeling lucky).

Since I’ve switched to Yahoo as my main search engine, mainly due to Google’s recent privacy scandals and coupled with the research which tends towards Yahoo results as being more reliable (Google bombing anyone?), I’ve been trying to look for a way of switching the default search engine to Yahoo. After a bit of searching, I found the answer:

1) Type about:config in a new tab.

2) Filter the configuration variables by “keyword.URL“, there should be one result by the same name.

3) Change the value of keyword.URL from the Google URL (should be: http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=navclient&gfns=1&q=) to: http://search.yahoo.com/search?ei=UTF-8&p=

Bingo, typing keywords into the location bar will now make Firefox search using Yahoo.

Note: You can add other “attributes” to the search URL, as long as &p= is left at the end, since this is where Firefox adds the search keywords.

Popularity: 3% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl

Writing an IRC Bot in Ruby

Internet, Programming 4 Comments »

Many people use IRC (Internet Relay Chat) to communicate with others around the world, usually within a specific group or community (developer projects etc). During the years that IRC has been used, many people have written scripts that log into the IRC server and perform specific tasks. These are commonly referred to as “IRC Bots”. They appear as users in the channel, but are in fact just scripts running off a computer somewhere.

An IRC Bot can be used to manage channels (kicking members, banning members, making members OPs), or just to perform fun tasks (such as randomly generate quotes for members). Either way, a lot of people don’t realise just how easy making a bot is, so I’ve put together this tutorial which will walk you through the steps of building your very own IRC bot.

First Things First
Before you start programming in Ruby you will have to have it installed on your computer. I use Ubuntu Linux and so I used the command:

sudo apt-get install ruby ruby1.9

This will install ruby versions 1.8 through 1.9 onto your system. Another program that is useful to have when debugging ruby is the interactive version:

sudo apt-get install irb

If you use another Operating System (like Windows) you will have to look up how to install ruby on the internet.

Step 1
Create a new directory which will contain all your files associated with the Bot. I’ve created a directory “IRC Bot” in my home folder, and then a subdirectory “Ruby” in that.

Enter into the directory you have just created.

Step 2
Create a file called “config.rb”, open it in your favourite editor, and type the following:

$irc_server = ''
$irc_port = ''
$irc_nick = ''
$irc_host = ''
$irc_realname = ''
$irc_nickserv = ''
$irc_identify = ''
$irc_channel = ''
$irc_prefix = ''
$irc_password_prompt = '(This nickname is registered and protected|This nickname is owned by someone else)'
$irc_password_accepted = 'Password accepted \- you are now recognized'

These are the global configuration variables that we will use throughout the program. Here is a brief description of each:
$irc_server - The address where the IRC server is located, for example ‘irc.freenode.net’.
$irc_port - The port through which you can access the IRC server. Usually this is set to ‘6667′.
$irc_nick - The nickname your bot will use when it connects to the server.
$irc_host - The host of your bot (you can set this to any address you like, for instance ‘adrianhayter.com’).
$irc_realname - The “real name” of your bot (can be anything, but I usually set it to the same value as $irc_nick).
$irc_nickserv - The nickname of the NickServ bot on the IRC server (usually left as ‘NickServ’).
$irc_identify - The command used to identify users on the IRS server (usually set to ‘IDENTIFY {password}’, where {password} is the password associated with the Bot’s nickname).
$irc_channel - The name of the IRC channel you want the Bot to join (’#linux’ etc).
$irc_prefix - The prefix you want your bot to have which saves time when typing out commands (set it to something like ‘!’ or ‘%’).
$irc_password_prompt - This is a regular expression which matches the password prompt from the server (usually can be left as it is above).
$irc_password_accepted - This is a regular expression which matches the password accepted message from the server (usually can be left as it is above).

Save the config.rb with your new values.

Step 3
Create a file called “bot.rb” and open it in your favourite editor.

Add the lines:

require 'config.rb'
require 'socket'
require 'parse.rb'

$connect_log = ""
$joined = 0

def place(s)
strx = s.gsub(/\n/, "")
strx = strx.gsub(/\r/, "")
$con.send strx + "\n", 0
puts "--> " + strx
end

$con = TCPSocket.new($irc_server,$irc_port)
place("USER " + $irc_nick + " " + $irc_host + " blah :" + $irc_realname)
place("NICK " + $irc_nick)

I’ve written a lot here, and if you have never used Ruby before then it will appear confusing, so I’ll go through it in a bit more detail.

The first three lines are all “require” statements. These statements read the files into the current bot.rb program. The first reads the config.rb that we just created, the next loads the “socket” class which is a class already built into Ruby that allows the creation of sockets to access content on the internet. The last loads the file “parse.rb” which we will create later.

The next two lines are global variables, the first is a string to store the outputs of the server (which we will use later), and the second is a variable which we will set to 1 when the bot has joined the channel.

Then we get to our first functn ion, which is called “place”. It accepts a parameter “s”, and strips this parameter of all new lines and carriage returns, before sending it down the connection and outputting it to the terminal. You don’t have to use this function, but it is very useful this entire bot program is based around it.

Finally, we open a new TCP Socket connection to the IRC server using the details we gave in the config.rb file, and then send our user and nick information down it using the place function.

Step 4

Now that we have a connection to the server, we are going to have to create an infinite loop which continually gets data from the server and checks it to see if it is important.

Add this code below what you have already written:

while true do

$connect_log = $con.recv(512)

s = $connect_log.split("\r")
for i in s
puts i
if i =~ /PING\ / then
a = i.split("\:")
place("PONG #{$irc_host} :#{a[1]}")
end

if i =~ /#{$irc_password_prompt}/ then
place("PRIVMSG #{$irc_nickserv} \:#{$irc_identify}")
end

if i =~ /#{$irc_password_accepted}/ && $joined == 0 then
place("JOIN #{$irc_channel}")
$joined = 1
end

parse(i)

end

$connect_log = ''
puts "Log Cleared\n\n"
end

This code fetches 512 bytes of data from the server and splits it into an array (separated by a carriage return). It then goes through each of these lines and checks if it is a PING from the server (at which point it will PONG the message back). This stops your bot getting booted from the server due to a PING timeout. It also checks if the password prompt has been given by the server, at which point it will send back the relevant identify message. If the server accepts the identify, then the bot will detect the accepted message and will join the channel you set in the config.rb.

Since a lot of servers have different messages for identify / password accepted, you may have to do a little investigating to find the right one. Luckily, the line “puts i” at the start of the for loop outputs the server message to the terminal, so you can see what messages are being sent, and change the config.rb variables accordingly.

At the end, it sends “i” through the function parse() (which is in the file parse.rb) and clears the log.

Step 5

Finally, create a file called “parse.rb” and open it in your favourite editor.

Add this code:

def parse(x)

# INITIALIZE VARIABLES
upmynick = $irc_nick
mynick = upmynick.downcase
nick = ""
chan = ""
fullmsg = ""
upfullmsg = ""
msg = ""
upmsg = ""

# SPLIT CODE UP
s = x.split("\:",3)
if s[1] =~ /!/ then
nick = s[1].split("!")[0]
end
if s[1] =~ /\ / then
chan = s[1].split("\ ")[2]
end
if s[2] != nil then
puts s[2]
fullmsg = s[2].downcase
upfullmsg = s[2]
end
if s[3] != nil then
puts s[3]
fullmsg = fullmsg + s[3].downcase
upfullmsg = upfullmsg + s[3]
end

fullmsg = fullmsg.strip
upfullmsg = upfullmsg.strip

# CHECK IF MESSAGE IS DIRECTED AT BOT
if upfullmsg =~ /^(#{upmynick}\:|#{$irc_prefix})(\ )*/ then
direct = true
upmsg = upfullmsg.split(/^(#{upmynick}\:|#{$irc_prefix})*/, 2)
upmsg = upmsg[2].strip
msg = upmsg.downcase.strip
else
upmsg = upfullmsg.strip
msg = fullmsg.strip
end
end

This is a very complex parsing function, but will be your starting point in creating your own custom commands. The local variables “upmynick” and “mynick” are set to the normal case bot nickname, and the lowercase bot nickname respectively. This can be very useful, as you will want to check regular expressions against the lowercase nick, but output messages with the normal case nick.

The parse function then splits the message “i” up into sections, and gets information from those sections. The local variables “nick” and “chan” are set to the obvious (the nickname of the user who sent the message, and the channel they sent it to). The variables “fullmsg” and “upfullmsg” are simply the entire message the user has sent, in lowercase and normal case.

Most IRC bots only respond to commands if they are told directly to the bot, so the next part is very useful unless you want to piss a load of people off. If the variable “upfullmsg” begins with the bot nickname (and a colon), or the bot prefix (usually &, %, ., etc), then we know that the user is telling the bot directly. A new variable “direct” is set to true, and two new variables are created (upmsg, and msg). These variables are very similar to upfullmsg and fullmsg, but they don’t have the bot nickname or prefix at the start.

So, if the “fullmsg” was “IRC_BOT: hello!”, and the IRC bot’s nickname was set to “IRC_BOT”, then msg and upmsg would now be set to “hello!”. This simply means that everytime you check the regex of a command, you don’t need to include regex to check if the bot’s nickname is being referred to. You only need to see if direct is true.

Step 6

The final stage of an IRC Bot is to add some functions to it. I’m going to show you how to make one simple function (get the bot to flip a coin) and how to add it to the parse function.

At the end of the parse.rb, before the last “end”, add the following code:

if direct == true && msg =~ /^(flip|coin)/ then
if rand(2) == 1 then
flip = "Heads"
else
flip = "Tails"
end
place("PRIVMSG #{chan} :#{flip}")
end

Simply explained, this code checks that the variable “direct” is true (i.e. the command is being told directly to the bot), and that the message sent begins with either the word “flip” or “coin”. If both these conditions are met, then the code generates a random number between 0 and 2. If the number is 1, then the outcome is “Heads”, if it is not, the outcome is “Tails”. Note that a the random number in ruby can never be the number you set in the rand() function. So the only two numbers ever outputted by rand(2) will be 0 and 1.

The bot then uses the place() function we defined earlier in bot.rb to send a message back to the channel with whatever the variable “flip” has been set to.

Finally…

To run your IRC bot, simply run bot.rb using ruby.

Thanks very much for reading my tutorial. Please comment on things you think could be explained in more detail, and if something makes no sense. If you are having loads of trouble doing anything, then please feel free to download the complete files from this tutorial here:

http://adrianhayter.com/ircbot.release.1.0.tar.gz

Popularity: 5% [?]

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • StumbleUpon
  • NewsVine
  • Slashdot
  • Netscape
  • Technorati
  • blogmarks
  • Spurl
  • YahooMyWeb
  • BlinkList
  • Reddit
  • TailRank
  • feedmelinks
  • Furl
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Login