Last half of year I live in a hotel. I do not have my workbench here nor do I have extensive electronics part collection but I do have some basic equipment. And I do use it.
Pictured here is last thing that I made - voltage and current monitor. It has one input, three outputs, display and two switches (that I forgot to order). On bottom there is an PIC, sense and LED resistors. Pretty simple SMD board (45x72 mm) as it goes.
What it does? Basically it just displays voltage, current or power on it’s display for selected input or output.
Once I assembled it, I left it turned on for a while, pressing button here and there. Ok, since buttons are missing, pressing is probably not the correct word for what I was doing, but you get the drift. There is nothing like long-term abuse to bring code bugs out.
As I was leaving for work, I took one last glance at device, stopped, powered it off and hid it in the drawer. Call me crazy but I haven’t dared to leave it on like that for cleaning lady to see.
Somehow I think that she would only see some clock-like device with some wires coming out and numbers that change. Even more innocent-looking things were misidentified.
Most of my electronics is geared toward micro-controllers. And there my undisputed champion is Microchip PIC. They are cheap, full of options and readily available. And development environment is not too bad.
When I say not too bad, I think of MPLAB 8 IDE. Kind of old fella but it gets job done. I did try a beta of their flagship MPLAB X but we never clicked. It didn’t help that it would not load my projects either.
Since I was just starting new project it seemed like a good time to finally get newest and greatest IDE. So I went to their download page and I was greeted by total of 2:30 minutes of video with voice narrative.
I am not sure whether problem lies in me but stealing my speakers for something like download of a tool is ANNOYING. And, of course, some idiot decided to LOOP the video. Probably the same idiot who though that putting stop control was too much work. I though that kind of annoying behavior was reserved for porn sites but Microchip never ceases to amaze me.
Only image that gives me any peace is seeing manager whose idea this was in tenth circle of hell listening to these instructions over and over again. Well at least looping comes handy.
Standard Random class works perfectly fine most of time. However, on bigger sample, you will see some non-random tendencies. Much better random source is RandomNumberGenerator.
Unfortunately RandomNumberGenerator does not actually return random numbers. It returns random bytes. It is our duty to change those random bytes to single double value ranging from 0 to 1 (as from NextDouble function).
Idea is to get 4 random bytes and to convert them to unsigned integer (negative numbers are so passé). If that number was to be in 0 to 1 range it would be enough to divide it by UInt32.MaxValue. Since we need result to be less than 1, we have slightly larger divisor:
privateRandomNumberGenerator Rnd;privatedoubleGetRandom(){if(this.Rnd ==null){this.Rnd = RandomNumberGenerator.Create();}var bytes =newbyte[4];this.Rnd.GetBytes(bytes);var number = BitConverter.ToUInt32(bytes,0);return number /(UInt32.MaxValue +1.0);}
It seems to me that Internet drives are everywhere.
For a while we had DropBox as undisputed king of remotely synchronized files. When it prove successful, we got bunch of others, among which SugarSync seemed like most serious contender.
This week things got interesting with Microsoft introducing SkyDrive. And today we got Google onboard with Google Drive.
Only company missing action is Amazon. Yes, they have their drive also but they are missing half-decent sync client.
With so many heavyweight players around, things are bound to get interesting soon. :)
My personal favorite when it comes to databases is Microsoft SQL Server. However, reality dictates that I sometime have to use different database. Actually quite often I need to have one application supporting different database servers. I might need application to work on SQL Server, PostgreSQL and (god forbid) Oracle.
With time I got used to prefer standardized parts of SQL. It makes life a lot simpler and SQL Server is usually ok with that plan. Except when it comes to NULLs where things can get little bit quirky. Setting ANSI_NULLS to true does sort most of issues but one.
If you have unique index on nullable column, SQL compliant behavior is to force uniqueness on all values except null ones. That means that having "a", "b", null, null is valid scenario. In SQL Server that second null will not be allowed under premise that such value already exists and thus violates unique index. That “feature” is part of SQL Server since it’s very first days and it is very unlikely that it will be changed in the future. Compatibility is a bitch sometime.
Fortunately there is a workaround since SQL Server 2008 in form of filtered indexes. That enables unique index on only some values. In our scenario we just need to ignore nulls and standard behavior here we come:
CREATEUNIQUEINDEX UX_MyIndex ON MyTable(MyColumn)WHERE MyColumn ISNOTNULL;