To Catch A Geek: Texas to Jail Computer Techs

Texas, of whom I am usually proud to call myself a native, somehow managed to pass one of the stupidest laws I’ve heard of in a while. If you work in computer service and repair (cough*geek*cough), you now are required to either have a criminal justice degree or a private investigator license. A CJ degree of course is 4 years, and a PI license takes at least 3 years of training to obtain. Punishment can be up to $4000 fine and imprisonment , and – get this – even a customer of such services can face the same punishments, even just for SOLICITING work from an “unqualified” geek.

Think about this. How many members of your local geeksquad, or your neighborhood ‘pooter geek, are going to have these qualifications? NONE.

Then also think about this: I don’t want to bash law enforcement, but think about the people you know with CJ degrees. Either cops, or college athletes who didn’t know what to take. Ok that was a bit harsh, but seriously, these are the guys we have to rely on to fix our PC’s for the next 3 to 4 years while the “real” geeks get “educated”? Refer to Zoolander clip.  (sorry, couldnt figure out how to embed this one..)

Texas has very few restrictions on gun ownership, and allows carrying a concealed weapon after taking a class that lasts all of 4 days (last I checked). Only in Texas: 4 days to be packin’ heat, 4 years to help your gramma find her missing recipes file.

There’s at least one lawsuit already in progress over this, from the good guys at the Institute for Justice. This link describes more about the law and what they are doing to fight it. I can’t remember the last time I called lawyers “good guys” but I wish them luck in reversing this stupidity.

Of course there is that silver lining… now when your friends ask you for help with their PC, you have a  reusable excuse instead of having to invent a new one every time.

Scratch your Car and Feel the Freedom!

A wise drunk weird crazy man once told me that the first thing he always did after buying a new truck was drive it through a bunch of brush to get some scratches on it. I was a kid at the time and thought this sounded crazy.

Now XX years later, I realize the wisdom in this.

My work truck is an old beat up Ford, which looks good overall for its age but has that spot where I nicked a mailbox, the dents from poorly-aimed firewood thrown in the bed, and the place where I kissed a wall in a parking garage (not due to unfamiliarity, but from trying to do 35 on a twisting ramp I had become too comfortable with…)

Last year I bought a new (to me) car which still had pristine paint, no dents, no scratches. And while it is a blast to drive, I found myself parking far away from other cars, and worrying about getting a nick or a scratch in the paint. However, when I drive my truck, I don’t have a care in the world.

Only about a month after owning it, a valet parked the car and backed it into a wall, creating a series of nice scratches on the back bumper. Of course I wasn’t excited about this, but I’ve realized since that those scratched has relieved me from the opression of perfection. Since that time, I’m no longer so worried about little nicks and dings from day-to-day use, and I’m now (at least closer to) enjoying the freedom from worry that I’ve enjoyed with my truck for so many years!

So apparently the crazy guy knew what he was talking about.

I’ve observed the opposite in action as well. An unnamed associate of mine is a wealthy business man who last year bought a very expensive luxury car. I’ve observed this normally relaxed individual become obsessive in his quest to keep the car in pristine condition. Not too long after purchase, the ”first scratch” appeared on a fender, inflicted by an unknown party. Instead of embracing the new freedom of imperfection, he took the car to the shop the same day to have it repaired, and continues to obsess over the car to this day.

Thus I propose the Scratch Your Car movement day month concept ritual. Anyone buying a new car should free themselves from the oppression of perfection by finding a creative way to “personalize” it and add their own first imperfections. Instead of dreading and being victimized this uncontrollable future event, embrace the process and take control of your life. Key yourself, bump into something (but not someone..), or find something really creative to do. You’ll simultaneously improve your life and create a good story to tell your friends.

And they’ll probably think you’re crazy too.

Nullable Datatables – another gripe

This is sorta old news, but my last Asp.net gripe put me in the mood to continue with another longer-term gripe I’ve had. Don’t misunderstand, I love .Net technology, but the few annoyances I have with the technology seem to drive me nuts.

So this time, I’m talking about datatables, and specifically strongly typed datatables via the new-as-of-2.0  DataTableAdapters.

Strongly typed datatables work fine when bound to .Net UI components such as asp.net or winform grids, because the binding mechanism knows how to check for null values in the table without blowing things up. This is accomplished via calling a IsColumnNameNull() method for each column in the table row, and then only accessed the column value if it is not null.

