Saturday, July 7, 2007

A Smarter rm for Mac users

Hmm, today I had a nice experience. I wanted to remove two files; httpd and httpd.tar. The former being a directory.

Did a rm -r httpd *

Went away, then returned, panicked, seeing that the space between the httpd and *.

Well, there went a good part of my documents. The important things I tend to replicate everywhere, but now I'm hunting lego manuals. From this experience came out a nice little script for all my fellow OS X users. All OS X users, who, like me, don't want to say "y" to every file during an rm.

First, open your .profile and add in the following line:

alias rm '~/rm-trash'

Second, open the terminal and type the following:

$ touch rm-trash

$ chmod 755 rm-trash

open the empty rm-trash file in your favorite editor, and type up the following:


#!/bin/bash

if [ "$#" -eq "0" ]; then
echo "No files specified for deletion."
else
for i in $*
do
echo "Trashing: $i"
mv "$i" ~/.Trash
done
fi


There, my little magic script to forward my rm's to the trash; so from the command line, if I make a mistake, it's not as fatal. I can still get my files back. And if I didn't make a mistake? Just open the apple menu, and do an empty trash.

Just call it like:

$ rm "Some Folder" "Some File"

No need the -r, or things like that. But you need quotes. Bash handles wild-cards, so:

$ rm "Some*"

would remove both files "Some Folder" and "Some File". Put in the quotes! Or else bash may treat the sections of the file name divided by spaces as different parameters.

This should work for Gnome/KDE users as well - I believe that a folder is used for the trash as well.

Monday, March 5, 2007

About a Girl

That student, I tell you, he had his heart in the wrong place. A lonely person he was, living in solitude, using his imagination to create false memories of friendship. A university student, praised for his good grades, work ethic, and lack of social skills. Work is his life, and his life is for work.

But that must end, today. In class, the prettiest girl enters the room. If he can be the top of the class, why can't he just get the top in the social world? A simple proposition, he blushed at the thought; how hard could it be to converse, to small-talk. If he could climb the ranks of the ivory tower, why not the social ladder?

He got up, looking at the eyes, looking at him. He was now in the spotlight, and ascended the stairs of the auditorium to where she was settling her books. What looked like physical perfection. He approached her; his heart gave a leap.

He looked at her, unknowing how to start a conversation. She noticed quiker than he could react; which made him run down the aisle back to his seat. His heart sinking with the silent laughter of the other students. What was he to say? Why was it so hard? He failed. If life were a game, he'd probably score the lowest grade - no small-talk, no informal conversation, just a mind to get ahead.

He had excelled in the academic world through so much effort, that he no longer had time to socialize. Had his mind be more mature, he would have befriended people instead of going for the ultimate goal in one jump. He would have choosen based on personality, not on the perfection of the exterior of the meat popsicle before him.

Friday, March 2, 2007

Mass Production

Joseph looked out the window of his second floor office, happily watching people loading what his company manufactured into the truck. Ants, efficiently transporting goods, to be distributed to warehouses, then to consumers.

He peered out of his office towards his production staff, grateful of all the work that they had done for him; satisfying a multitudes of clients. They appreciated him, or so he hoped, for the job and money. But they, like him, are temporal beings. As was this building, the products on the crate outside, even the dramas currently being lived through the interactions of peoples. All worthless, to be forgotten to make place for the memory of the various media idols.

His factory, like the human population, was producting at record rates. His factory created a useful product, humans created humans. A new generation to surpass the old. But was it good to look at the human race as another result of mass production? Did it overly reduce people to just another component of a greater organism. Each company an orgasnism with people as cells.

A person, another completely replaceable part in the whole. That is, except for a few, special, that should be properly choosen. Joseph knows that he's not important enough to be remembered; but is the mass-produced population looking towards the right people?

Why was he bothering about this? He knows his place, he does what he has to do, returns to his desk, and prepares for the iteration of product specification, production, and release.

Monday, February 26, 2007

My Little World

