Nadav and the wonders of the web


Archive for March, 2008

How to: Get unique device id in C# (Windows Mobile)

Friday, March 28th, 2008

While looking for a full article about this I found out it won’t hurt to have another quick explanation about this process.

Sometimes when creating an application you want some sort of verification about which phone is accessing your service (service-client application). A good way to do this is to use the unique device id.

Now I will explain how we do it, we are going to get a 40 char string that is hashed with an AppString we will provide which will be unique to each and every device, and will be constant for this device and AppString.

First we define the P/Invoke signature:

[DllImport("coredll.dll")]
private static extern int GetDeviceUniqueID([In, Out] byte[] appdata, int cbApplictionData,
                                            int dwDeviceIDVersion,
                                            [In, Out] byte[] deviceIDOuput, ref uint pcbDeviceIDOutput);

Now we are going to define a private static member so we don’t go through the entire process every time we need this and then create it with a public static method:

private static string s_UniqueDeviceID;

/// <summary>
/// Gets the unique device id, this is an unique id of the phone
/// which is hashed with the AppString
/// </summary>
/// <returns>a 40 characters unique id</returns>
public static string GetUniqueDeviceID()
{
    if (string.IsNullOrEmpty(s_UniqueDeviceID))
    {
        // define AppString
        string AppString = "MyAppString";

        // get the byte array for the string
        byte[] AppData = Encoding.ASCII.GetBytes(AppString);

        // some parameters for the native call
        int appDataSize = AppData.Length;
        uint SizeOut = 20;

        // our out parameter
        byte[] DeviceOutput = new byte[20];

        // Call the native GetDeviceUniqueID method from coredll.dll
        GetDeviceUniqueID(AppData, appDataSize, 1, DeviceOutput, ref SizeOut);

        // check that we got something
        if (SizeOut > 0)
        {
            // build text from received bytes
            StringBuilder resultText = new StringBuilder();
            for (int i = 0; i < DeviceOutput.Length; i++)
            {
                resultText.Append(string.Format("{0:x2}", DeviceOutput[i]));
            }

            // set up result
            s_UniqueDeviceID = resultText.ToString();
        }
    }

    return s_UniqueDeviceID;
}

As you can see the AppString can really be whatever we want it to be. the rest is a little work in order to transform it all from bytes to string but that is why we do it only once!

The only important thing I can see about the AppString is that it won’t be null\empty and that it will be constant throughout your application and usage.

Hope this was clear.

Cheers,

Nadav

What Microsoft is doing RIGHT and why open-source is LOOSING

Thursday, March 27th, 2008

It had been a while now that I’m reading about how Microsoft is going down and open-source is going to rule the world. Lately I’ve been giving this issue some thought and wanted to share my conclusions, so here goes:

  1. Scattered resources - Microsoft has many(many!) developers\QA\design… people working for them while open-source projects which has the advantage of being able to recruit "all" the developers in the world actually has much much less than that working for them. What happens is just another example of human nature, when people are not told what to do, they will do what ever they want. This means that we end up with many open-source projects working on the same things. The problem of open-source is not that the resources are limited but that they are unlimited and scattered.
  2. Advertising - There isn’t much to say here which is not self implied, but still, remember that the power of advertisement when it comes to the general public is HUGE.
  3. Where used to it - I know many people trying out Linux or other open-source platforms, but no matter what, what they are looking for is the similarity to Microsoft Windows. Microsoft has us by the *alls here and we can all say "well if we won’t change it, it won’t change" but the poor truth is that people don’t like to try new things and evolve.
  4. Awesome IDE - admit or not, Visual Studio is an amazing program. I don’t think there is another IDE that will compare, that means the developers use Microsoft which means they develop for Microsoft and that means you get the old "I can’t switch to Linux, there are no programs…" argument which is not true but again, people don’t change.
  5. Community - At least when it comes to the community we can say that the BIG open-source projects have a community to match or at least be at the same league of the Microsoft community(the world).
  6. Evolving - We are witnessing the past few years that even a company as big as Microsoft can evolve, maybe not as fast as open-source but we are seeing the Live! Office coming to life and other new projects.
  7. Force in numbers - If you think about it, they’re so big that if you piss them off they can just sit on you.

