Friday 11 December 2015

Western Digital Elements drive, One TB, Pull-apart insides

Last night I pulled apart the Western Digital Elements portable 2.5" External hard drive.
This drive is quite light and easy to carry around. My new favorite in portability and relatively cheap.
I remember hauling a box full of floppies mid to late nineties, this elements drive is so much better!

Prying open the case was not too bad. Simple unplug the cable, gently expand one of the edges with a jewelers screwdriver flat head and then insert a larger flat head in the cavity and pry gently all around. Do not start at the cable end but on the side middle. Once the cover is poped on all sides, simple slide the cover up at the cable input and it should gently lift out with no damage.

I will discuss further after the images, but here they are(Click to enlarge):
Cover off. Drive still in bottom casing.

Drive out of bottom casing.

Cable end of the drive. You can see the Drive form factor for a 2.5 in is retained but is bonded to the disk controller that has a USB interface built into it.

Better view of the drive controller and USB interface circuit board at the bottom of the drive.

Put back together. The screwdriver is the smallest one I have and it is 13 cm in length.
The drive controller circuit board that is normally present on all Hard Disk Drives to control and communicate between the host and the drive mechanics also has a usb interface. It does not appear like you can simply purchase a 2.5" drive and put it in this casing. However at the low costs these things are, why would you want to! The drive is from their Western Digital Blue range.

The drive mounting screws have rubber around them that slides freely into the bottom half of the casing. This provides some cushion against shock and likely helps reduce vibrations from the drive filtering onto the surface the unit is in contact with. Other than that, the inside is fairly unremarkable.

This is an awesome drive and it is currently plugged into my NetGear R8000 Nighthawk wireless router so I can share files on any devices on my wireless network. I mostly put backup files on it however.

Enjoy, and remember, I pulled this apart so you don't have to!

Friday 13 November 2015

How to get old games working under windows 10 using VMWare Player

Hi gamer guys and gamer girls!

Last time I showed you how to get Need for Speed Carbon working under windows 10 and mentioned that this could be used to run other games relying on safedisc.

I have been continuing to experiment with better ways to enjoy Need for Speed Carbon and found yet another way that works surprisingly well without the compromise to system security.

The answer is simply to use VMWare Player
It is free for personal use, and of course running a video game is pretty much personal use.

I wont go into detail on how to set up the player because VMWare Player is quite intuitive when you use it.  Just click "Create a Virtual Machine" and follow the on-screen instructions. When you get to the screen below, click the button called "Customize Hardware" :


Note: Unlike the hard drive mentioned in the screen shot (5 GB), you should use at least 40 GB. The above screenshot is a mistake as I was trying to create a VM just to take a screen shot for this blog. I was going to type 50GB. So please be sure to use at least 40, or 50 GB as your virtual HDD size! Also the Memory should be what ever your game needs + 1 GB. For Need for Speed Carbon, I used a VM with 2 GB Ram allocation.

In the Customize Hardware screen, select "Display" then at the top right, CHECK the box called "Acclerate 3D Graphics"

You are done! You now just have to install the OS

The gotchas:
1) You need a legitimate OS that is windows XP or higher original install disk and key so you can install it inside the virtual machine.
2) You need OS installation experience.

However, it is a Virtual machine and anything you do inside it wont harm your computer, so experiment away!

Once you have setup your virtual machine and set up an OS that is Windows XP(service pack three) or higher, then you need to install need for speed carbon.
First tho, you MAY need to connect your CD/DVD to your VM if it isn't already set up for it. To do this, simply click on Player drop down then click on "Removable devices" and then select CD/DVD option. Now you should be able to pop in the NFS Carbon (or any other game) DVD in and install the game. Once done, it should run fine.

Performance:
  • Slight jitter but quite playable.
  • A few settings can be pushed to high.
How does VMWare compare to Hyper-V Manager? No comparison because VMWare is, hands down, far superior.
VMWare ran the Guest OS at 32 bits, 1080p (without going through RDP), and virtualised 3D hardware. Hyper-V manager did none of that and only ran 1080p via RDP but still no 32 bit colour mode.
After checking out the features of VMWare player pro, versus the free version, I am convinced I need to purchase this amazing piece of virtualisation software especially when half the available features of pro is something I will use.