Listen, my friend, I do not wish to give you directions, neither do I wish to help you. We may seemingly both be standing in this super-market, seemingly both buying our supplies for nourishment. But do not be fooled, I am not from here.

How can you see me if I'm not from here? Why do I grace you with my presence? I suppose that it is a valid question. And I will respond with a simple question: deep down in your heart, do you really want to live in this world?

I was like you, some time ago. Brought up in a world of magic, just for the magic to disappear and be replaced by this land filled with scheming corruption. Anything for an extra buck. I saw medical doctors go on strike ignoring their patients, public service people unhappy with their pay block roads, having rulers who were probably as trust-worthy as a shadowy figure luring a child with candy. Is this the world you want to live in?

I bid you good day, my friend. Our worlds maybe crossed this one day; but they shall not again. I desire a different world, and that is where I'll be, no matter in what situation my physical representation manifests itself.

Sunday, February 18, 2007

Projects, projects, projects...

Are you like me? You want to do so much that nothing really gets done until completion? I want to finish the old, but the latest and greatest is just tempting me.

My first project to actually graduate away from this is "GameLib" (yes, I'll probably end up uploading it a year later, but I'm proud, it's a code base that works). But it's supporting applications could use a bit of work, sadly enough. On the bright side, it's a project, it's over a year old :).

Last month I had to bury "AfterLife", a little story that I was working on. Sort of sad, really. I really wanted to evolve it, to develop it. However, the social structure that I had to enforce for the scenario to work, sort of worked against the scenario. Also, the characters needed quite a bit more development. And the story had no point.

Next, is "Metaphysics". The characters are much better defined. I still have to introduce myself to them; but I know who they are, how they are related to each other. This project, opposed to the previous, has much greater focus on relations among characters rather than a complex underlying world, a world that I wanted to live in, but my mind never went. "Metaphysics", being much simpler, is much easier to grasp, for me to enter the world, it's a story at my level. Various sketches were done; and for a personal project, it's advancing quite smoothly. I will post the first chapter once it's ready; and the sketches will wait until the relevant portions of the storyline is determined -- which is what I fear.

"AfterLife" also suffered from a very bland story-line. Nothing happened after a dozen pages of text. Characters were introduced, things happened, but all in all, no one ended up needing to save the world, there was no suspense. It's as though I documented Mr. Joe Average perfectly normal life (well, as normal as possible given the circumstances in the story). Also, after a certain while, the story just "ended" -- what was I trying to say; where was this going?

"Metaphysics" might be much better defined, but it really lacks in the story department. I'm working from the top-down, and am planning playing with the relations between groups of characters to cause chaos. However, who knows how that will pan out. Will it even work? Will the reader be interested? Will this sound like some stories where the author seems to be inventing things in order to make the story progress within practically every chapter? I hope this is a success.

The other project is my city in SimCity -- this is an easy project. Yet, I always tend to destroy my cities. Again, a bit of perseverence is key. There is a large demand for residential, however the residential zones haven't completely built up, or are complaining about transportation woes. From experience, I can expand the city 10-fold it's size, but still have transportation problems; hence time to attack the heart of the problem, and get those sims from point A to point B.

Friday, February 16, 2007

Illegal Copying

This just came to mind. At what point is something considered copying? While watching a DVD on the computer, I wondered how I'd implement the DVD player software -- assuming it weren't encrypted -- which would be quite fun one day. Well, I'd open the files on the DVD, copy data to memory, decompress the data, and stream the results to the audio device and video-card.

Now; here's the fun part. Copy. Yes, to watch a movie, all of the content is copied onto the machine. And written on the disc is "Do not copy"... Hmm, and to say I'm sure that all DVD players do something similar (especially if they are buffering parts ahead in case of future seek problems).

If you can see it, it was copied into a memory buffer somewhere. With HDMI, the decompressed video data will probably be on the monitor itself; but it's still a perfect copy.