The new DataTableAdapters allow attaching sql queries directly to the strongly typed datatable, so these become a quick-n-dirty data access method for things beyond just binding to visual components. I’ve built numerous apps that work with these adapterd in business object layers that never see the UI. But the pain being that any time in code I wish to reference a column value, I am back to having to write code like this:

int? MyValue = SomeTableRow.IsSomeColumnNull()? (int?)null:SomeTableRow.SomeColumn;

or alternatively:

int MyValue = 0; //assign a default value
if(!SomeTableRow.IsSomeColumnNull())
    MyValue = SomeTableRow.SomeColumn;

Let’s do some math. If your table has 20 columns that are non-nullable (varchar/strings can be configured to not need this check), and your datatable is referenced in 10 places in your app, this is 200 places you have to write this mindnumbing code. My last database had about 10 tables to work with, so I could estimate I wrote this about 2000 times. And each one is unique, so you can’t cut an paste it very well (thank God for intellisense making this just a bit easier).

The bigger problem with this… the *HUGE* problem actually… is that if you don’t put this code in all the right places, you will produce an application that will compile fine but could have horrible bugs that may not show up for years. The following code compiles without problem:

int MyValue = SomeTableRow.SomeColumn;

SomeColumn is an int property on the datatable’s datarow, and thus the compiler sees no problem with this line of code. And if your database always has data in SomeColumn and never encounters a null, this will run fine.

However, if the column does allow nulls in the actual database, and a null winds up in there, this will throw an exception at runtime when this tried to access the null value.

With the release of Linq to Sql, we now have a easily generated object representation of the database tables similar to what the typed datatables used to provide. The linq versions support nullable fields, so that any database field is represented by a nullable version of the base type it represents. So now the equivalent code as above in using a linq table is:

int? MyValue = SomeTableRow.SomeColumn;

This sample uses a nullable int for MyValue, so that it will handle a null value just fine. But even if you want to keep the original non-nullable MyValue variable, you can still very easily do this:

int MyValue = SomeTableRow.SomeColumn.GetValueOrDefault();  

And this will use the nullable default method to return a default int value if it is null.

Not only are both of these nullable methods much cleaner and easier to use, the (again HUGE) benefit is that they are safe – if it compiles, it will not throw an exception at runtime… for nulls, anyway.

I had hoped that MS would add nullable column handling to these datatables in Visual Studio 2008 when it was released.. unfortunately not. And I’ve already had another project since 2008 release where I had to cuss my way through a huge pile of IsColumnNull()’s and the subsequent app blowups from the ones I managed to miss. I know developers have been asking Microsoft to add this feature for a long time, and it’s not a difficult thing to do, PLUS it adds so much safety to the compiled code… If this is good enough for Linq to Sql, why not for out trusty old DataTables? I don’t understand why this has dragged on so long.

ASP.Net formview – gripe of the day

I upgraded an asp.net project today to switch from a DetailsView control to a FormView control. Obviously I needed editing capabilities, thus the reason.

The upgrade reminded me of a major gripe I have with the FormView control. When you associate the control with a datasource, it will auto-generate a tabular form view of your data, in a list of Name: Value format. Really what it is doing is just creating a quicky view of the fields in your datasource and throwing the generated fields into the 3 templates needed (ItemTemplate, EditTemplate, and InsertTemplate) so you can have them handy for all that extra formatting you are expected to want to perform.

One formatting difference between the auto-generated code this control produces versus the format of the simpler DetailsView is, the DetailsView produces table elements so that all the “Name” elements show up in a single table column followed by the “Values” column. This is a nice formatted and is usually pretty close to what you would want to create in a list of values.

The FormView however assumes you are going to do a lot of editing of the templates, and so doesnt include any layout except the basics- Just the Name, “:” , and the bound feld value.  This results in the Name and Value getting bunched together up on the left side and results in a truly ugly form.

Not too difficult to format these into a table if you want to, right? Well sure… but after building a few apps using this, it can drive you nuts. Some of the apps Ive worked on have, say, an average of 30 fields to present on the screen. After I generate the FormView from the datasource, I then have to go add table TR/TD code around every element… 3 times. So those 30 elements are tripled to 90 elements. Each of the 90 elements has to have an opening TR/TD, then a middle TD/TD, then a finished TD/TR. So we are now looking at having to cut n paste about 270 items and try to make sure you didnt fubar anything.

To make things worse, if you make a schema change in your database (and who doesnt), you pretty much need to regen the thing and start over. 