Ehm, back to the games at hand...

The performance I got in Need for speed carbon outlined above is on a system running VMWare Player 12 with hardware:
INTeL I7- 2600, 12 GB Ram, and an nVidia (EVGA brand) GTX560Ti card. The VM is stored on a RAID drive using Software RAID in "Stripping" mode. HOST OS is on an SSD (Samsung Evo 850). VMWare player is installed on a 2 TB Seagate Hybrid hard drive (8GB SSD Cache coupled Mechanical drive).

I have no idea how it will perform on other systems but it is a safe bet it will perform as mine did on at least a system with the mentioned hardware or better.

Happy Gaming Everyone!

Saturday 31 October 2015

How to get Need For Speed Carbon Working Under Windows 10.

Hi Gamer guys and Gamer girls!

Today I will show you  how to get Need for Speed Carbon working under Windows 10. This same process can be used for other games as well.

UPDATE: The instruction that is present at the bottom half of this post need only be performed once. See the very bottom for the rest of this update.

I have plenty of video games I have bought and never sold. I still have their original packaging, receipts, and you will be lucky to see any scratches on my CD's or DVD's. As the years went by and new versions of Microsoft OS's came out, I am always nervous whether my old games will work or not. That is because I sometimes still play them(at least the ones I can still get working).

This then brings me to Need for Speed Carbon. It would not work so rather than re-invent the wheel, the first thing I did was scan the Internet to see if somebody has found a way to make it work. I could not find any where that showed how to make it work other than NoCd cracks(which you must never get).

The symptoms are:
-The game installs fine but:
-You try to run NFSC.exe and it asks for Admin privileges.
-You launch it with admin privileges but nothing happens, the CD does not get accessed, no process is created.
-You try compatibility modes but  nothing works.

Read on!

The most interesting thing abut NFSC is that it uses the same game engine as Need For Speed Most Wanted, and need for Speed Most Wanted works perfectly fine under Windows 10. So the first trick was to see if I can get the need for speed most wanted exe to launch Carbon, or at least do something enough to give me some clues. It fired ok and asked for the CD even though the NFSC CD was still in the drive. I popped in the NFSMW disk and the game started to launch, the NFS Carbon splash screen came up and then the game crashed. This would give me a clue later on, just not immediately.

I attached a dis-assembler(ollydbg) and walked through it to see what was breaking. It failed after making a call to ntdll. There were a whole bunch of other external files it had jumps to. I was getting a little suspicious, it did not want to read the CD.

Long story short, as it turns out, the NFSC executable is infact a Safe Disc decrypter by Macrovision. Worse still, Microsoft has announced that Windows 10 will not support Macrovisions DRM driver secdrv due to security issues. I personally fully support this decision, however it is clear that nfsc is not the only game that is going to be affected. After much research, I found that if you can get hold of secdrv.sys, you can get older games to run, so the question I asked myself was 'can I get NFSC to run'? It is not that straight forward as simply copying secdrv.sys into the right folder and the popular "deso" tool does not work for Windows 10.
I will explain how to get it to work.

How to get Need for Speed Carbon Working Under Windows 10 - THE INSTRUCTIONS

The trick is to sign the driver your self. See this link for signing the driver your self:
Test Signing a Driver

Step 1:
Get secdrv.sys either from an older windows version or download it from the internet. Microsoft no longer supplies this driver in Windows 10. But you must get this driver for the correct architecture. Hence you cannot load a 32 bit driver in a 64 bit system and vice versa. Place the file in C:\Windows\System32\drivers\
Step 2:
Open command console using elevated privileges (Admin command prompt: right click Windows start icon, choose "Command Prompt (Admin)")
Step 3:
You will need a tool called SignTool. If you do not have it, download it as a part of the windows 10  SDK. If your environment settings are not automatically added after installing the SDK, you can find it(assuming default install) in : C:\Program Files (x86)\Windows Kits\10\bin\x64 (for 64 bits) and C:\Program Files (x86)\Windows Kits\10\bin\x86  (for 32 bits). Alternatively you can temporarily add it to your path by typing  at the command prompt:
path=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\x64 
(or change x64 to x86 if for 32 bits).
Step 4:
You need to create your own certificate store. For simplicity I will call my store "MyCertStore" and I will call the certificate file "MyCertStore.cer" And call the Certificate name OLDGAMESCERT
Firstly you create the certificate with the following command:
MakeCert -r -pe -ss MyCertStore -n "CN=OLDGAMESCERT" MyCertStore.cer
Step 5:
Sign the secdrv driver by issuing the following command:
SignTool sign /v /s "MyCertStore" /n OLDGAMESCERT /t http://timestamp.verisign.com/scripts/timstamp.dll C:\Windows\system32\drivers\secdrv.sys
Step 6:
You will need to install the certificate to Trusted Root Certificates with the following command:
CertMgr /add MyCertStore.cer /s /r localMachine root