Like unprintable and unsavable PDFs, a copy of the PDF resides in memory on the local machine (it'd be stupid not to). Hence, anything viewed on the web is already copied to the local machine. Anything viewed on the web is downloaded (even streamed data; no matter what hoops someone has to jump, it still gets decompressed somewhere in memory to be sent to the video-card's memory).

The moral of this story, to play or watch a movie implies that it is copied. "No Illegal Copying" would be a better phrase (and that is what should be assumed they meant) - however that would reveal to everyone that there is such a thing as legal copying. They could say "no copying for more than 3 seconds at a time" (for those of us with extremely huge buffers), but could just seem as confusing.

Or they could do like they did with my "Rise of Nations" and "SimCity" discs. Include a nice blurb like "If you think these discs are illegal, contact Microsoft", or just don't mention it. (It's all detailed in the EULA anyhow...). I only wish I could read the EULA before buying the product (aka, in store, and before popping in the disc; some games like HL2 I would have liked to have a different EULA - it was one where some clauses I wanted to refuse; but what store accepts returns on opened software?).

Tuesday, January 30, 2007

Passports

All hail, a new dumping ground for thoughts beyond of "Random". Now there's "Life", something that hails more of a questioning of modern relics. Passports, currency, government, etc. being of these things to be questioned of their efficaciousness. It is intended to go deep into the roots of what we are, but, being completely ignorant of all the philosophical thought that has come before it... Enjoy!

Also, notice the added links!

To begin, let's define the purpose of a passport. It's used as a document to determine if a person can enter a country or not. Sort of like Country A trusts Country B, so they let their accountable citizens travel. How do we decide which citizens? Use the top tier and have them sign off on the authenticity and integrity of the person.

Let's take three small communities (A,B, and C) for example. C's people are completely untrustworthy; or so speculation goes, so no-one from C can enter A or B. A or B trust each other, and people wish to travel, but to leave a good impression, only a select few can travel.

If A, B, and C are small communities, each consisting of about 20 people. Under such circumstances, people from the community know exactly know should come and go. It's small, and can manage itself.

Let's bring the population up to maybe about 100 each. There will some bad apples in all 3 communities. C currently is being punished for no reason. A and B interchange people, but they now need guards to ensure that only those that are allowed travel. Still, it's a small community, and guarding the borders is relatively trivial.

Population boom, 10 000 people in each community. There are troubled people in each community. C is still being unfairly punished. A and B still interchange people, but having a few guards managing the borders is no longer reasonable -- the population is so big that it now needs police to keep the calm. As well as people outside verifying the borders.

Why verify the borders? so no evil comes in. But why? there are equal numbers of trouble-makers in A, B, and C. Each has their own police force. Only thing that they are attempting to stop is the spread of the crime; which is still leaking through the borders. Those that want to circumvent the system will manage; unless if easily rooted out by the nation.

In our non-fictitious world, people are just re-exported to where they came from.

The idea of the passport is good: guarantee that people going to another country originate from somewhere, and that they are somewhat screened. The downside: are countries too big to issue such control? The populations are massive; people no longer have to escape their community to reach anonymity. It's in the looming office building on the other side of the street.

Build a wall? Go right ahead; tunnels will be built, people adapt. And how can you be 100% sure that someone has not fooled the system.

Building a new electronic system? will people care about it? will all employers care?

Passports, like government, are an opt-in process. People can make a big fuss out of them and follow their every indication, or just do as though they mean nothing. Traffic ticket? It's your taxes that go to paying those officers that give out tickets. Income tax? It's just an agreement between enough people that it must be done: if 100% of the people disagreed, an no-one filed it one year, the government could yell and scream all it wanted, whine, complain, but theres no way it could imprison everyone at once.

Right now, we are opting in for passports. Well, governments (which we keep well funded) opted in for passports.

Are passports a good idea? of course; but at their current scale, they probably are somewhat of a joke (in the west that is).

