Tuesday, January 24, 2012

Get HTML in C#

In many situations, I needed to fetch a simple HTML (or other type) document over the HTTP protocol in C#. So here is my final solution to the problem, that mostly will work!
Sometimes it'll give you a hard time, because some websites don't like the Header, but it's great to fetch "real" HTML from a simple server.


Usings:
 using System.Net;
using System.IO;

Code:
  String getHtml(String URL)
        {
            string result = "";
            try
            {
                // Get HTML data
                WebClient client = new WebClient();
                Stream data = client.OpenRead(URL);
                StreamReader reader = new StreamReader(data);
                string str = "";
                str = reader.ReadLine();

                while (str != null)
                {
                    result += str;
                    str = reader.ReadLine();
                }
                data.Close();
            }
            catch (WebException exp)
            {
               return exp.Message;
            }
            return result;
        }

Saturday, January 14, 2012

System engineering the life, the universe and everything!

ATTENTION: This post was written in a phase of general anger and disagreement with a normal person. If you consider yourself easy to be offended, maybe you shouldn't read the text below...

Hi!
As you might have experienced, it is quite easy to tell apart "nerds" from "normal people" by just comparing their sight on life, the universe and everything.
A simple explanation to the rather extremous views of some would be that they think too much about software and to less about real life, but in reality, nerds only use their knowledge on software and logic structures to understand their surroundings.
It might no be true for everyone, but the further you go into logic structures, the more likely you will recognize them in the real life. Many thing just demand you to think about them. Take for example the placement of a banana in a fridge. A normal person would just stuff it somewhere, where enough space is free, but I would place it in the highest point available, because too low temperatures would destroy the flavor of the fruit. What might be seen as an exaggerated and overcomplicated use of thermal physics (cold air goes downwards), is for people like me just a milisecond of thought. Also other situations in everyday life like conversation are handled like this. Why do I instantly have an opinion on mostly everything I get to know? Well, because I can't help but seeing it as a logic process.
Why do I hate DMTF tones? Because they are not in harmony.
Many people would think about this and come to the conclusion, that I see everything as a scientific problem, but that is not true.
I live my life as I do without feeling like solving equations and stuff.
I am able to do these thing without noticing and because I don't have to think about everything I do (it is done in the background and it does not take hours) I can live more satisfied than someone thinking about simple questions all the time.
This can sometimes lead to problems as some people aren't able to talk about other things than their limited problems.
I don't like complaining about what is existing. I like DOING CHANGE things.
Same thing applies to our politicians. Oh god, we have a decrease in tax income. Oh my god, our roads are getting broken. While a normal nerd would just come up with a soulition these people just keep on complaining.
Here in Germany, you can see nerds getting into politics and I'm sure you can see it in other places too, but politics is not enough. We need to convince other people to stop coplaining and start DOING.
If you come to the conclusion, that there is a problem with your life, then get solving it and don't waste time complaining.
That is the reason, why we act differently!

Saturday, January 7, 2012

Laser pointers and video games

Hi again,
in the last week i had a couple of interesting discussions about laser pointers. Since most of these discussions were with video game fans, this is what this post will be about.
In many first person shooters, you are able to mount a laser pointer on your weapon. They then create a red beam of light which helps you aim.
Now one game that allows this is the FPS Crysis. A youtube walkthrougher named Majorslackvideos (if you like video games, be sure to check out his channel) mentioned, that in real life, enemies would be able to see your laser pointer. That is true for real life red laser pointers, but these would be incredibly hard to see, since they do not create a beam in the air at such low power. Anyway, you could use them with a scope to get a red dot like sight.
Then he mentioned infrared and this is in fact a way to get a game-like laser pointer. Infrared light is invisible to the human eye (or can you see your tv remote), but extremely bright to night vision devices since they rely on the infrared radiation of the environment as image source.
In Crysis, you play a supersoldier with a highly developed nanosuit and one of the implemented features is in fact a night vision device.
With a infrared laser, you would create a very bright point on the image. Now use modern image
processing techniques and overlay the brightest point on the image with the live-action feed. Voila, you've got a laser pointer thats only visible to you and night vision viewers. If you mount a second bright IR light source on your weapon and now draw a line between the two brightest points then you get exactly the look and feel from the game.
So why did we talk about this?
Well, using the laser pointer gives perfect aim to every weapon in the game and this is not fair.
So for future use, we agreed on only using the laser pointer in Nightvision mode, which decreases the level of detail you are able to see. A highly scientific experiment later, we were quite happy with this solution. Now we only need to write a mod that auto-switches to night-vision mode, if you use the laser pointer.
I hoped you liked this post.
Apexys