After that command it should say that CertMgr completed successfully. If it does not and instead launches the certificate manager (Image below) then you need to do something different.


You may see something like the screenshot above.

In that case look for the store name you created, in this example it is "MyCertStore" and expand that branch on the left pane. You should see another branch called "Certificates". Click on that and on the right hand pane you will see the certificate with the name you called it (OLDGAMESCERT). Right click and select Copy. Then expand the branch on the left hand pane called "Trusted Root Certificate Authorities" and then then click on "Certificates" branch under that. Right click in the right hand pane and select "Paste". It will display a message asking if you want to install the certificate here --of course you do!
Step 7:
Once the certificate is installed, close certmgr (unless your certmgr did not open and yours worked fine from the command prompt -in that case continue on to step 8).
Step 8:
You should still have the admin command prompt open. If not, open it again. Issue the following command:
bcdedit -set testsigning on

WARNING: THIS IS A DANGEROUS COMMAND, READ THE FOLLOWING BEFORE DOING IT:
The above command will switch on test mode for loading unsigned drivers. This is a serious security risk and will open your system to virus and malware attacks. It should only be used for developers to test drivers they are developing by signing unverified certificates.
Why I am showing you this is for those people who want to run NFSC without using any of the options that will come at the end of this article, and also it is a proof of concept that this game CAN run under windows 10.
Step 9:
Reboot your system. Once rebooted and you have logged in, you will see a test mode watermark on the lower right corner of you screen. This should not appear in your game and there are ways to remove it, however, I recommend that you do not disable this watermark. This watermark serves as a reminder that you need to switch off the test signing after you are done playing the game.
Step 10:
Launch your game with your original CD in the drive and Need for Speed Carbon should launch.

The next step is pretty easy.... PLAY HARD!!! --But it isn't over yet, there is just one more thing to do...

Step 11:
DISABLE TEST SIGNING MODE:
Open the admin command prompt again and issue the command:
bcdedit -set testsigning off
Then reboot your computer. Confirm that the test mode water mark is gone.

Why I recommend the following options instead of the above:
As mentioned above under the RED headings', it is very dangerous as you are crippling your systems security. If you are really desperate and do not have any other older copy of Windows, then this will get you playing again.