Am I suggesting that everyone revolt against what they don't like about the government? Be careful of your decisions. It has to be practically unanimously agreed upon. 50% doesn't cut it (more than 50% take part in file-sharing, and under that logic it would become legal). Will people break under the pressure of the "leader"? (the ones we pay to lead the country are quite powerful, and have access to the military to make the population comply, no? - unless the military is against the government; which you have another issue at hand). So, the quick answer is no.

Is this an over-simplified version of things? of course; it's just here to make you think -- it has opened doors of thought in my mind as well. Excellent for creative writing.

Sunday, January 21, 2007

Vegetarian?

Here's some food for thought. Notice that foods, previously made without peanuts, still had traces of peanuts in them (from being manufactured with foods made with other nuts). Now that allergies are a big thing; we're aware of this -- next thing will probably making vegetarians aware of exactly what traces of animal could be in their food.

Or, is this overly paranoid? Some just put the extra labels to not be blamed if ever an alergic reaction were to occur.

Saturday, January 13, 2007

Self Filtering vs. Objectivity

I'm probably one of the few people to complain about this, since it probably is so rampant. But I have an issue with white lies, and skewed objectivity. It's taken me about 20 years just to read the implicit hits from my parents to know what they actually think, and it's annoying. They complain of the facades that they're parents wear, unaware of their own facades.

Now that the angry-man's rant is over, let's get on to the meat of the subject. Is it best to try to make someone feel better, or be completely objective and always tell them what you think.

I'm pro objectivity. For one simple reason, it may hurt the person at first, but they'll be stronger because of it. They're head won't be as swelled afterwards. Before College, I never had any subjective impression on how I draw, and thought I was good. Now, I can better evaluate what I can do, now I know what to look for. If I had a bit more subjectivity in the critiques, I probably would have been better.

However, I can't deny the uses of filtering, lying to encourage someone to keep on going. Parents, must, by nature, see good in their children, be biased towards what they do. Why? learning anything needs time, and if my parents were blunt, then they would have always said that it could be better; that some of it was crap. Faced with such criticism in any field, it would be impossible to believe that I was good at anything.

In the end I became a software developer... why? video-games, and since the computer provided a means of escape, and QBasic seemed to offer all the escape I needed. Want to see the family dog succeed at a level eerily similar to super-mario bros? Code it! Want to be in a star-trek away mission? Code it! Want to fly a plane? Code it! And the list went on. As I wanted something, just coding it would do. If I didn't feel like coding, I'd meditate in front of the blue screen.

Then College came, and with objectivity entering my means of escape, I was opened to new worlds. Those included OpenGL, DirectX, Photoshop, etc. New worlds opened, possibilities emerged.

Now I'm a University student. I know that I learned the most in my beginning College years, and feel as dumb as ever. Up until now, my greatest mistake was to not know myself. To just let things flow.

Now, I'm starting to know myself. The reasons for the ways I am can be traced back to what I don't like about my parents. Things which sound stupid, which I must correct. Self-examination has made me a better person. I now know that the pessimist in my classes was a realist, and knew what he was talking about. I now know why my best friend seemed to have drifted away.

And from knowing myself, I can tell when people are annoyed since they do exactly what I'd do, try to shake them off.

Oi, and to say this blog was supposed to be a test of being able to remain on a subject, and coherently follow an arguement, yet again I followed my heart.

All this to say, if you're reading this, the filtering will make you feel good, but don't dwell on it. Relive life through every moment you can. Turn down the stereo, put yourself in the other's shoes, figure out how you can improve yourself. That is more important than what celebrity is getting a divorce, it gives you a barometer to how you affect people, and how you can leave a more positive impression.

The past defines the present. The present will determine your future. If you can't tap into the past to exploit it's resources, there is no way you can hope to greatly improve the future.

Friday, January 12, 2007

Collision Detection as Rasterization

The easiest method to collide objects takes n factorial time. That is, compare each and every object with each other.

Now, the smarter methods involve using quad-trees, arrays, graphs -- essentially any method to minimize the search path given a region.

Let's assume the following:
  • Memory is cheap
  • Small world
  • Looks right preferred over perfection


