Wolfram Alpha

September 24th, 2009

After doing some school work, I was browsing through a dutch website about math (www.wiskundemeisjes.nl), and in one of the comments linked a site called Wolfram|Alpha... This is the best search engine EVER.
Or, not so much a search engine.. It's a knowledge engine. It can solve almost all your math problems, you can ask it how many days seconds years have passed since your birthday.. Who was born on that day... Or check how much 5 mol of silver nitrate is!
Just check it out:

www.wolframalpha.com

Popularity: 4% [?]

Featured

Left 4 Dead

April 6th, 2009

Great game, this is..

Popularity: 32% [?]

Video Games

What would you do?

March 30th, 2009
Would you try break open the local bank vault?

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: 36% [?]

Miscellaneous

IRC Bot (part 2)

March 28th, 2009

Part 1

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% [?]

PHP, Tutorials

Using MySQL to select data from multiple tables (Using JOIN)

March 24th, 2009

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: 42% [?]

Web development