I Recommend the following options instead:
1) Purchase a version of the game that does not use Safe disc anymore such as from Valve's Steam
2) Install an older version of windows as a multi boot and install your old games on that.
3) Revert back your Windows 10 upgrade (don't do this, Windows 10 is awesome, please keep it!)

NEVER use noCD crack (even though Microsoft appears to be advocating its use under windows 10 for old games!).
NoCD Cracks have a high chance of containing malware that is probably more dangerous than switching your system TEMPORARILY to Test signing mode.

*** UPDATE ***
You only need to perform the instructions provided ONCE. After that you just need to switch the testsigning instruction ONLY. Hence: Switch on testsigning, reboot computer, play game, switch off testsigning, reboot computer.


Happy Gaming everybody!

Sunday 30 August 2015

Moving your firefox profile after a clean install of Windows 10

After the awesome flawless upgrade to Windows 10, and knowing that I can now do a clean install and still have windows 10 activate afforded the re-install.

However an excellent question to ask is 'moving your firefox profile after a clean install of Windows 10'. You want all your extensions, bookmarks etc to come over, not just your bookmarks.

Hunting on the internet didn't yield much. Most options revolved around exporting the JSON file for your book marks. This information probably does exist somewhere but here it is anyway.

First go to the drive your windows is sitting on (Windows 7 and up). Head to <your windows system drive>:\Users\<your user>\AppData\Roaming\Mozilla\Firefox\Profiles
You will see a cryptic looking folder inside looking something like z8h0c3kh.default
Make a backup of that folder. The cryptic looking name will be important later on.

Perform a clean install of Windows 10, then install Mozilla Firefox. Run Firefox at least once and exit.

Go to the same folder as above: <your windows system drive>:\Users\<your user>\AppData\Roaming\Mozilla\Firefox\Profiles

Copy the backup you made earlier into that folder.

Now go back one level so you are at: <your windows system drive>:\Users\<your user>\AppData\Roaming\Mozilla\Firefox\
Edit the file "profiles.ini" in that folder.
It should look like :
[General]
StartWithLastProfile=1

[Profile0]
Name=default
IsRelative=1
Path=Profiles/d9jf63k8.default
Default=1
 Change the line "Path=Profiles/d9jf63k8.default" to "Path=Profiles/z8h0c3kh.default"
In the above example, replace the cryptic looking name I have here with the one on your folder from earlier.

Now if you load Firefox everything should be there. Your bookmarks AND extensions, plugins, themes.

It will be as if Firefox was never un-installed, all the while enjoying your CLEAN install of Windows 10!

Tuesday 25 August 2015

Windows done right

Ahhhh, local account on Windows 10, Finally!

I didn't like windows 8 and 8.x's idea of "logging to the netz" method of logging to get full benefit. You could create a local account there though but windows 10 has a lot less restrictions, and apps downloaded will work without signing in. I now have two accounts. One local for most of my stuff, and one connected for the "rest of the stuff". I like this harmony and it works for me; I will use my local more than the connected.

I digress now, my windows digression.

Also after much study on how my windows systems behaved from windows 7 on wards and with prior experience with Windows XP and down, I found something interesting.

I am a gamer, yes I am, I love games, I love the artistic expressions in games, I love the technology and the intrigue. I LOVE DEVELOPING THEM.

So I am naturally going to look for the best gaming experience and I have done so since 1995. In the "good ol' DOS" days I created a config.sys and autoexec.bat combination with menu to select which "mode" I wanted the computer to boot in. Windows 3.1 would load in the "normal" option where as games would load in a different mode and of course would not launch windows 3.1. Wow back in those days it was inconceivable to run big games from windows 3.1.

Transporting to windows 95 and "boot into dos" was used, along with its hardware profile settings for windows based games. Come windows 2k (eew 98, eeww ME, never got those!) it was time for dual booting. So the dual boot menu selected from Linux, Windows Main and Windows Game. Windows XP pro, same thing. Windows 7 pro Same thing (eeww Vista! never got past the technical preview). However in windows 7 pro I noticed something different. Previously I had to re-install windows to get it stable after using it for some time, and to make it work quicker. Windows 7 suffered less so of this problem. Infact after a while I began installing games on Windows 7 Main and comparing it to the Game boot version. No matter how much I used windows 7 main and installed stuff, I was not getting a frame hit difference. It seemed to be much better behaved than previous versions.

Ultimately windows 7 professional became the last windows OS to have multiple copies installed on the same computer, which could be used only one at a time. With windows 10, there will be one instance, and as always, on a separate drive dedicated for OS's only. Finally I can say, going from windows 3.1 up, that you can run games in windows proper. I do not envision needing a reformat, or another boot just for games in windows 10. Too early to say "Windows done right"? Perhaps, but given my experience with OS's for over 20 years from old BBC computers, Amiga's, Linux, DOS, Windows, I am confident that this time, it is going to be how I think it is going to be...Windows done right.

Tuesday 28 July 2015

How to get your FREE Windows 10


You might have heard of Windows 10 coming out. What you may not have heard is that if you have a "qualifying" version of windows installed, you are eligible for a FREE upgrade to Windows 10. This will also depend on whether your system can handle it.

If you have Windows 7 through to windows 8.1, you may have noticed a windows flag that has come up in you notifications area. If you hover your mouse on it it will say "Get Windows 10"
Here is my blog post with a screenshot showing where:
http://techdistillate.blogspot.co.nz/2015/06/something-interesting-has-appeared-in.html

Click on that windows icon and REGISTER your system. When windows 10 gets released, you will be notified.

If you do not have that icon in your task bar and you have a qualifying Windows version then you need to do the following:
1) Perform ALL your updates using windows update.
2) If the windows icon does not appear by the next day following your update perform the steps on this website:
http://answers.microsoft.com/en-us/windows/forum/windows_10-win_upgrade/i-want-to-reserve-my-free-copy-of-windows-10-but-i/848b5cce-958b-49ae-a132-a999a883265b?auth=1

