Posts

Showing posts from August, 2016

msqlserver : Cannot open user default database

Image
When you face this issue, some googling will land you on this page . To fix this, all you really need to do is change your default database to master. In your Sql management studio -> connect -> connection properties -> change Connect to database = "master" or some database you have in your local machine and hit connect. It might look something like this. No need to use sqlcmd  to do the dirty job.

Virtualbox adding extra drive to your vm when your storage is getting less

If your virtual vm storage is getting less and you need extra storage space, you need to the the following :- a) power down your virtual machine b) add a new virtual disk (vdi) and store it at a specific folder in your host machine c) power on your virtual machine. d) goto disk management and you will see a prompt asking you to acknowledge the new disk partition e) assigned a drive to it and proceed format that drive. That's all you need to do to add a little extra space to your virtualbox. 

Crappy random issue : The trust relationship between this workstation and the primary domain failed

When your password expired on your virtual box and you get locked out of the network, then you need to go through this process to resolve the issue , Phew! thankfully it only come to haunt you when every 3 months. :) or essentially if it says you already have your machine added to the domain, what you need to do are 1. change your computer to a random workgroup. 2. without restarting, change it to your VALID domain. You will be prompted to key in name and password. 3. restart

dotnetcore serilog using rolling file

serilog is a logging component for .net. To serilog into your project and configure logging from your project configuration file, here's what you need to do. First, you need to install the following packages :- Install-Package Serilog.Extensions.Logging -DependencyVersion Highest Install-Package Serilog.Sinks.RollingFile Install-Package Serilog.Settings.Configuration In your start up,  you need to configure serilog using the following code. Next, just add it in your log factory, Next, see how our configuration file looks like. Here are we telling serilog to log to a folder in c:\temp. Well, that's all you need to do to add serilog into your project.

working with windows certs x.509 and private keys

Image
I guess this is something i don't work with alot and i need to get it in my head. Hence this post. Assumption : in this post i am using dotnetcore to encrypt and decrypt a jwt token. (using jose jwt library). By design x.509 certificates contains only public key. private key are not stored in x.509. By design, public key are stored because it is presented to other external parties. Public key normally comes with extension ".cer", while private keys file ends with ".pfx" (private keys). For a developer, it is essential understand the followings :- a) where you store or getting certificates from - you could be installing your certs to your local certificate repository - that is accessible to you only, local machine - accessible to more users or service account. You can goto mmc-> Add/remove snap-in -> Certificates -> Two steps installation process. first we install our public x.509 cer and then private keys. For info, please click here

retrieve file async over webapi in .dotnet core

WebApi in .Netcore makes it really easy to  retrieve / download file asynchronously. There are 2 different ways to go about this (could be more) but here's my approach a) ActionResult b) FileStreamResult c) CustomActionResult Check out the following codes (a and b - ain't that much of a difference) FileStreamResult is async operation. You will get read chunk by chunk, asynchronously and delivered to client. What about ActionResult? Tricky part would be (c) creating your custom ActionResult to read and send to client. A huge differences to note is that, traditionally we use HttpMessageResponse. But this introduce conversion challenges and with dotnet core, we gonna have a huge incompatibilities issues too. But WebAPI approach to solve this is pretty easy. Take a look at code below :- As you can see, instead of creating you HttpMessageResponse manually, you can just leverage on existing ones. :)

.net core configuration

.net core configuration has changed. there will be no more System.Configuration, instead we're gonna be using Microsoft.Framework.Configuration. :) To summarize how it is different :- a) Read all configuration (file - json, ini and also environment variables) on Startup (Owin's start up) b) Also in startup, save settings of your model using ConfigureServices. You model needs to have exact attribute name c) Expose it in your Controller's constructor via IOptions. So it takes abit of reading to understand what is going on. Lets say i have config.json which contains the following contents : I will create my model to read in these properties as shown here. Finally in my controller, i have my controller and constructor which looks as follows :- That's it! :)

.Net core Owin namespace does not exist

If you run into this, issue after installing nuget packages like install-package Microsoft.Owin.Security.Jwt install-package "Microsoft.Owin.SelfHost" please check if you're looking at version "3.0.1". If it is, then Core5 is not compatible with these libraries. Solution : Stick with dnx451. Just remove the dnx5 in your project.json and it should just look like the following :- "frameworks": {     "dnx451": {       "frameworkAssemblies": {         "System.IdentityModel": "4.0.0.0"       }     }   } That's it! :)

Deep dive Angular2

Just how many directive you know in Angular2? @NgModule @NgModule({ imports: [ BrowserModule ], declarations: [ MyComponent ], bootstrap: [ MyComponent ] }) @Component Control component @Injectable Service as we know it. @Directive Use  this for creating Angular2 directive. What is the differences between directive and component? Directive you can use it along with existing HTML mark up. Component stands by itself. @Pipe