This reasons and many others bring me to the believe that even though people don’t like Vista and even though it is cool to hate Microsoft we are looking at one big company that is not going anywhere and is actually going to win.

What do you think?

Nadav

The Ultimate Firefox setup!

Wednesday, March 26th, 2008

After writing a post about the best Windows setup I realized the setting up Firefox to max its potential can be just as or even more complicated. So, here I will detail what i believe to be the Ultimate Firefox setup!

Preferences:

Go to Tools->Options

  1. On Main tab - I would set up my download folder here so when I download files they won’t just end up on my desktop. Choose Save files to and browse to the folder of your choosing.
  2. Tabs tab - We’ll use an add-on for this one.
  3. Privacy tab - You might want to mark Always clear my private data when I close Firefox and choose the correct Settings for you. this is good for security reasons.
  4. Security tab - I HIGHLY recommend you use a master password for all your saved passwords, it is really no hassle and adds a very important security layer. Just mark Use a master password.

I didn’t talk about any other thing in the options because the rest of the default values seem fine to me.

Add-ons:

This are add-ons I use and find helpful for fun and productivity.

For setting up specific add-on settings go to Tools->Add-ons->[add-on name]->Options

  1. Download Statusbar - Gives you a small downloads status indication at the status bar.
    After install and restart choose in it’s settings:
    Top right Mini Mode.
  2. Fasterfox - Does different optimizations to your Firefox installation so it will run much faster.
  3. Firebug - This might be the best one in the list. If you are a web developer this is the extension for you, extensive all-web related features. viewing and editing in real time of DOM,CSS,HTML,JS… and a JS console and a view of all requests sent including AJAX requests.
    And what I consider to be the coolest feature, live JS debug with breakpoints !
  4. Flashgot - When combined with a download manager (Flashget\GetRight\DAP…) enables to send to download all links in a page, links marked, building a gallery of picture\video and many many more.
  5. Forecastfox - Weather in your status bar. Personally I change the settings so it will only show icons and just when I hover above one give me more details.
  6. Foxmarks Bookmark Synchronizer - Does exactly what the name says. I use this to keep a backup of bookmarks and at the same time keep my Portable Firefox synched with my standard installation.
  7. IE Tab - Enables viewing of pages using IE’s engine inside Firefox. Very useful for web-developers or just people that use non-standard web sites.
  8. Long Titles - Makes sure that the image tool tips will show completely.
  9. Master Password Timeout - If you wish your master password will expire every so minutes than use this extension.
  10. ProfileSwithcer - Firefox add-on developers or just people that want a clean\different profile for normal usage can install this for a quick and easy switch.
  11. Resurrect Pages - Don’t you just hate it when you go to some site and get the 404 missing error ? Well, this extension lets you view this page from many different web cache archives, can be very useful at times.
  12. Tab Mix Plus - Adds a whole lot of features for the Firefox tabs. I highly recommend going through it’s settings and setting it to your liking.
  13. Update Notifier - Notifies of new updates to the main Firefox program and to add-ons.
  14. Web Developer - A must have for web developers, just get it and explore all the wonderful options. this does not conflict with Firebug, they complete each other.
  15. iFox Smooth - A nice theme I have been using for a while now.
  16. JAJAH Click-to-call - Last but not least, our very own. - adds telephony functionality to your pages with number recognition and other cool features.

I recommend going through each new add-on you install and its various settings options and choosing what is right for you.

Tweaks:

Write at the address bar about:config and now we are going to search for values and change them, if a value does not exist, add it.

This is a little more complicated and dangerous for your Firefox installation so use at your own risk.