AND: This is just ONE FormView. One app I recently finished had at least 20 FormViews in it. Neglecting any rebuilds, this is around 5000 elements I had to hand edit. Deadline? You talk funny.

I understand MS’es thinking in this, and I would probably be much worse off if I were in the other boat and had to *remove* all these unwanted table elements every time a Formview is generated… but why not offer an option to include a basic table formatting? Or even allow for custom formatting of the generated code so we can include our own tags or whatever markup is desired. I even researched to see if it’s possible to create my own generator for this to override or replace the one Visual Studio uses… found some obscure stuff but nothing really useful.

I’d like to hear if anyone has any pointers on this.

Linq and Sql Server Timestamp Columns – Why Binary?

As explained a bazillion times before on the net, the timestamp column in sql server is not a datetime or anything to do with time.  It is a binary(8) column which contains a big number which is incremented on every edit of any row of any table in the database. It is also identical to the rowversion column.

Now for my gripe. I’ve used strongly typed datatables in past projects and with some manipulation, you can get the datatable to treat the timestamp column as a bitint (Int64). Why does this matter? Because I’ve used it for some simple version tracking in the past, and this requires I perform range checking on these versions. A simplified explanation:

-Use the largest timestamp in my cached table
-Query the database table for any timestamps larger than this one
-Retrieve these new or updated items to be merged back into the original dataset

This normally is not useful for 2 or N tier apps, but in my instance I am transferring data over the net via a webservice so would like to only retrieve the new or changed records to the client.

Gripe time: why are these columns Binary? The only way I was historically able to query on them is to force sql server to cast them as a bigint, through some magic in the typed datatable. But now Im using Linq as my data access layer. I love linq so far, but I have tried every trick I can think of and it will not make this work- Linq will always fail with a illegal cast type error when it attempts to load the record.

So, whyt exactly are these binary? Wouldnt it be much easier to make use of rowversion and timestamps if they were represented as a real datatype like int64/bigint? I know I wouldnt have wasted half a day yesterday on this if this were the case.

So now it looks like Ill switch to using a datetime column that I hope is udpated with every edit or insert. Should work ok, but not my preference.

Fined for Handicapped Parking

Noticed at the park yesterday, a handicapped parking sign for a parking spot (I was stretching in front of it, no I didn’t park there.) In the smaller print, it said “Fine $50 - $200″. You’ve probably seen these around as well, and I know I’ve seen them for years.  

But then I thought… What determines whether the fine is on the $50 or the $200 end of the spectrum? Should I be glad or upset if I get a $50 fine? Imagining the cop’s train of thought: ”Yeah, this guy is in violation, but since he seems a bit mentally handicapped I’ll just give him the minimum fine.”

And what the heck are you to think if you got off with a warning?

Solar AC System?

One I was thinking of yesterday – a vented ridge cap on the top of a house’s roof will let hot air in your attic flow upward and out the top, drawing in cooler air along the eaves. So was wondering if home AC systems could use this airflow to draw air over the exterior coil and reduce the energy needed to run a fan. But a bad side effect would be adding extra heat to you your attic.

So the next thought was, just build either a series of “chimney” tubes, or even just join the tubes together to form a large thin chimney which could cover an entire wall of a house, and would let the hot air entering it from the bottom out of the AC coil to flow upward and pull more air through the system, thus again eliminating or reducing the need for a fan. This could also act as a sunshield for one side of a house, and the funny thing is sunlight would even enhance the effect (heating the chimney causes extra airflow).