NOTE: It is better to register windows 10 even if you are not sure if you want to upgrade. The simple reason is that once you register, you have up to one year to install it after its release. Hence there is no obligation to install it after you register.
You can to do this by the 29th of July (not long now from time of post!)
If after doing all this you do not see the "Get Windows 10" icon in your notifications area then it is likely that your system has been detected to be incompatible with Windows 10. After the 29th of July 2015, the icon should appear according to Microsoft, to provide you the option to register for Windows 10, but this will not infer that your system has become compatible.

Good luck with your upgrades!

Thursday 4 June 2015

Something Interesting has appeared in my notification area

Something interesting has appeared in the notification area of my windows 8.1 task bar.
Can you spot it in the picture below? -Click on Image to enlarge.

Time to do some backup and prepare!

Monday 11 May 2015

A New Begining

To be precise, a Brand New Begining.

Not long ago I posted this:
End of a fantastic Server 2000-2015

Since then I have been looking at what I can get to replace it. I have a US Robotics Router that serves as the internet gateway, I need a gigabit Ethernet switch (my current one is 100 Mbps), it will draw considerably less power than my Server did, but provide many functionalities that are important for me.

After long tiresome searches and consulting with people who have owned network devices from interested brands, I came across an alien face hugger; Whoops, I mean a Netgear Nighthawk X6 R8000.
Behold:
Ahh the sight and smell of new gear!

In the picture above is the face hugger, along with Belkin surge protector (I need the extra sockets), and a Western Digital 1 TB 2.5" USB 3.0 HDD. Wow what a mouth full that was!

Here is what I wanted:
-Good filtering and well configurable firewall.
-Network sharing my printer.
-Some kind of NAS like functionality to a connected drive.
-God awesome Radio for wireless.
-Built in Gigabit switch

Here is what the Netgear Nighthawk x6 R8000 delivers:
-All of the above.
-THREE RADIOS with the ability to join the 5GHz radios for automatic channel balancing.
-BONUS unexpected awesomeness: I can segment my network between the LAN side and the WAN side!
-BONUS expected(from reading specs) awesomeness: FTP server I can access from the internet as well as internal network.
-BONUS expected(from reading specs) awesomeness: TIVO media server compatible!

If I were asked to describe this awesome face hugger in one word, it would be "Incredible".

I can list and talk about all its features but that would be a large post, so I will only talk about the features important to me. You can read the full awesomeness, eh, I mean specs on the Netgear website.

On my server, one of the cool things I liked was the network segmentation that kept the internet side of the network different to the LAN side of the network. When setting up the netgear router I found that what it called Internet setup is really a WAN/LAN bridge. As a result, the ip addresses need to be different for the router(X6) and your gateway (modem, fiber modem, etc). My US Robotics allows a VLAN to be created which can be on a different network than its own network. What I did was do just that, the VLAN on the USR is on the X6 side of the network(my LAN) and the USR's address is on a different network. The USR itself creates a WAN bridge to the ISP but this is invisible to the X6 and it doesn't care either. So in the internet setup of the X6, I assigned an ip address for the routers network side and a gateway which is the USR's router address. I can still access the USR via the VLAN address for maintenance allowing me to disable internet remote access for security. Connecting wireless devices use the address provided by the X6 via its DHCP and get given the gateway address that is on the USR's lan side.

There is another advantage to this segmentation. I can fully utilise the firewall functions of both routers. More than that, I can setup the FTP service on the X6 and rather than fiddle with its accessibility, I can simply turn on or off the pinhole on my USR. DNS services are provided by the USR, which the X6 happily passes to connecting devices.