Given that, let's work on the 2D problem (some games can be represented as 2D problems in a 3D environment -- for example, if the number of objects to collide on the y-axis is little, and the level spans quite a distance on the x & z axis). And, we'll use this example. Let us assume that we have access to a big array, about 1024x1024 which can be used to represent a view of the world from the top.

Each element of the array can be thought of as a pointer to a sprite object. All that we have to do is then "render" the level onto this bitmap of pointers. It'll tell us exactly what object is colliding with which other object. I'm currently using this in one of my games since some sprites have very odd/ever changing shapes. Also, this must not be a new/clever technique since other games have over-sized morphing objects.

But, here comes the interesting part: we have hardware to do rasterization. If we only had 4 objects, we could assign each object to a specific element (RGBA) and render the scene from above without the land/useless detail. Any time a pixel is shared between two objects, then it could be used to raise a red flag. The more clever may want to use the individual bits (but since everything is done in floating-point, I'm not sure how exact the colors 1,2,4,... are when normalized. Also, the other problem is that the bitmap has to be brought back to the host -- which uses quite a bit of bandwidth.

On the other hand, rasterizing on the CPU takes away time that would normally be used for AI/other game logic.

For those who want the most speed, they should read the articles on quad-trees, etc. in Game Programming Gems. These provide smarter/proven ways of doing collision detection than this little rant.

Monday, January 8, 2007

A few notes about GameLib

Well, the time to post GameLib is getting closer. I've been keeping a little SVN database on my local machine to keep track of it. Once commit #7 (this is after a years worth of coding) is done, the system will have a very mature implementation for matrices (now it's quite basic), and have it's own entry-point (the current one is platform-dependant).

What does GameLib look like in code? It's OOP design was partly inspired with DirectX compatibility in mind (that I wouldn't have to do too many hacks to port it). Well, let's say it has the following interfaces/objects (and more):

  • Object - handles reference counting/allocation tree

  • IString - handles static strings

  • I3D_Device - access to state of currently-rendering-to 3D device. Also allows creation of sub-objects from device.

  • ILight - A light, allocated from the device

  • ITexture - A texture,

  • IGPUDataPool - Use this to prevent loading the same image twice into memory (retains pooled objects with weak references)

  • IVertexBuffer - Used for holding everything that is needed to describe a mesh

  • IInputDevice - Used for getting input from a game-pad, etc.

  • IState - Used with the finite-state machine (game is loaded up in a state).



I'm still wondering about initialization; but will code it as follows (since booting up the system is getting more complex every day). Right now, I'm debating whether having a struct be filled, or having an object that can be queried and can return errors.

Also, the exceptions are used only in cases of extreme failure, and should not be used to manage program state (once the library gets out).

And for the license, do I have to pre-pend it to the start of each file? If so, then that'll take a bit more time before the first upload.

All this, to say that it exists, I've spent a year or so on it, but I just haven't gotten to uploading it yet.

Friday, January 5, 2007

Pattern Recognition

Working on an assignment, recalling some information in articles from MIT on Face Recognition, something about the uncanny nature of humans being able to memorize and recognize millions of faces. This has given me a few questions; as if we were to take various cats that look the same to us and see if the computer could find differences between them visually (not behaviourally).

Back to the topic of the uncanny ability to recognize faces; then I recall the idea of the "creative interlocutor" -- something that another teacher probably put a bit more emphasis on. More or less the importance that we put creating associations among various items.

We compare color.
We compare shape.
We compare smells.
We compare sounds.

If we see something with a wooden texture, then we don't expect a clanging sound when knocking on it; something that could happen if someone were to paint the texture on a piece of metal.

We auto-associate unrelated items based on previous experience.

For example, a few weeks ago the Jewish community was attacked by the community at large for a frivolous event. It was massive mis-associations. Like what's happening to people in the middle east. Massive mis-associations based on previous knowledge. Our minds are wonderful things, but we have to keep it in check from extrapolating what is false.

Noise might just as well be noise, and not a pattern to apply to the whole.