I’ve been working on a quiz section for one of my websites lately, well tried to anyway. One of the dumbest things happened. In a quiz you want to randomly pick questions and serve them to the visitor. That way they can answer them and shout WAHOO once they have one right.
Problem I had was that I couldn’t figure out how to sort all the questions in a completely random order, well semi random any way (since a computer does not know random as we do). I tried to do this by first counting the number of rows in the table and then creating a random array with 0..x (x being the number of rows). But this is very inefficient.
It requires two calls to the database for every visitor. One to get the number of rows and another to get the actual question. To most of you this might not seem like a problem, but try counting a few million rows. My second approach was already a bit better. I used the following statement:
SELECT * FROM QUESTION ORDER BY RAND();
It’s a lot better as it only requires one call to the database to retrieve all the questions for the visitor. The ‘ORDER BY RAND()’ part makes sure that the rows are sorted in a random order.
Note that I stated it is better, but far from perfect. Every time the same visitor hits a page this query will be executed, which defeats its purpose. So the next step is to cache all the query results for the visitors, which is a step I still have to make.
As some of you may have heard Microsoft is trying to obtain a patent on receiving and searching RSS feeds. Is this going to ruin RSS as a feature. Or have they got something else in the working for the standard.
Let’s first explain what the patent request is all about. They are requesting a patent on the technique of displaying RSS feeds and searching in RSS feeds. If the patent is accepted it will mean all producers of RSS readers will have to pay royalty fees to Microsoft for using the technique described in the patent.
So if the patent is granted it will reduce the effectiveness and usefulness of RSS for web developers like me. What use is it to provide a RSS feed if everyone that wants to use it has to pay Microsoft for reading it. That’s not why I’m providing RSS for you guys.
Let me hear your thoughts on this…
I’ve been using Google Sitemaps for a while to keep track of how my site is doing. Not in rankings, but in crawlabillity and errors. For the past month I haven’t had to much time to watch the stats on the Sitemaps website. But today I did. And to my suprise they improved it.
I think some of the best improvements I noticed were:
Now there are still somethings that could be improved. Like the fact it keeps reporting a broken page on my website, but fails to tell me which one.
All software developers have to deal with it. Version control software. Today I decided to play a bit with installing my own dedicated SVN (subversion) server. This, hopefully brief, step plan will help you do the same :).
Downloading all needed software
Before you can continue with the tutorial you will have to get the following things:
That’s all you will need. But be aware that we will be downloading various other packages (software applications) later on. So make sure you have your network prepared.
Installing Debian
Since I’m a complete newbie with Linux I just accepted all of the default settings. Which is fine for most people, but don’t do this for a company SVN server. It’s not really secure ;).
Setting up subversion on your server
You will need to login as root on the just installed Debian server. If you are set then it’s time to download some additional software. Just run the following commands:
apt-get update
apt-get install subversion
apt-get install libapache2-svn
If Debian starts asking you questions just answer them with ‘Y’, mostly it will confirm if you want to install the packages. After this step you’ve just installed SVN on your server. Easy isn’t it :D.
Setting up the svn root
The next step is creating the svn root, which basically is the location were all your files will be stored. What I usually do is create a directory in the /home directory. But it’s your server so create it wherever you want to.
mkdir /home/svnroot
svnadmin create –fs-type fsfs /home/svnroot/project_worms
svnadmin create –fs-type fsfs /home/svnroot/project_cats
As you see I created two different svn root’s. Most people love to create one for each project or each department. But do whatever you like.
Creating users for subversion
To be able to use subversion you need to give people access to it. So the next thing we will be doing is setting up some user accounts and a user group for subversion. You can do this by executing the following commands.
groupadd subversion
adduser bob -g subversion -p bobpass
adduser dylan -g subversion -p dylanpass
The first commando creates the group we will be using. The next two commando’s create a user. By using ‘-g’ you can set the group the user belongs to. With ‘-p’ you can set the password.
Now you can continue with setting up secure access to you SVN, but as I said before I’m just installing a private server so I don’t need it.
Confirming subversion is working
To make sure everything is working you can execute the following commando’s. The first will verify SVN is working the other two that the integration with Apache is working properly.
svnlook tree /home/svnroot/project_cats
a2enmod dav
a2enmod dav_svn
Preparing password protected access
In this step we will set up the protected access through Apache. This is done so we can access the svn root on other computers, which is the point :). Run the following commands to create a password file that we use to limit access.
htpasswd2 -c /etc/apache2/dav_svn.passwd bob
htpasswd2 /etc/apache2/dav_svn.passwd dylan
You can add as many users as you want, but keep it maintainable. The next step is creating a file to set up the access through Apache. But before I give you that let’s explain some basics of vi, which is the text editor you’ll be using.
To browse through a file you can use the arrow keys on you keyboard. To start editing you can either press i or a both enable the edit mode. The first is insert and will push the text after the cursor back. The latter is append and will make the typed text appear after the selected text. To leave edit mode press esc. To remove an entire line press dd. For a complete list view http://www.chem.brown.edu/instructions/vi.html
Now open the file /etc/apache2/mods-available/dav_svn.conf and put the following text in it.
<Location /svn/cats>
DAV svn
SVNPath /home/svnroot/project_cats
AuthType Basic
AuthName “Subversion Authentication - Project Cats”
AuthUserFile /etc/apache2/dav_svn.passwd
Require valid-user
</Location>
What these few lines do is simple. It creates an alias on http://localhost/svn/cats and maps it to the previously created svn root. The AuthType, AuthUserFile combination enables simple password protection for the folder.
Warning: You should create just as many entries in this file as you have svn roots, which you created a few steps earlier.
Now you need to complete the installation by restarting Apache. This will apply all changes we’ve just made. Just run the following command:
/etc/init.d/apache2 restart
Optional: Setting a fixed IP
The last step of this tutorial is optional. Since this is a server you may want to set it up with a static IP address instead of a DHCP one. To do that edit the file /etc/network/interfaces.
It should have at least one entry named iface eth0 inet dhcp. You need to change that to the following:
iface eth0 inet static
address 192.168.12.2
netmask 255.255.255.0
gateway 192.168.12.1
Now if you’re not familier with the network your SVN server will be in ask the network administrator what the settings should be. But generally speaking you can use the ones I just gave, except for the gateway. Set this to your routers IP address.
The next article I will post will be on how to install Trac, which will help you manage your SVN projects. But that’s for a later time.
Most people will know about the fake PayPal e-mail spreading across the web. Sent by people trying to gain access to the PayPal accounts of innocent and ignorant consumers. When hitting the link in the e-mail the consumer is taken to a fake PayPal website where they give away their username and password. That’s a classic example of phishing.
You might think that you as a company will never have to deal with any such problems. But you are wrong. If you are making money online, then your company may become victim to these type of scams sooner or later.
I hear you think that it’s not important. But realize that when ISP get wind of the fact that e-mail scams are going around for your company they may decide to block you. And what’s the use of you e-commerce if you can’t mail your users. Not to mention the risk of your customers actually falling for the scam and getting ripped off.
If you are victim of phishing then you should always take the following steps:
A final word: keep track of all e-mails that are sent in your name. You may just prevent phishing or other scams against your users.