It just works, and works wonderfully. I checked the range and found that the 2.4 GHz radio gets me to about 30 Metres, and the 5 GHz radio manages 14 Metres. This is despite having the router placed inside an old concrete building! The 5 GHz range is lower because usually the lower frequency will travel further than the higher frequency, so not even this router can change the laws of physics. However in saying this, the stability and range seriously blows away any wireless devices I have owned.

It was so easy to configure the external hard drive. In fact it was so easy, you just plug it in and that's it, you have network shared drive! The only time you will need to change the work group on the router is if you use a different Workgroup for your windows computers. That is the only thing I changed.

Of course, I know what you are REALLY waiting for, you want to see the un-boxing pictures.
Well, here they are:
First opening of the box

What is sitting underneath the router in the box

Top view straight out of the box. The black strips on the label is my paint program edit so you don't eyeball stuff where it says no stuff eye balling. mmk?

Bottom view

Rear view

First power on!

It is now settled in to my place. Shes mine now!


I still miss my Linux sever and it will still return one day, but the Netgear Nighthawk X6 R8000 does a damn good job of replacing it at a considerably reduced power consumption. It is by far the best network product I have ever owned (previously my USR). Well done Netgear with this one! Cant wait to see what they will think of next!

Saturday 2 May 2015

C# Parameters, Value or Reference? -Explained.

C# Pass by Reference vs value

C# is one of my favorite languages with a chief architect that is also my favorite language designer. After working with C# for some time, I know C# pretty well however being an expert in it is something I am yet to achieve. There are so many things to remember about it that you really need a reference nearby. Alternatively you can browse blogs by blog posters posting their experience with the language! The other equation of programming is good design patterns so this brings me to another part of C# that I like. It makes it quite intuitive to implement design patterns such as three-tier Programming Architecture.

Recently I had a discussion with someone about whether C# passed by reference or value. It isn't a simple an answer as one would expect at the onset, however I'll explain with examples.

Firstly what does the C# specification say about parameter passing?
C# specification 1.6.6 (Version 5.0) states that parameters are passed by value. This is where the confusion arises.

Consider:
private void PassByValue(int index)
{
    index = 10;
}
What happens in the above code? The original Index remains unchanged but the index inside the method changes to 10. This is the correct behavior as outlined in the C# Specification.

The confusion arises when we do this:
private void PassByValue(int[] index)
{
    index[0] = 10;
}
What happens in the above code? In the first example and according to the C# specification if not well understood would have you believe that  the array "index" was passed by value, correct. That changing the value inside the method for cell one will not change the original, which is incorrect!

So what happens is that C# passes everything that is not a primitive, implicitly, as reference. If I just left it at that, then that statement is not entirely correct and that is where the confusion arises. When is a value not a value? When it is a reference! The array is actually a reference to memory location and when you pass the array to the method, you are passing the "value" of that reference to the method. Hence when you change a "cell" inside the array, you are changing the value pointed to by the reference. Since the original reference is not broken this change is reflected in the original. However if you changed the "value" i.e you changed the reference which was passed by value, you are breaking that therefore the original remains unchanged and you are working on a "new" reference.
Hence if you did this:
private void PassByValue(int[] index)
{
    index = new int[1];
    index[0] = 10;
}
In the above code, the reference to the original is broken. You are now working on a new reference and changing this will have no effect on the original. This does not break the C# specification because you passed by value, except in this case that value is the reference. Also the original is not left "dangling" simply because in C#, much like java, an object is never GC'ed if there is still a reference to it (the calling scope in the above example).

In order to maintain the changes you make to an object in C# in the original passed from outside the method, you need to tell C# that you want to pass a reference to a reference and that is done using the ref keyword.
The code below:
private void PassByReference(ref int[] index)
{
    index = new int[1];
    index[0] = 10;
}
The code above will reassign the reference the original is pointing to, to the new location created in-scope of the method it was passed to. So cell 0 of the original will show the value changed to 10.
This is also another advantage of C# over C++. If you did this in C++ you will get a "dangling pointer" where by once the method goes out of scope, the "new" object created inside the method is destroyed, but the original pointer is changed to point to nothing. This also highlights why C# is considered a "safe" language (Chapter 18, Paragraph 1, C# Language specification version 5.0).

If you do not understand this behavior correctly, you will either abuse the use of "ref" and "out" Modifiers or you will create a bug in your code and have trouble finding out and even understanding what went wrong.

