Code
Encryptr
by james.mckee on Dec.20, 2011, under Code
I had been fooling around with this idea for a long time, and I finally sat down and coded it. The idea is simple, in the world of secret sharing you want to ensure that the fewest number of people have what is needed to expose the secret. The problem is that in many cases when you hand over that information to a service or escrow you have no idea if they are really keeping that infromation secure. Classic example is that if you send email from one person to another the email, even though it may be sent across the wire using ssl, is more than likely sitting on the server in plain text. Even if it isn’t there are ways for the administrator to expose the contents of the email box. So how do you pass a message and make sure that everything is secure.
You encrypt it on one end and decrypt it on the other end, without storing anything but the encrypted text on the server. That’s what encryptr does. It takes a message typed in by the user and encrypts it using javascript then sends only the encrypted information to the server. The only part of the message that is identifiable in the server is the id which is used to look up the message.
If you are interested in the project feel free to got to https://bitbucket.org/punkcoder/punkcoder.applications.encryptr
Things I Wish I Learned in College: Someone will be reading your code…
by james.mckee on Jun.24, 2011, under Code, Technology
I came across this the other day in a piece of forgotten code. If you have been in programming for any period of time then you surely have seen it. Its the ‘well documented hack’ for example:
//This Item was created per the client //Instructions to correct a legacy issue // ... //Do not delete this method
I know people who have written those lines of code, as I am sure that there are some people out there that continue to write lines like this. But I want to take a moment and think about this, is this the type of code that has a place in your product? This is the essence of hacked code. In my current line of work I find code like this alot, programs and methods that have gained so much dust that the people who wrote them are no longer around to ask why they were important.
Which brings us to the point of all of this, at what point to you attempt to fix the issues of time that has gone past? How do you turn around a program rifled with code rot, and in the end is it really worth it? Many cases the applications that contain this type of code have millions upon millions of lines of code. The only way to make certain that you don’t land yourself in this spot is to always approach code with the thought that someone forty or more years down the line will be reading your code. They will look at your prized application and they will not see the bleeding edge technology that you saw when you designed it. They will see the hulking and aged behemoth that remains, they will look at it with very different eyes. The only gift that you can give to that person is code that is clear, clean, and easy to read.
If you see a hack replace it with the corrected code, and don’t write any more hackish code. If you are intent on making software your craft, learn it, and exercise it to the best of your ability.
Parallel namespace in .NET 4.0
by james.mckee on Feb.11, 2010, under Code
It was only a couple of months ago that I purchased a new laptop. A very shiny Dell Studio 15, with a core i7 in it. I have been very happy with it.
But it wasn’t long before I started to notice a problem, when I would run programs it would max out one maybe two of the cores and the rest of the computer would be idle. For a machine that has 8 logical cores (4 Physical w/HT) that’s a whole lot of waste without a whole lot of return. Then I started to think about the problems that come up with doing multi threading in code. It’s flat hard, and in many cases if its not something that you were thinking about from the very begining you are in for a world of hurt. So you could imagine how happy I was when I heard about the Parallel namespace that is included in version 4.0 of the .net framework.
The idea was that because multithreading is difficult especially when you are talking about systems that are generally designed by people whom have little deep understanding about the technology that they are dealing with, it was refreching to see that the people in redmond were thinking about us. Now it is as simple as working with a single namespace and making sure that your resources are properly taken care of.
How well does it work? I decided to put together a little test to test the whole thing out. So I decided to create a small code segment that would simulate a thousand segments processing at 10ms a piece and the results were almost exactly what I expected, I tested this on my new laptop, so it’s splitting the work between 8 logical processors.
Single Console Run Time : 9990ms
Parallel Console Run Time : 1216ms
While this is not a super scientific task since we can see that the work that is being done is just putting the thread to sleep, it does effectively show that the framework for parallel core processing is working and can be implemented with little extra work.
Here’s the code so you can test and see what you come up with:
static void Main(string[] args)
{
int MaxCount = 1000;
System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
timer.Start();
for (int i = 1; i < MaxCount; i++)
{
Syscode(i);
}
timer.Stop();
Console.WriteLine("Single Console Run Time : {0}ms", timer.ElapsedMilliseconds);
timer.Reset();
timer.Start();
Action sysDelegate = new Action(Syscode);
Parallel.For(1, MaxCount, sysDelegate);
timer.Stop();
Console.WriteLine("Parallel Console Run Time : {0}ms", timer.ElapsedMilliseconds);
Console.Read();
}
public static void Syscode(int x)
{
System.Threading.Thread.Sleep(10);
}



