Tuesday, August 20, 2013

Sync up model with input field when setting value through Javascript in Angularjs

I was having issue with validation when using the bootstrap-datepicker.js for my angularjs app. The field has "required" text next to it initially and it supposed to go away when the user selected a date. Apparently, angularjs has problem with field being set through javascript instead of entering through the keyboard. When field is set through javascript, it doesn't get sync to the model. I found a work around by creating a directive that force the sync on change.

Here is the directive I am using as a work around.
angular.module('somemodule').directive('forcesync', [
    function () {
        return {
            restrict: 'A',
            require: '?ngModel',
            link: function ($scope, element, attrs, controller) {
                if (!attrs.type || attrs.type !== 'text' || !controller) {
                    return;
                }
                element.on('change', function () {
                    $scope.$apply(function () {
                        controller.$setViewValue(element.val());
                    });
                });
            }
        };
    }]);
Here is how you would use it.
<input forcesync id="date" name="date" ng-model="Date" ng-required="true" type="text" />

Thursday, May 31, 2012

Steps to Create Self Signed Certificate for use with C# Thrift Server and Java Thrift Client over SSL

The C# implementation of Thrift does not have build in support for SSL as of version 0.8.0.27874. It doesn't seems like there is any interest in integrating the two provided solutions, https://issues.apache.org/jira/browse/THRIFT-181 and https://issues.apache.org/jira/browse/THRIFT-66, from the community either. The Java implementation does have support for SSL though.

Unfortunately, I have a need to provide a Thrift service over SSL using C#. I used the solution provided in issue 181.

This is the story on how I went about creating a self signed certificate for the server and client side.

This is what I have on my computer
1. .Net 4.0
2. Java SDK

Create the self signed certificate on Windows
(I am using Windows 7)

1. Open IIS Manager
2. Click on your computer name on the left pane. It should look something like this.
3. Double click on Server Certificates
4. Right click and select Create Self-Signed Certificate
5. Enter "Thrift Self Signed Certificate Demo" or whatever name you want to give your certificate.
6. Export the Certificate by right click on it and select Export.
7. Fill in the file name for the certificate and the password. You should see a pfx file created in your chosen directory. For this demo purpose, my exported certificate file name is ThriftSelfSignedCertificateDemo.pfx Now we have a self signed certificate.

Convert the Certificate to JKS store type

1. For the next couple of steps you will need to have a copy of openssl. If you don't have it then you can download it from http://slproweb.com/products/Win32OpenSSL.html. I downloaded "Win64 OpenSSL v1.0.1c Light" and "Visual C++ 2008 Redistributables (x64)"
2. Open up a command prompt
3. Type in
openssl.exe pkcs12 -in ThriftSelfSignedCertificateDemo.pfx -out ThriftSelfSignedCertificateDemo.pem

4. Enter the password you provided during the certificate export process.
5. Enter in a new password for the PEM file.
6. Next type in
openssl.exe pkcs12 -export -in ThriftSelfSignedCertificateDemo.pem -out ThriftSelfSignedCertificateDemo.p12 -name " ThriftSelfSignedCertificateDemo"
7. Enter the password you provided during the PEM export process
8. Enter in a new password for p12 file.
9. Finally, we are ready to create the jks file. Type in keytool -importkeystore -srckeystore ThriftSelfSignedCertificateDemo.p12 -destkeystore  ThriftSelfSignedCertificateDemo.jks -srcstoretype pkcs12 -deststoretype JKS
10. Enter a password for the new JKS keystore
11. Enter the password you provided when creating the p12 file

Now you have all the necessary certificates for the Java Thrift client ssl and C# Thrift Server ssl.

ThriftSelfSignedCertificateDemo.jks is for the Java client.
ThriftSelfSignedCertificateDemo.pfx is for the C# server.

Monday, April 09, 2012

TopShelf Service won't install

