What would you do?

Would you try and break open the local bank vault?
Here's just quick post in between.
I've been thinking about this a lot for the last couple of days/weeks. What would I do if suddenly everyone disappeared, I mean everyone. Would you shoot yourself? Would you rob the stores? Would you try to fly an airplane and head to warmer climates? Would you do the same thing, but by car?
What I would probably do, is take my parents car, and drive as far south as I can get, then refuel for free (nobody there to stop you from stealing petrol) and just keep on driving until I got somewhere warm. Then I would probably just chill out there for a while. But wouldn't this get boring (read: lonely)?
So, what would you do?
Popularity: 37% [?]
IRC Bot (part 2)
This lesson's goals
- Set up a MySQL database
- Check every message for incoming commands
- Update commands dynamically
Yes, that's quite a challenge. Unlike the previous tutorial, I'd call this an average tutorial. Not too hard, but not truly easy either. Full tutorial after the jump.
Good, so you decided to follow up from the previous tutorial and make it do what you want? The bot will be controlled through the IRC window itself by sending it different queries.
Let's start by laying out a work plan, things we want it to do:
- Add your own functions (!hai => Say something back; !slap => Slap someone, etc)
- Track user stats (Words per line, #of lines, #of words, avg. #of characters per word, etc.)
That's what we'll be covering this tutorial. We'll keep the functions and user data stored in a MySQL database.
Read more...
Popularity: 100% [?]
Using MySQL to select data from multiple tables (Using JOIN)
I got on the idea of writing a little post about this a while ago, but forgot about it. And just today I uncovered the note I had written to myself, to keep my promise to all of you, so here goes.
My situation was as follows: Imagine a store. Every product has a unique identification code (NASA-number), a product description and a price, to keep it very basic. Then, every product has a stock number (The amount of items currently in stock). We're keeping these values apart from eachother because keeping the amount of items in stock isn't enough. We also need to keep a log of everything that happens to the product (how many do we sell per day, how many are delivered to us, how much do we throw out).
So basically, we have two tables. One contains all product information, and the second keeps daily logs of what happens to each and every product. Let's give you a basic table layout:
CREATE TABLE `nasa` ( `nasa` INT(16) NOT NULL, `name` VARCHAR(255) NOT NULL, `price` FLOAT NOT NULL, `content` VARCHAR(255) NOT NULL, UNIQUE KEY `nasa` (`nasa`) );
This is the listing of the products, every single item has a unique NASA-number, names can overlap providing the content is different (think a litre of whole milk vs. a gallon of whole milk), than we have the log:
CREATE TABLE `history` ( `DAY` INT(16) NOT NULL, `nasa` INT(16) NOT NULL, `stock` INT(16) NOT NULL, `received` INT(16) NOT NULL, `sold` INT(16) NOT NULL, `counted` INT(16) NOT NULL );
So this one has a daily log. But if you want to display the data of these tables on your screen, you might be tempted to run two queries, one to fetch the name (for legibility, people aren't very likely to remember numbers), maybe the content and one to fetch the current stock (are we out? did we receive anything?). This would go as follows
SELECT name,content FROM nasa WHERE nasa=62334
and then
SELECT stock FROM history WHERE nasa=62334
What if you combined these two into a single query? First write down which things you need: name, content, sales and current stock. Then, lo and behold the power of the JOIN-statement.
SELECT name,content,stock,sold FROM nasa JOIN history ON nasa.nasa = history.nasa WHERE history.nasa = 62334 AND history.DAY = today
See that? You can just select the four columns you need. MySQL will retrieve any row where the history.nasa matches the nasa.nasa so be sure to specify which row you want to retrieve. In this case you could also order descending by the date and limit the rows retrieved to 1:
SELECT name,content,stock,sold FROM nasa JOIN history ON nasa.nasa = history.nasa WHERE history.nasa = 62334 ORDER BY history.DAY DESC LIMIT 1
Thanks for reading, hope it makes any sense :))
P.S. In case you were wondering, 62334 is an actual NASA number used in Albert Heijn. It's the code for fresh cod filet.
Popularity: 46% [?]
Topic ideas
Hey guys,
I'm still alive, and I've been thinking about some nice topics to cover on my website again. I actually got the idea to start creating posts again a few weeks ago when I got billed for my annual subscription fee. Ever since I've been thinking, there's plenty of ideas I have, but none that I can actually finish. For example:

Anti-theft stickers
I've been reading about RFID tags lately, and I'm using them at work (grocery store, the RFID tags sound the theft alarm), nothing complicated but they have me wondering. I was looking on thinkgeek.com and I've found a funny RFID starter kit - for 99$ (plus like 20$ shipping to the Netherlands) - which looked like fun, but to spend 120$ on something that just looks fun isn't really my way. Nevertheless it hasn't slipped my mind completely yet, it just looks like so much fun to have a credit-card with a RFID-tag in it and I can use that to log in to my computer, open my door amongst many, many other possibilities.
I have also been browsing through my drafts here at my website admin panel and I've seen a couple of topic titles that I'd like to finish such as Building your own eShop, IRC Bot (continued), Filtering functions (think phpBB code), MySQL tutorials (UNION statements, complex statements), variable pointers (&$var) and many others. Most of them already have part of a tutorial or explanation to them, but I just haven't had the time to finish them. Which usually is the case when I get stuck on something and I can't be bothered too much to figure it out in a crystal-clear way, that makes other people understand it.
Even mental mathematics have come to mind, which ways can you use to increase the speed and accuracy of your guesses, easy ways to do large multiplications and divisions, even working from left-to-right instead of right-to-left while adding up will increase your speed and allow you to speak out the answer while you're still calculating, even though it might sound unlogical. From simplification (don't do 29*11, but 29*10+29 (319)) to handy tricks for squares, cubes and even quads.
The issue hasn't been time, I've got plenty of that, but will. The will to write something is back, but now the issue is whether I understand fully what I'm writing. I don't want to give any of you the wrong ideas, make you do things in the wrong way just because I said so without thinking.
I hope this'll keep most of you tuned for now, I promise there'll be an update before friday.
Thanks for reading.
Popularity: 45% [?]
Recent comments!