SQL – Joining two tables without related data – joining without an on clause
I'm loading test data, and have a situation where I have a list of ID's I need to generate test-data for, and a list of sample data I'd like to populate for each test ID. Something like this:
TestIDs
---------
1
2
3TestData
--------
A
B
What I want is a join that produces:
Result
--------
1 A
1 B
2 A
2 B
3 A
3 B
This is essentially a join without an "on" clause, however the trick in SQL is that the "join" keyword isn't needed either. The select statement is simply:
select * from TestIDs, TestData
Notice that there is a comma seperating the tables to select from, and no join keyword anywhere. Handy!
Rooting the Sprint Evo 4G from stock version 1.47.651.1 (2.1-update1)
Here's how to follow in my footsteps to successfully root a new Evo 4G purchased with the Update1 firmware--I had some issues early on, so hopefully this will help.
Things to gather:
- Your Evo, when you're ready to wipe all data (write down apps to reload, backup anything you don't want to lose, etc)
- Your USB cable
- SimpleRoot OTA 1.47.651.1 Edition
Ideal Steps:
- Try following the instructions on the SimpleRoot thread, ideally you won't have any issues and will result in a rooted stock firmware (note: this will leave your Evo in a state where you can install an alternative firmware--but SimpleRoot *is not* an alternative firmware).
- If things don't go so smoothly, try my customized steps:
My Extra Steps
- Check the version of HTC Sync on your PC, it should be the same version that was included on the SD Card of your phone. ( 2.0.31)
- Perform a Factory reset on the phone, either through the System menu or from the bootloader (hold the volume-rocker when powering up)
- Mount your MicroSD card as a USB drive and Format it (FAT32)
- Repeat the SimpleRoot steps
At the end of this process my phone entered a reboot-loop; which definately made me nervous. I pulled the battery and SD card, then replaced the battery and powered up (without the SD card) and it booted successfully. I verified the firmware had been successfully downgraded (to 1.17.x.x), which indicates the process was successful, and resumed.
My next step was a custom recovery--I tried using SimpleRoot's Extras menu, but my phone would boot to a red triangle with an exclamation and make it no further (this is the recovery screen)--so I grabbed evorecovery from here and (with the phone still at the red-triangle) unzipped evorecovery and successfully ran recovery-windows.bat. Upon completion I had my customized recovery screen running and took the opportunity to partition my SD-card for apps2sd (not sure if this will be relevant since I'm going to cyanogenmod 6/froyo/android 2.2--which includes an official form of apps2sd), and ran a nand + ext backup.
VB.NET (and C# 4.0) Optional Features – Great for Unit-testing structures and DTO’s!
Here's a great use-case for Optional parameters in VB.NET (and to be introduced in C# 4.0), it's saved me lots of code and kept my unit tests small.
Some data structures (DTO's to some folk, and classes as well) have a large number of properties with the same return type, such as:
public struct MyData
{
public MyData(string firstName, string middleName, string lastName, string surName, string formerName)
{ // set the properties }
public string FirstName { get; set; }
public string MiddleName { get; set; }
public string LastName { get; set; }
public string SurName { get; set; }
public string FormerName { get; set; }
// ...and so on...
}
Imagine that this strucuture is implemented with field-backed properties (instead of automatically-implemented properties) and we wanted unit tests to ensure that setting SurName didn't change the backing field for FormerName. Each unit test would need to instantiate an instance of MyData by passing a laundry-list of parameters. Here's a sample of a unit test (and accompanying BuiltTarget() method) showcasing how ugly this can be (notice that BuildTarget() is an ungainly mess; and that there would normally be one or more tests for each parameter).
Public Function BuildTarget(ByVal firstName As String, _
ByVal middleName As String, _
ByVal lastName As String, _
ByVal surName As String, _
ByVal formerName As String) As MyData
Return New MyData(firstName, middleName, lastName, surName, formerName)
End Function<TestMethod()> _
Public Sub New_WhenFirstNameProvided_KeepsValue()
Dim firstName = "Steve"
Dim target = BuildTarget(firstName, _
Nothing, _
Nothing, _
Nothing, _
Nothing)Dim expected = firstName
Dim actual = target.FirstNameAssert.AreEqual(expected, actual)
End Sub
To work around this my tests contain a single "BuildTarget()" factory which declares each parameter as optional, and provides a default value. Then when I need to set just a single parameter I can do so by name and let the default values provide the remaing parameters. The above sample cleans up to look like:
Public Function BuildTarget(Optional ByVal firstName As String = Nothing, _
Optional ByVal middleName As String = Nothing, _
Optional ByVal lastName As String = Nothing, _
Optional ByVal surName As String = Nothing, _
Optional ByVal formerName As String = Nothing) As MyData
Return New MyData(firstName, middleName, lastName, surName, formerName)
End Function<TestMethod()> _
Public Sub New_WhenFirstNameProvided_KeepsValue()
Dim firstName = "Steve"
Dim target = BuildTarget(firstName:=firstName)Dim expected = firstName
Dim actual = target.FirstNameAssert.AreEqual(expected, actual)
End Sub
As you can imaging, the small amount of extra code in the BuildTarget() method is insignificant compareed to the savings in each TestMethod.
UPS: Back to the future!
I ordered a D-Link DNS-323 NAS from Amazon yesterday with Super-Save shipping, which left me thinking I'd see a box next Tuesday or Wednesday. So I was beyond geeked when I checked the status midday today and saw it as Delivered, right up until I looked more closely at the tracking...
Apparently UPS can ship so fast that they wind back time. Which would be awesome, if only they got it to the right address (I like in Kentucky, not Missouri).
.NET: Referencing a 2.0 DLL from a 1.1 DLL
*NOTE* This only works if your executable is running under the 2.0 Framework!
At work we are writing a .NET 2.0 application that has its roots back in 1.1. Some ancillary applications were also written in 1.1, and shared some common libraries; so when it came time for this application to be upgraded to 2.0 some libraries had to be left behind for compatibility reasons.
One such library has the task of loading data from databases, and was designed to read from MS Access, SQL Server, or MSDE; however in the ongoing development of our application we are scraping the MS Access use in favor of SQL Compact Edition. For those familiar with SQL CE, you'll know it's not compatible with the 1.1 framework--so we were faced with the issue of either duplicating the functionality of the 1.1 DLL in a 2.0 DLL, so that old applications could be left alone, or with doing massive work to overhaul the old applications and try to bring them all up to 2.0... neither option was terribly appealing (although the first option was obviously preferable).
Our project architect put the task to me, and had a plan of attack that he figured would let us make the 1.1 DLL talk to the SQL CE database via a 2.0 DLL proxy--however you'll know that 1.1 projects cannot reference 2.0 projects. Here's where a little trickery comes in...
For a quick recap we have: A Framework 2.0 application, which calls a 1.1 Library to retrieve data. We need: A Framework 2.0 application to call the 1.1 Library to call a 2.0 Library to retrieve the data from SQL CE.
To achieve this we added an interface to the 1.1 Library, and implemented that interface in the new 2.0 library which uses the interface to fetch the needed data from the database. The 1.1 library uses reflection to late-load the 2.0 library and instantiates it by its interface.
So the workflow is:
- 2.0 Application makes a call to the 1.1 Library
- 1.1 Library uses an Assembly.Load() call to late-load the new 2.0 Library and casts it to the 1.1's interface definition.
- 1.1 Library then can call the Interface member, which...
- Talk through the 2.0 framework to our SQL CE database.
ThinkPad T61p: Converting drives from Compatibility-mode to AHCI
I formatted my T61 for the purpose of squeezing Vista down to a reasonable size, and so that I could ensure that I could get XP to install as C:\ (because (1) I will use it more, and (2) Vista will always show itself as residing on C:, even if it is really isn't).
To install XP I had to convert my SATA controller to run under Compatibility-mode, which allows XP to recognize the drive without a 3rd party driver during installation. After installing XP, Vista, and Ubuntu Gutsy Gibbon on the drive in this mode I flipped the BIOS switch back to AHCI, and both versions of Windows crashed hard.
Here's the path to recovery:
- Go to Lenovo\IBM's site and lookup the driver-download page for your machine, this page is under Support.
- Find "Intel Storage Matrix" on the driver page and download it. Then run this file, which will extract other files.
- Open a command prompt, and go to C:\Drivers\Win\IMSM\Prepare (created by the above step). Then run "Install.cmd" which will install the Intel drivers.
- Reboot, flip the BIOS switch to AHCI, and you should be all set.
This works for both XP and Vista; although Ubuntu was happy without any work
screen – a terminal encapsulator
My title might not be quite accurate, however screen is a great little utility that has a lot of leverage. My main use for it is to start an application and allowing it to run on my remote machine while I disconnect my ssh connection. Basically, just ssh into your remote machine and install screen. Then start the program with the 'screen' command. Now start your task, maybe a torrent with btdownloadcurses. Whenever you want to disconnect and leave the program to run press Ctrl-a d (Control and 'a' key, then 'd') to detach. Whenever you want to reattach to that session restart screen with the -r command, so 'screen -r' and voila you're back!
dmidecode
This is more a Post-it note to myself to remember one of my facorite new commands: dmidecode
dmidecode will output lots of details about your motherboard and the devices connected to it, including BIOS information as well as some upgradability info (usually).
Recovery from a dead FAT32 Windows drive
My landlord's old PC has suffered several failures over the years, including several fans and power supplies and at least one hard drive. When I moved in a year ago they called me over to replace yet another PSU for them, and a few months later to figure out why the machine would not even begin to boot.
The suspect was immediately either the IDE controller or both of its drive. After transplanting the drives to a seperate machine and failing to find their partitions, and after trying a new drive in the machine it was looking as though possibly all were fried.
A couple months have passed and my landlord has had me build him a new computer and the day has come to try to recover his data... Below is the process I've used to diagnose and recover his files.