So i did a quick search and confirmed my suspicion that this is old news..Patent 4706471 for a “Solar Chimney” uses solar energy to heat a chimney and produce airflow to aid in cooling an AC system, though this particular one seems to be focused on geothermal. (See http://www.google.com/patents?id=NsAwAAAAEBAJ&dq=4706471 ). This is after a 15 second search, so Im sure there is lots of other related tech out there. I may add more here as I find time to look into it.

 

The patented solution to the world’s energy problems (hint: not really)

This one has amazed me for a while, figured I would post it here.

Following is a patent, number 7095126, which was issued in 2006 for an energy creation device… first, take a look at some pictures:

 

What a great idea! In fact, I remember trying this one when I was a (really young) kid. I had a motor connected to the rear tire of my bicycle, and a generator hooked up to one of the tires (maybe it was the front tire, you know, since that might make it work better). The generator had gearing to spin it much faster than the motor, thus the bike should generate its own electricity and power itself.

It’s a barely genius idea, except of course it doesn’t work. It is a classical example of a free energy machine, also known as a perpetual motion machine.

So let’s review patent number 7095126. Electric motor, check. Generator, check. Gearbox to make the motor spin the generator faster. A battery to get things started. And a load to use all that extra electricity you will generate. A truly bare bones implementation of a perpetual motion machine, minus the usual clutter of obfuscation in an attempt to fool yourself or others into believing it really works.

Iv’e expressed frustration for years over what the patent office has become and the level of incompetence it has reached. It appears they will grant a patent on just about anything, unlike the rigorous and difficult path that washistorically required to obtain one. But even the PTO has specific rules regarding perpetual motion machines, specically that NO PATENTS BE GRANTED FOR THEM.

So, this means that the patent examiners either a. knew this was perpetual motion, and accepted it anyway, or even worse b. accepted it because they didnt recognize this as perpetual motion.

I propose that any future discussions or debates about the quality of work being produced by the US Patent Office, simple state “7095126″ followed by a “QED”. Nothing more need be said.

 

A more efficient refrigeration compressor?

This is the weird stuff I wake up thinking about. Last week I woke thinking (dreaming maybe) of a system that would recycle some of the energy wasted in compressing refrigerant in an air conditioning system.

If you recall how the refrigeration cycle works, you basically run a compressor that smashes a gas to a high pressure, which causes it to get hot. Since it is now hotter than ambient air, blow ambient air over the hot gas to cool it off, while staying at the high pressure. Then move this high pressure, slightly cooled gas back  to where you want to be cool (inside your house), and let it rapidly expand thus causing it to cool off a bunch. Use this coldness to cool your house (blow house air over it to cool it), and then repeat this process with the gas which now contains the heat taken from your house.

I had read recently about a generator being used in the oilfield to generate electricity by replacing the choke in the gas well with a generator. A choke is just a smaller opening through which the gas has to slow as it flows out the well, since many gas wells would flow to quickly without one. So this generator replaced this simple choke with a turbine that would provide the same flow slowing effect, but with the benefit of using this pressure drop to spin a turbine and produce electricity– energy that would otherwise just be lost.

So, do you see the applicability to the AC system? The compressor in this system is pressurizing gas to a high pressure, but then this energy stored as pressure is “lost” as the gas simply expands across an orifice, just like the gas well choke. Why couldn’t the compressor benefit from some form of turbine attached to the outlet which would recover at least a portion of the energy used in compression? It should still provide the refrigeration benefits as the gas is still expanding and thus cooling.

So, I did a quick search and sure enough it looks like the Japanese have a colleciton of patents on this technology. This one is pretty much it exactly: http://www.google.com/patents?id=2qAMAAAAEBAJ&dq=6543238

Strangely, it seems a US patent was issued in 2007, quite a bit newer than the japanese ones: http://www.google.com/patents?id=IGCEAAAAEBAJ&dq=7272932 (although it does seem more broadly defined).

So now I’m only curious if A. this is being used at all and B. I’m pretty sure it isn’t, so I wonder why not? I know with many ideas like this, the benefit just doesn’t justify the addional cost, so I’ll have to assume this is the case. Let me know if you have any comments on this one.

This whole discussion got me thinking about resonant refrigeration and what the current state of the art is in this arena, but I’ll save that for another day. Some quick searching didnt turn up much, but I’m sure there has to be more info out there on this topic.

 

 

 

Howdy, and Why?

Since I spend a lot of time online seeking solutions to problems (aka, find some sucker who has already done the work for me), I finally decided to start this to keep the results of my “hard work” in one location. A lot of this is programming related, and specifically of the C# flavor.

But I also have a problem of what I call “reventing”… inventing things that have, well, already been invented… sometimes almost a century ago. But these reventions are typically interesting discussions nonetheless, so why not put them here. And perhaps it could help me avoid re-reventing, and it’s not like I’m revealing some big secrets.

If you are wandering in from some far side of the globe, let me explain that “Howdy” is how we say “Hello” in Texas. Or at least, how we used to. Although it was never considered proper english, I’m trying to at least keep this reminder of our past alive, as it seems most Texan’s no longer speak “Texan” anymore… we all sound like boring midwest losers like the kind you see on tv… myself included. Well, except for the growing quantity of “press 2″ crowd here, but that’s another topic.