specflow using scenario outline + examples

Image
Specflow scenario outline and example are pretty useful when you have many inputs that you want to test out scenario. For example, a login page, you might have many heaps of user/password combination to try out - maybe to test out different roles, valid / invalid users combination. So you probably need to create a basic scenario outline with example, as shown here :- To create those table separator, just type it out using the pipe character and Specflow will automatically parse for you (will also auto generate test cases for you too). Nothing magically about it.  What my test scenario will do is, fire up chrome and use input provided in the table to login to a system. Its pretty descriptive of what it is trying to do. The only catch is you need to create a model and tied it together. If you take a look at Line #14, this method accepts an object called table. We bind table data into our model called "User" and then we can start filling up our control wi

debugging specflow in general

Debugging specflow is pretty straight-forward. Go to your feature file, .feature, set your breakpoints (by using F9) and then right click on it and select " Debug Specflow scenario ". You should be able to step in and out of your code. If you can't, there could be some issue with project configuration file like dependency injection, logging configuration not setup correctly and mostly project's startup related configuration. It also helps if you can enable Tools->Options->General->Break when exceptions cross AppDomain or Managed/native boundaries. Hope this helps! :)

xgboost tutorial using R

xgboost is gradient boosting tree. To use xgboost in R at least for this tutorial, you need to install it by using the following command install.packages('xgboost) install.packages("Ckmeans.1d.dp") install.packages('DiagrammeR') The workflow for xgboost is pretty straight forward.

Plotting graph using R for dummies

Image
One of the simple way to plot xy graph say, x is a range from 1 to 10 and the same case with Y. So what we will see is a linear graph, Figure 1 Figure 2 Notes about predict function. In R, predict a proxy or middle man which routes to predict.lm or predict.glm depending on what data you're passing in.

unable to retrieve a valid winsat assessment

if you get this message, probably think that you're trying to run some selenium test on  your chronium browser. All you gotta do is upgrade your chrome to a recent version and that's it. :) easy. 

bamboo server fails to execute common task on windows

Suddenly bamboo server fails to run common task on windows like powershell, copy or calling task scheduler. One fine day, i tried logging in to build server using bamboo service account. E.g i might have a service account called "abc" that configure to run as an agent in bamboo. After i used this account, bamboo fails to run basic task in windows. After much troubleshooting, found that Computer->Properties-> Advanced System Settings->Environment Path->User variable contains weird looking PATH. So i decided to remove it. After this, i immediately queue a build and it was working. Hurray! :)

window service will not start ui thread / task

This is kinda dumb post.  :) Bamboo running under a window service will not be able to start your UI related task. That's by design. For example, you might want to run an end-to-end specflow task which utilized chrome driver. And i went through the entire process of using CreateProcessAsUser and CreateProcessWithLogonW which attempts to run a process as a logged on user. CreateProcessWithLogonW is called after i stumble into the following " If this function fails with  ERROR_PRIVILEGE_NOT_HELD  (1314), use  CreateProcessWithLogonW   ".  End results for this :- the process gets created without any user interface, you can pretty much see it in the background. Wasted at least 16 hours trying to work on this, with the same end results. It is a fact that you need a user to be logged on to start UI task. So I decided to do something really simple, get a user to login (for example user abc), create a task using task scheduler (yes very lame indeed)  and then creating a

trying to get bamboo running on window service to start ui process/task/thread

This is kinda dumb post.  :) Window service will not start your UI related task. That's by design. And i went through the entire process of using CreateProcessAsUser and CreateProcessWithLogonW which attempts to run a process as a logged on user. CreateProcessWithLogonW is called after i stumble into the following " If this function fails with  ERROR_PRIVILEGE_NOT_HELD  (1314), use  CreateProcessWithLogonW   ".  End results for this :- the process gets created without any user interface, you can pretty much see it in the background. Wasted atleast 16 hours trying to work on this with same end results.

understanding specflow support for different test framework

Specflow is a BDD testing framework. It can be confusing to work with it. There are some key component that you need to be aware off. 1. SpecRun.Runner - that is used in many of their tutorials and it needs a LICENSE  if you need to use it in production. You probably going to be calling "specrun.exe". Setup is really easy as it is well documented in their tutorials. 2. Specflow.MsTest - this is the tool that you use specflow together with mstest. This is the link where you can grab your nuget package. It is just a simple " Install-Package SpecFlow.MsTest ". Last step in this process is you need to edit App.config to configure code generation for Microsoft. When you SAVE your file, you will be prompted to RE-GENERATE your features. If you have existing test say in specflow runner, it will be over-written and replaced. Your specflow is ms test ready. Run unit test as you normally would in visual studio. 3. Specflow NUnit - Specflow offers support f