Dream, not what is, but what can be.

Android app using multiple cloud services / vendors

Created an Android app using Android Studio and Java using Google Cloud Speech API client for speech recognition, IBM Watson Conversation Service for natural language dialog, and Amazon Web Service (AWS) Polly for speech synthesis.

Posted on Thursday, October 05, 2017 6:32 AM


Android Emulator crashes when open [SOLVED]


  1. Start the Hyper-V manager

  2. Select the emulator you are trying to use

  3. Right-click, hit settings

  4. Click processorClick Compatibility

  5. Set checkbox “Migrate to a physical computer with a different processor version”




Posted on Sunday, October 01, 2017 10:07 AM


Universal Windows Platform (UWP) API's from .Net Framework

To get access to the C# API's, add two references to your project:

1) C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
2) C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll (depends on the version of .Net that you're using)

Posted on Tuesday, July 18, 2017 8:52 AM


WPF Allow UI to update within long running method

OnPropertyChanged and Dispatcher do not update within long running method.

This code does!

void AllowUIToUpdate()
{
    DispatcherFrame frame = new DispatcherFrame();
    Dispatcher.CurrentDispatcher.BeginInvoke(DispatcherPriority.Render, new DispatcherOperationCallback(delegate (object parameter)
    {
        frame.Continue = false;
        return null;
    }), null);
    Dispatcher.PushFrame(frame);
}

Posted on Monday, July 31, 2017 10:06 AM


Play multiple audio on multiple channels using ASIO using NAudio

Play multiple audio on multiple channels using ASIO simultaneously using NAudio.

var waveProvider = new MultiplexingWaveProvider(new IWaveProvider[] { this.reader, this.reader1 }, 2);
waveProvider.ConnectInputToOutput(0, 0);
waveProvider.ConnectInputToOutput(1, 1);

this.asioOut.Dispose();
this.asioOut = null;

this.asioOut = new AsioOut(comboBox1.Text);
this.asioOut.Init(waveProvider);

this.reader.Position = 0;
this.reader1.Position = 0;
this.asioOut.Play();

Posted on Wednesday, July 19, 2017 6:31 AM


Visual Studio built in Presenter Mode

Install Visual Studio Productivity Tools

Quick Launch (ctrl + Q). Simply type “PresentOn” and press enter. All of the fonts including code and environment are sized to be appropriate for presenting. When you are done, simply go back to the Quick Launch and type “PresentOff” and everything goes back to normal.

Posted on Monday, April 24, 2017 7:05 AM


Random String


private string RandomString(int length)
{
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    return new string(Enumerable.Repeat(chars, length)
      .Select(s => s[random.Next(s.Length)]).ToArray());
}

Posted on Friday, April 14, 2017 6:30 AM


Web Sockets example

Code for web socket server

    public class MyEchoHandler : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            if (context.IsWebSocketRequest)
            {
                context.AcceptWebSocketRequest(WebSocketRequestHandler);
            }
        }

        public bool IsReusable { get { return false; } }

        //Asynchronous request handler.
        public async Task WebSocketRequestHandler(AspNetWebSocketContext ctx)
        {
            //Gets the current WebSocket object.
            WebSocket socket = ctx.WebSocket;

            await socket.SendAsync(new ArraySegment<byte>(Encoding.UTF8.GetBytes("Connected to the echo server!")), WebSocketMessageType.Text, true, CancellationToken.None);

            WebSocketReceiveResult result = null;

            ArraySegment<byte> buffer = new ArraySegment<byte>(new byte[20480]);
            while (true)
            {
                using (var ms = new MemoryStream())
                {
                    do
                    {
                        result = await socket.ReceiveAsync(buffer, CancellationToken.None);
                        ms.Write(buffer.Array, buffer.Offset, result.Count);
                    }
                    while (!result.EndOfMessage);

                    ms.Seek(0, SeekOrigin.Begin);

                    if (result.MessageType == WebSocketMessageType.Text)
                    {
                        var sr = new StreamReader(ms);
                        var str = sr.ReadToEnd();
                        data = new JavaScriptSerializer().Deserialize<TimingData>(str.Substring(0, str.LastIndexOf("}") + 1));

                        string response = svc.TimingDataPost(data);
                        byte[] toBytes = Encoding.ASCII.GetBytes(response);
                        await socket.SendAsync(new ArraySegment<byte>(toBytes, 0, toBytes.Length), result.MessageType, result.EndOfMessage, CancellationToken.None);
                    }
                    else if (result.CloseStatus != null)
                    {
                        await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Result Goodbye", CancellationToken.None);
                        return;
                    }
                }
            }
        }
    }

Code for web socket client

<body>
<p>
<input id="txtInput" type="text" value="" />
<input type="button" value="Send" id="btnSend" />
<input type="button" value="Close" id="btnClose" />
</p>
<div id="output">

</div>

<script type="text/javascript">
<!-- ws / wss (SSL) -->
var url = "wss://<service>/MyEchoHandler.ashx";

var webSocket = new WebSocket(url);

var inputTextBox = document.getElementById("txtInput");
document.getElementById("btnSend").addEventListener("click", function () { webSocket.send(inputTextBox.value); });
document.getElementById("btnClose").addEventListener("click", function () { webSocket.close(); });

var outputDiv = document.getElementById("output");
function appendToDiv(text) {
var newElement = document.createElement("p");
newElement.appendChild(document.createTextNode("[" + new Date().toLocaleDateString() + "]" + text));
outputDiv.insertBefore(newElement, outputDiv.firstChild);
}

webSocket.onopen = function () { appendToDiv("Socket Opened!"); };
webSocket.onmessage = function (event) { appendToDiv(event.data); };
webSocket.onerror = function () { appendToDiv("Socket error!"); };
webSocket.onclose = function (event) { appendToDiv("Socket closed with message '" + event.reason + "'."); };
</script>
</body>

Posted on Tuesday, February 07, 2017 6:30 AM


Directly editing IIS 7 applicationHost.config configuration file

File is located: C:\windows\system32\inetsrv\config

Making changes in 32 bit app like Notepad ++ saves the file in c:\Windows\SysWOW64\inetsrv\Config so need to copy the file to C:\windows\system32\inetsrv\config.

Restart IIS

Posted on Wednesday, December 28, 2016 6:43 AM


405 error - Method Not Allowed using IIS - Restful service

Make sure you are including the web page file name in the post URL (http://yoursite/app/Page instead of http://yoursite/app)

Posted on Tuesday, December 27, 2016 9:51 AM