Here is another example:
//Class for testing.
public class DataStorage
{
    public string FirstName; //Field
    public string LastName { get;  set; } //Property
}

//The test Method
private void TestCase(DataStorage ds)
{
    ds.FirstName = "John";
    ds.LastName = "Smith";
}
In the above example, the DataStorage instance passed by the caller to the TestCase Method will have its members changed to reflect the new values set by the method. If you print the original in its respective order, it will print "John Smith". It does not matter whether the members of the class are fields, properties, other class instances, they will all behave exactly the same way. Once again, it does not break the C# language specification.

This can also cause problems with 'Deep Copy'. If you created a copy method that that copies all of an objects members and some of them are objects, then the original and the copy will share those objects members. So a Deep copy may end up actually being a shallow copy - oho! a trap! A good way to avoid that is to do a Deep Copy as a clone copy where there is a bit-by-bit copy of the entire object into a new object. This means new references and new locations. It isn't hard to do and you can achieve this in 10-13 lines of code regardless of how many members you have in the object being copied! I use bit-by-bit on any of my objects I want a deep copy on. In saying that, however, I  have rarely needed to use deep copy and good program design can reduce or eliminate its needs. If you find you need to make a Deep copy, maybe it is time to re-evaluate your design and refactor it.

So to summarise, primitives have their values passed, where as objects have their reference passed as value.  In order to assign a new reference to a closure variable (external variable passed to the method) you have to explicitly tell C# this is the intended behavior.


Sunday 19 April 2015

Auckland Harbour Bridge, New Zealand, wired up as a VU Meter

Celebrating the City's 175th anniversary a mobile telecommunications company, 2-Degrees, wired up the bridge with more than a 1000 LED lights. People can request their songs on the 2-Degrees app and then watch it play out on the bridge. This will only stay on until 25th April and runs each week from Thursday to Saturday.

It was truly an amazing sight to behold from the Silo Park Waterfront in Auckland City when I saw this on Saturday the 18th of April. Being there is an amazing experience with the 2-Degrees speaker playing out the tune as it is being rendered in VU meter style on the bridge with cars passing on the bridge. It certainly draws a crowd making for a party like atmosphere which is absolutely spectacular.

Thanks to whoever at 2-Degrees thought this up! and the only thing I can say is, "please Mr Mayor, can we make this permanent?"

Enjoy the short video I took with the best camera in the world (The best camera in the world is the one you have with you; in this case my phone the Nokia Lumia 830).

Saturday 4 April 2015

Blood moon, April 2015

Yay!!
That is how I will start this blog entry.
YAAAAAAA<Kermit>
Excited because I saw the blood moon Luna eclipse this time which I missed last time.

I don't have any special cameras but here are two shots from my Nokia Lumia 830 phone.

Can see the earths shadow covering half of the moons surface.

Can see the blood moon


Saturday 21 March 2015

End of a fantastic Server 2000-2015

It is with great sadness that I have to take my Linux server offline. I monitored the server running 24/7 between the last power bill and the new power bill. The server is no longer sustainable. It will still function as normal for everything else except hosting online services like my web server, network segmentation box, MySQL Server(internal), SVN repository, ad blocker and firewall; which require a 24/7 uptime. In addition I will lose full time operation of MySQL database server, NAS, my own DNS server, and a 24/7 watchdog looking after and logging my connection from any attempts.

I wrote a pretty awesome IPTables firewall script which I constantly updated and I was quite proud of it. Attacking it using linux based nmap, and spoofing showed that it blocked them all. Although not 100% impenetrable(only a fool would think that), it did take care of a lot! It was a nice hobby to apply solid security such as one you might find on business premises in order to understand them better.

The hardware failed some  years ago (I think about 2004) due to bulging capacitors on the motherboard. The motherboard was also from a great company(then) called ABIT. I replaced 12 capacitors with low ESR's and breathed new life into this thing. The power supply also failed later on and I added in a new power supply. It has been going strong since without blinking an eye.

My internet connection will be less secure now by having a direct connection to the internet via my internet gateway. I.e no more secure than someone with a modem connected to the internet.

To compensate, I will begin looking for a router that uses a pinch of power and provides fully configurable proxy and firewall services. To resume hosting my web services and DNS server I will investigate Linode or Azure cloud services to see if that is sustainable.

