Thursday, February 23, 2017

At-First-Glance Comparison between Xamarin and React-Native

I am nothing more than a beginner in mobile development, but I am leaving here my impressions after being assigned the task of setting up a dev environment in both Xamarin and React-Native and share what it felt like to create a hello world app and play a bit with the source.



Wednesday, February 22, 2017

Setting up a React-Native dev environment in Windows 10

After days trying, alternating sighs with enthusiastic exclamation marks, I... formatted my computer, threw all my coins in the fountain, and was set to try it for one last time.

This time heavenly miracles agreed to intercede in my favor, so I ended up running the Hello World app.

This post has one sole objective (apart from occasionally hinting that you should only try mobile development (I was assigned the task in my company to try Xamarin before) if you have given up all your dreams about computer science):

Following the official docs instructions should be enough to get you there (the time frame required is, on purpose, not mentioned, neither in their docs nor here. Otherwise no one will ever try it).
You will run into config problems, missing environment variables, but you should be able to get around.

The thing is: the only real successful setting that worked for me is:
  1. Running the app not from another command prompt, as suggested by the docs, but from Android Studio itself. When asked, pick the emulator of your choice
  2. Opening a command prompt, and running react-native start...  and... it works ! (All right, it does not crash fits better)
  3. To "develop", "simply" edit the project's android.js file. 
  4. After editing your js sources, you do not have to shut the emulator, rebuild the app with Android Studio, re-start react-native packager... you can leave all up and running - just hit R + R after focusing in the emulator so the app is rebuilt and refreshed.
Congratulations, we are now on the same boat.
You are welcome to leave a comment advising leading where to.

(I like the complete appocalipytic tone of this post. It came to life after some highly frustrated days :)

Wednesday, February 15, 2017

Why Edit and Continue is not working even though it is marked in Visual Studio ?

Because it is supported only in projects that has framework versions greater or equal to 4.5.1 (from here).

AND - your scenario is likely one of the following:


Tuesday, January 3, 2017

Numbering the result set records in mysql (oracle like ROWNUM)

Here's a nice stackoverflow answer as to how to display row numbers in a mySql query. (I am perplexed how is this a missing feature both in mySql Workbench and in the proprietary sqlYog).

Seems you can declare variables within queries and use them, on the fly. You may need, this, someday.

Thursday, December 22, 2016

Concatenating strings with different writing systems / orientations (RTL, LTR) and forcing the resulting one's orientation to one of them

If you are facing problems in concatenating strings with different writing systems/orientations into a single one (those that are RTL are all moved to the beginning of the string, for instance) - you can find a solution to the problem here.

Basically, you need to prepend to the strings you want to manually change the orientation the unicode character that specifies the orientation of the following piece of text. If you have RTL and LTR strings and do not want the LTR strings to be positioned at the beginning, rather in their proper positions, prepend the unicode character \u200E.

Sunday, December 18, 2016

Reset Visual Studio "Look at these file types" value

private static void Main(string[] args)
{
    RegistryKey regKey = null;

    try
    {
        //HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\14.0\Find
        regKey = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\VisualStudio\14.0\Find"true);

        var filters = regKey.GetValueNames().Where(v => v.StartsWith("Filter"));
        foreach (var filter in filters)
        {
            regKey.SetValue(filter, string.Empty);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("Registry clear for filter keys failed. {0}", ex.Message);
        return;
    }
}

Tuesday, December 6, 2016

Reading Windows Registry values in c#

An example I wrote for retrieving any windows registry value, and return its string representation (some values are stored as byte arrays, some as 4-byte or 8-byte numbers, etc)


private static bool GetRegistryKeyValue(string keyFullPathWithoutRoot, string subKey, out string valueAsStr, RegistryHive rootNode = RegistryHive.LocalMachine, RegistryView registryView = RegistryView.Registry64, bool getNumericValuesInHexaNotation = truebool displayMessageBoxUponErrors = false)
{
    //search a registry key for a given subkey, if found return its value in a textual representation

    /*
     * Note:
     * The Wow6432 registry entry indicates that you're running a 64-bit version of Windows.
     * The OS uses this key to present a separate view of HKEY_LOCAL_MACHINE\SOFTWARE for 32-bit applications that run on a 64-bit version of Windows.
     */


    RegistryKey root = RegistryKey.OpenBaseKey(rootNode, registryView);
    RegistryKey registryKey = null;
    object subKeyValue = null;
    valueAsStr = null;

    try
    {
        //read key
        registryKey = root.OpenSubKey(keyFullPathWithoutRoot);

        if (registryKey != null)
        {
            //get subKey value type (binary, dword, etc)
            RegistryValueKind subKeyValueKind = registryKey.GetValueKind(subKey);
            subKeyValue = registryKey.GetValue(subKey);
            switch (subKeyValueKind)
            {
                case RegistryValueKind.Binary:
                    byte[] byteArray = (byte[])subKeyValue;
                    valueAsStr = string.Join(" ", byteArray.Select(b => b.ToString()));
                    break;

                case RegistryValueKind.DWord:
                    int dword = (int)subKeyValue;
                    valueAsStr = getNumericValuesInHexaNotation ? Convert.ToString(dword, 16).ToUpper() : dword.ToString();
                    break;

                case RegistryValueKind.QWord:
                    long qword = (long)subKeyValue;
                    valueAsStr = getNumericValuesInHexaNotation ? Convert.ToString(qword, 16).ToUpper() : qword.ToString();
                    break;

                case RegistryValueKind.String:
                    valueAsStr = (subKeyValue ?? string.Empty).ToString();
                    break;
            }
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine($"Failed to read {keyFullPathWithoutRoot}\\{subKey} key from registry. {ex.Message}");
        return false;
    }

    return true;
}
private static void TestRegistryReads()
{
    List<Tuple<stringstring, RegistryView>> keys = new List<Tuple<stringstring, RegistryView>>
    {
        new Tuple<stringstring, RegistryView>(@"SOFTWARE\Khronos\OpenCL\Vendors""IntelOpenCL32.dll", RegistryView.Registry32),
        new Tuple<stringstring, RegistryView>(@"HARDWARE\ACPI\FACS""00000000", RegistryView.Registry64)
    };

    foreach (var key in keys)
    {
        string value;
        if (GetRegistryKeyValue(key.Item1, key.Item2, out value, RegistryHive.LocalMachine, key.Item3, displayMessageBoxUponErrors: true))
        {
            Console.WriteLine("---------------------");
            Console.WriteLine($"Key: [{key.Item1}]  SubKey: [{key.Item2}], SubKeyValue: [{value}], Architecture: [{key.Item3.ToString()}]");
        }
    }
}