Sunday, November 6, 2011

Microsoft's 1999 Homepage. Disingenuous Much?

Check out Microsoft's homepage from 1999 and Bill Gate's apparent concern with privacy and security. lol. The veritable orgy of ball-dropping since then defies belief but back then using the right business "e-speak" was all you needed to convince people you had things under control.

See also the link to the propaganda piece entitled "Microsoft and the freedom to innovate" along with the gavel symbolizing the DoJ's oppression. Freedom to innovate seemingly meant Windows ME, ActiveX, a web browser that was essentially an open telnet server. This of course was around the time Microsoft was being dragged through the courts in the US for being an anti-competitive monopoly. They eventually settled with the DoJ by offering to give free software licenses to schools and certain  non-profits, thereby further increasing their market share. Go figure.


Asp.Net Session variable not set on Redirect()

In Asp.Net, when you want to set a Session variable then immediately do a Response.Redirect(), the Session variable gets lost, like it was never set. Asp.Net has an overloaded version of  Response.Redirect() that, as well as a destination URL, it takes a bool that tells Asp.Net whether to end the thread or not.

By default, calling Response.Redirect(string Url) will terminate the response thread, meaning your session variable will not get set, only the redirect header gets sent to the client. Use something like this instead.

{
Session["somevariable"] = "some value";
Redirect("http://whatever..", false);
.
.
//Rest of code gets executed
.
.
}

C# Image Watermark (Overlay) Example

It's often a good idea to stamp your own photos or images with your mark when distributing on the internet to discourage people from claiming them as their own work, or in case they just forget image attribution.

NOTE: This is an over simplified piece of code and is missing some functionality like
  • Image resolution syncing (ensuring base and watermark images have the same dpi). Otherwise the watermark could end up being stretched compared to it's native view.
  • Boundary checking (check that watermark is totally inside the base image).
  • Watermark transparency. A fully opaque watermark can distract from the content of the base image, or just look ugly. Transparency blends the watermark into the base image creating a nice effect.
  • Rounded watermark corners. Rounded corners are cool right so yeah gotta have them too.
A more comprehensive class to achieve these is available in my open source C# library BFLib hosted at Google Code: http://code.google.com/p/bflib/

Here is the simple piece of code that overlays one image on top of another:

//_baseImage is the photograph/image you want to put a watermark on
Bitmap _baseImage = new Bitmap("c:\myphoto.jpg");
//_stickerImage is ususally a small image with your logo or name.
Bitmap _watermarkImage = new Bitmap("c:\mystamp.jpg");

//Draw the watermark offset 10 pixels from the left and 10 pixels from the top of the base image.
Graphics canvas = Graphics.FromImage(_baseImage);
canvas.DrawImage(_watermarkImage,
new Rectangle(10, 10,
_watermarkImage.Width, _watermarkImage.Height),
0,
0,
_watermarkImage.Width,
_watermarkImage.Height,
GraphicsUnit.Pixel);

canvas.Save();
_baseImage.Save("c:\watermarked.jpg");


Saturday, November 5, 2011

Google Chrome extensions - deal breaker dialog

Recently I've been looking at installing some Google Chrome extensions to speed up certain tasks. Browsing through the extension repository or "Chrome Web Store" I found that the extensions are divided into 2 types. The first is a bookmark type, that just add a link to your new blank browser tab. Nice and simple but not super useful. Then the more useful type that always seem to display this deal-breaker of a dialog box before installing. (This TinEye dialog is used just as an example).

A pretty typical extension installation dialog

Access to my data on all websites? Why? Why do extensions that have no need to access my browser history need access to it? This is either a serious browser deficiency or lazy extension developers who have never heard of the Principle of Least Privilege.