I found a few good articles about this specific subject so I will link to them and leave the fame to who ever deserves it.

  1. Link 1
  2. Link 2

– — – — – — – — – — – — —- —- —- —- —- —- —- —- —- –

Hope this helped you.

Tell me what is your ultimate Firefox setup in the comments.

Some credit goes to Lifehacker for ideas.

Cheers,
Nadav

How to: Know if a program was launched on boot

Wednesday, March 19th, 2008

Sometimes you would like to know if your program was launched on the boot of the machine or activated by a user.

Here is a simple way to find just that in real-time.

What I would do to handle cases where the launch on boot is done through a shortcut is one of two options.

  1. If you can, add a parameter to the call of your application and check for it using the args[] in:
    [MTAThread]
    private static void Main(string args[])
    {
  2. Use this post to know how long its passed since boot, check for a minimum period to know that it was started by the user, this is not bulletproof as it might take a while for boot to finish and your app to start but it is a solution when you have to do this.

Got any ideas yourself? let us know in the comments !

Good luck,
Nadav

How to: Get system up time in C#

Monday, March 17th, 2008

I guess this is quite the easy one but the fact is that while I was searching the web for this answer it was very hard to find.

This is something I knew and forgot so it is good that I will have it here for future quick reference.

Just use:

Environment.TickCount

This will return the time in milliseconds that has passed since the last boot.

Quick Note:

I have read here that this might overflow on systems running for a few days, they also give a solution. as I am using this for a Windows Mobile device I don’t have that option. (CF.Net being deprecated and all…)

Hope you found this faster then I did.

Update:

After further looking into this I have found a nice article about how to overcome the overflow problem, here is the solution:

public static TimeSpan GetTimeSinceBoot()
{
    long _newTicks = Convert.ToInt64("0x" + Environment.TickCount.ToString("X"), 16);

    int days = (int) (_newTicks/(1000*60*60*24));
    int hours = (int) ((_newTicks/(1000*60*60)) - (days*24));
    int minutes = (int) ((_newTicks/(1000*60)) - (days*24*60) - (hours*60));
    int seconds = (int) ((_newTicks/1000) - (days*24*60*60) - (hours*60*60) - (minutes*60));
    int milliseconds =
        (int) (_newTicks - (days*24*60*60*1000) - (hours*60*60*1000) - (minutes*60*1000) - (seconds*1000));

    return new TimeSpan(days, hours, minutes, seconds, milliseconds);
}

The ticks represent milliseconds and when I just call the constructor for TimeSpan it doesn’t treats it this way, that is why i am doing all of this.

Good luck,

Nadav

Windows XP tweaks & useful programs - the new computer necessities

Monday, March 3rd, 2008

A couple of weeks ago I got a new computer and after spending quite a while setting it up and collecting all the different programs and little tweaks I like I figured it’s a good idea to make a list of it all.

at the end there’s a bonus!

Programs:

.Net Development:

  1. Resourcer - Enables looking at what’s inside .Net’s binary resource files. - Link
  2. Reflector - Enables looking at assemblies wether they are the .Net assemblies or your own. can be very useful - Link
  3. Guidance Explorer - Contains different guidance lines in regards to .Net development. - Link
  4. TailXP - this is not really geared solely on .Net, this is a tool used to watch a certain text file for changes, this is very useful when watching a text log file change in real time. - Link

General purpose:

  1. Notepad++ - An excellent free text editor. - Link
  2. 7zip - A free zip\rar\7zip(their own) compression\decompression program. - Link
  3. Paint.NET - An open-source photo editing program written in .Net - Link
  4. CDBurnerXP - A very nice program for burning different CD’s\DVD’s.(FREE!) - Link
  5. SharpKeys - I used this little program to change some keys behavior on my laptop’s keyboard. you can use it to change the behavior of most keys on most keyboards - Link
  6. foobar2000 - A music player. The reason I use this music player and not Winamp\Windows media player\ITunes\Whatever are both that it’s FREE and that uses virtually no memory once minimized(in today’s scale). - Link
  7. Firefox - Of course - Link
  8. SyncBack - A very good program for synching different locations including FTP servers.(there’s a free version) - Link
  9. CCleaner - Cleans all temporary locations on your computer and fixes some registry issues. free and very good. - Link
  10. Daemon Tools - A free CD\DVD drive emulation, very useful when downloading an install CD you don’t want to really burn. - Link
  11. WinSCP - Useful for accessing SFTP\FTP servers. - Link
  12. Putty - Simple SSH client - Link
  13. VLC - Good media player(I use it solely for video though it supports audio playback as well) - Link
  14. Gimp - If you are looking for a more professional alternative to Paint.NET but don’t want to pay for Photoshop, The Gimp might be for you - Link
  15. Windows Live Writer - The software I am using to write this posts. - Link
  16. Picasa - My choice for photo organizing. -

Windows tweaks:

  1. You know it when some program crashes(all do eventually) and you get that annoying "Send\Don’t send" message? well, you can set it up so it just shows the error and a close button. This way you won’t click the send by accident.
    Right click My Computer->Properties->Advanced->Error Reporting(at bottom)->Disable Error Reporting. Leave the mark as it is.
  2. Some times you have a simple file you wish to open with Notepad but Windows doesn’t recognize the file type and won’t do this by default, yes, you can fix it manually but that will only help this file type. what I like to do(or at least liked[better idea coming up]) is to add a shortcut to Notepad on the "Send To" list.
    Start menu->Run-> write "sendto"->right click the empty space->new->shortcut->write "notepad.exe"->Next->write "Notepad"->Finish
    And your done! now you can just right click a file and choose sendto->notepad and it will open up with notepad.
  3. A new way I found of doing the previous mentioned tweak is to have a "Open with Notepad" context menu item so you don’t need to go to "send to" the How to is detailed here: Link
    You are probably wondering why then have I wrote here the previous one, the answer is that i think the previous tweak is quite useful for many different usages even if just to remove useless links from the sendto list.
  4. Most people look into choosing a nice desktop wallpaper and a nice screen saver, what they forget about is looking through the power options and setting them to they’re liking. it can be a real pain to leave your computer on at night for a big download and come back the next day to find out it turned itself off after a couple of hours.
    Right click on the desktop->properties->Screen Saver->Power…(at the bottom)
    Go through all the options and choose what’s best for you, if you don’t know what something means leave it as it is.
  5. Using hibernation - If you wish to shut-down your computer but you want it to boot back to the same exact situation that you left it in you can put your computer in hibernation. what windows does when you do this is copy all your current RAM(memory) to the hard-drive and then restore it the next time you boot. I found this most useful with laptops mainly as it shortens boot-up time quite drastically.
    Go to Power as before->Hibernate(tab)->Mark Enable Hibernation(if it’s not already marked).
    If you are using the old\server style of the shut down screen then you have a list view when you choose "Shut down" from the start menu. If this is the case then you will see the hibernation option at the bottom of the list. if you are using the default XP shut down view then you will need to hold down the "Shift" button while viewing the screen and then the standby button will change into hibernate.

    If you are experiencing problems with the boot up after hibernation you can rapidly click a few times on the F8 key just before Windows start loading(right after the BOIS screen is gone). This will open up the boot option screen for windows, you can choose here to boot normally and not from the hibernation data created earlier.

    I would also recommend rebooting the computer the old fashion way at least once every 3-5 days, this is Windows were talking about after all…

Hope you found at least one cool thing here. If there is anything you want me to try and find out for you just say so in the comments and I will give it my best.

Cheers,
Nadav

Ow right… the bonus! - just a free nice game, very cool indeed. - Link
and if you are into shooters and such look into F.E.A.R(I will leave this one for you to find, the multi-player should be free).

Jajah is the VoIP player that brought you web-activated telephony.