However this architecture is not out for good. It will return someday! Until then, it will be on demand operation only. I.e I will turn it on when I need it to do something for me.

Until then, so long old friend.  2000-2015


Friday 13 February 2015

BINARY SEARCH.


A wheem away a wheem away a wheem away a wheem away.....In the Searches, the Binary Searches, the Data lurks today.......

The mighty Binary Search, the final part of Part one "Sort and search algorithms using C#"

Lets put it in perspective what it means when operating a binary search on sorted data.
Assume that we have a data set one million long and reading them takes 1 milliseconds.
Lets say that the data we are looking for is roughly in the middle (but we don't know that yet).
That is approximately 500,000 milliseconds or 500 seconds, or 8 minutes 19 seconds and 80 milliseconds. We'll just say 8 minutes 20. This happens because you have to sequentially read the data either from the start or from the back. Each read and compare taking 1 milliseconds.

Can we drop that substantially to a few milliseconds? Yes we can! Enter, the 'Binary Search'.

How this works is rather simple actually. In the initial condition, you find the mid point, start and end indexers. We will call the start and end indexers the left and right index. The data we want to find we will call the "key". We now start our binary search and we do this by first checking the key with the value at mid point index. If key is smaller than the mid indexed value we move the right indexer to one less than the mid index and find the new mid index which sits between the left and the new right index. We then compare the new mid indexed value with the key. If the key is more than the mid indexed value we then make the left index one more than the mid index and find the new mid point index between the new left and the right index. Eventually we will reach a case where left= right and either we have found a match or we return that the record does not have the value searched. We are essentially halving the problem domain at each pass. So how does this look on 1 million data set? Like this:

initial = 1 million.
Problem domain size after 1st pass: 500, 000
Problem domain size after 2nd pass: 250,000
Problem domain size after 3rd pass: 125,000
Problem domain size after 4th pass: 62,500
Problem domain size after 5th pass: 31250
Problem domain size after 6th pass: 15625
Problem domain size after 7th pass: 7813 (we round up the decimal point)
Problem domain size after 8th pass: 3907
Problem domain size after 9th pass: 1954
Problem domain size after 10th pass: 977
Problem domain size after 11th pass: 489
Problem domain size after 12th pass: 245
Problem domain size after 13th pass: 123
Problem domain size after 14th pass: 62
Problem domain size after 15th pass: 31
Problem domain size after 16th pass: 16
Problem domain size after 17th pass: 8
Problem domain size after 18th pass: 4
Problem domain size after 19th pass: 2
Problem domain size after 20th pass: 1 and it is here where we either find the data or we say we cant find it.

If each of the comparisons took 1 milliseconds, then the jobs done in 20 milliseconds. Compare this with a linear search taking 8 minutes 20 seconds.
We also only had to perform 20 passes instead of 500,000 passes.

Now for some code!

 public int BinarySearch(ref int[] array, int key)
 {
    int m = array.Length / 2;
    int l = 0;
    int r = array.Length - 1;
   
    while (l < r)
    {
      if (key > array[m])
      {
        l = m +1;
        m = (l + r) / 2;
       }
       else
       {
         r = m;
         m = (l + r) / 2;
       }
      }
     if (array[m] == key) return m;
     else return -1;
   }

How the code works
At the initial stage m is set to half the array length. "l" and "r" is set to 0 and one less than array length respectively.
The code then enters the while loop which only runs if l is smaller than r. The key is compared with value indexed by m. If bigger, l is one more than the middle indexer other wise r is adjusted to be the index m is and a new m is calculated from the new problem domain range.
Notice that there is no case where key == array[m] in the while loop because for that to happen l == r must be true. If l==r is true the while loop will break before the "if" statement and instead execute the final test of array[m]==key. If this is true the index where the found key is gets returned otherwise return -1(to indicate no key was found).

The pros is that this search is very fast. The con is that the data has to be sorted first. This is the reason also why I put this at the end after talking about sorting algorithms first.

This was the last post for part one. Part two will focus on taking these same algorithms and making them accept all data types including abstract.

Thank you for reading and I hope things were clear.

Previous: Heap Sort part two.
Landing page: Part One.