I created a Windows service using TopShelf and for the life of me I couldn't get it to install. I followed the Command Syntax from http://topshelf-project.com/documentation/command-line-syntax/ and the install process ran with no error. But when I did net start myservice, I get "The service name is invalid." After a lot of head scratching, I realized I need to run the install process as an Administrator. Anyway, I put it here just in case someone has the same problem I have.


Saturday, April 07, 2012

Dell XPS 15z active window randomly lost focus

I have been using the Dell XPS 15z for a few months and it has this really annoying bug that drive me crazy. Some how my active window would lose focus and I have no idea why. I look at the task bar and there appears to be no other active window. This is especially frustrating while writing code. After doing a little research, I cut and paste together a little utility that helps pin point the thief. It was Dell quickset.exe util. Further research reveal that the ambient light sensor trigger quickset.exe which in turn steals the focus from the active window. You can read more from this forum, http://en.community.dell.com/support-forums/laptop/f/3518/t/19393785.aspx?PageIndex=3.

Here is the code to my little utility. I didn't come up with the idea nor the code.
https://bitbucket.org/tuesdaysiren/detectfocusstealingprocess/overview

There doesn't seem to be a fix for the problem except taping over the sensor. The only temporary fix is to adjust the back-light by pressing Fn + F6.

Friday, April 06, 2012

Partial declarations of must not specify different base classes

I am working on my first WPF application and I decided to clean up my code and moved all common properties into a  base class for all my user controls. I hit this error, Partial declarations of must not specify different base classes. After a few minutes of head scratching, I found this post,
http://blog.peterlesliemorris.com/archive/2009/07/23/partial-declarations-of-must-not-specify-different-base-classes.aspx, by Peter Morris that fixed the problem. Basically, the base class is declared in the xaml.

Basically, just change your xaml from
<UserControl x:Class="MyApp.MyUserControl" />
to
<local:BaseUserControl
  x:Class="MyApp.MyUserControl "
  xmlns:local="clr-namespace:NameSpace.To.Your.BaseClass"
  />

Yes, I copied the sample from Peter Morris's post.

Thursday, March 08, 2012

RtkNGUI64.exe using 25% of my CPU issue and solution

I had a problem with my computer's fans constantly running because RtkNGUI64.exe was using 25% CPU time continuously. The only way I was able to fix the problem was killing the process. There is a problem with killing the process though. All sound would come through the speaker even when I plug in the headphone. Unfortunately, I am working in an open environment so that is unacceptable. I finally found a solution on dell forum by cheshirecat179. Here is the link to the thread.

The problem has to do with a missing registry key (HKEY_LOCAL_MACHINE/SOFTWARE/SRS Labs/APO). RtkNGUI64.exe looks for a the registry key and since it is not there, it keeps on trying. The solution is to add the registry key.

Here are the steps from the post:
Click the Windows Orb button thing (Start Button)
In the search bar, type regedit
Navigate to HKEY_LOCAL_MACHINE/SOFTWARE
Right click "SOFTWARE" and left click "New", then "Key"
Name it "SRS Labs" (without quotes)  - that's one
Next, right click "SRS Labs", left click "new" then left click "Key" again
Name it "APO" (without quotes)

Saturday, March 03, 2012

How I solved my on board LAN wasn't able to connect above 10 Mbps problem

Yesterday, while trying to use my laptop as a test runner to do performance test, it was only able to connect to the network at 10 Mbps even though the switch and my laptop both support 1 Gbps. All the other machines that were connected to the switch were connecting at 1 Gbps. I tried to do everything including restarting my computer but nothing help. The same laptop was able to connect at 1 Gbps to the switch a few week ago. My boss needed the performance numbers and I was at a lost on what to do. I Google around and landed on this page. The solution is quite simple.
  1. Turn off your computer
  2. Wait a few minutes
  3. Turn it back on
It does sound stupid but it worked like a charm. Don't you wish all computer problems can be solved this way?