Virus Quote – Final Thoughts

I’m still unsure if a virus should be considered life. But for the sake of argument, let’s say it is. If that’s the case, then I’d have to disagree with Hawking about humans creating purely destructive life. Let’s consider the traits of a virus. Once injected into its environment, it searches out for it’s target and does its job – whether it be to change the wallpaper or to crash the network of an enterprise. Most of the time virus spread from computer to computer spreading the havoc. All will agree that this malicious act is purely destructive.

But this is not that different from another “life form” that roams the network, jumping from server to server to complete its mission. Yet this entity is integral to something we do every day. I’m referring to the spiders ,or bots, that index the the millions of websites. Without them, where would Google and Yahoo be. Heck, where would the internet be? Once again I think all will agree that the information age would be very different had it not been for these spiders.

Viruses and spiders, though their payloads may differ, their “instinctual” characteristics are the same. It is to spread was wide as possible. So if indeed humans have created life in the form of code, then Hawking is true in saying that it has been created in our own image. I just don’t believe we are as dark as he believes.

Virus Quote

Here’s an interesting quote from Stephen Hawking.

“I think computer viruses should count as life. I think it says something about human nature that the only form of life we have created so far is purely destructive. We’ve created life in our own image.”

Whether I agree or not is still up in the air.

Dynamically create gradient image

The code below dynamically creates a jpeg with a gradient, saves it to the server, and is assigned to an image object. I used the code below to dynamically generate a bar graph. The reason we append the uniqueVal to the file name is so that if the user is constantly refreshing the graph, the browser won’t pull up a cached image.

using System.Drawing.Imaging;
using System.Drawing.Drawing2D;
using System.Drawing;

string uniqueVal = DateTime.Now.Ticks.ToString();
Bitmap bitmap = new Bitmap(180, 15);
Graphics graphics = Graphics.FromImage(bitmap);
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0,0,180,15), Color.Gainsboro, Color.Blue, 45.0f, false);
graphics.FillRectangle(brush, new Rectangle(0, 0, 180, 15));
string fileName = "gradient" + uniqueVal + ".jpg";
bitmap.Save(Server.MapPath(fileName), ImageFormat.Jpeg);
graphics.Dispose();
bitmap.Dispose();
System.Web.UI.WebControls.Image img = new System.Web.UI.WebControls.Image();
img.ImageUrl = Server.MapPath(fileName);

Post data to server and capture response

If you want to post information to a server, capture it and manipulate it, use the code below. If you only want to get the server response for a particular url, click capture url response.

using System.Net;
using System.Text;
using System.IO;

private void OnPostInfoClick(object sender, System.EventArgs e)
{
string strId = UserId_TextBox.Text;
string strName = Name_TextBox.Text;

ASCIIEncoding encoding=new ASCIIEncoding();
string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

// Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Default.aspx");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream=myRequest.GetRequestStream();
// Send the data.
newStream.Write(data,0,data.Length);
newStream.Close();

//Get the response
HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse();
string result = new StreamReader(response.GetResponseStream()).ReadToEnd();
HttpStatusCode status = response.StatusCode;
}

Capture response from server

If you need to get the response from a server without displaying it on the browser, use the HttpWebRequest and HttpWebResponse classes. Sample code is below. If you want to post data and capture the response, click
post data to server and capture response.

StringBuilder str = new StringBuilder();
byte[] buffer = new byte[8000];

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(
"http://www.siteurl.com"
);

HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Stream stream = response.GetResponseStream();

string temp = null;
int count = 0;

do
{
count = stream.Read(buffer, 0, buffer.Length);
if(count != 0)
{
temp = Encoding.ASCII.GetString(buffer, 0, count);
str.Append(temp);
}
}
while(count > 0);

Another attempt

Well here I go again. I’m going to give another shot at blogging. Partly because I need to record all my discoveries as I go through my path of code self-awareness, partly because I hear bleeding one’s thoughts is therapeutic. You can say my previous attempt at blogging failed miserably. I’ve had an account at Blogspot for a few years and managed to output 3 entries. The main reason is lack of time/commitment. But as WordPress as my new home, things will be different, right? Of course.

In any case just as an FYI to those that may have stumbled into my lovely abode, the next 3 entries will be transfers from my Blogspot account. Apologies for the lack of depth of these post.

Ahhhh…a new day dawns.