Posts

Showing posts from 2016

vscode install offline packages

Image
To install vscode package offline, you need to download those extension by following the resource path as follows :- https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publisher}/extension/${extension name}/${version}/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage Goto https://marketplace.visualstudio.com and browse the extension you're looking for. You probably get something like this :- This gives us the 'publisher' and package name. Finally to get our version number we look at the bottom right corner of the extension repository as shown here. All you need is to fill up the template url above with the right info. Examples extensions you can download are as follow (might be out of date) :- Python extension. https://donjayamanne.gallery.vsassets.io/_apis/public/gallery/publisher/donjayamanne/extension/python/0.5.5/assetbyname/Microsoft.VisualStudio.Services.VSIXPackage Typescript Javascript Grammar https://m

Bye bye Atom - I switching to Visual studio code

Image
After days of trying out Atom with typescript, i finally gave up. Autocomplete (intellisense) is not working and end up losing alot of time. I switch to Visual Stuido code and install 2 main component and I'm good to go - i have all the autocomplete for javascript and typescript that i needed. This not just include javascript method for string like indexOf but also include Angular2's EventEmitter. The component that I installed are :- a) Typescript and Javascript grammar b) Angular 2 typescript snippet by John Papa. Check out my autocomplete. My development time just went up by 200%. ;)

angular2 - 2 ways of getting value from ngmodel

There are 2 ways you can get value from ngModel. In this example, we have an input and whenever you change the text, it will always keeps your value updated. #1. via Get / Set method The first method uses, get and set to get value from model. Whenever a value is set, it triggers a custom event which parent class can listen to. #2 via ngModelChanged Event - If you decided not to do it that way, you can use ngModelChanged event to get value  as illustrated in codes below : #3 Listening to onkeydown events - which will not be discussed here. :)

angular2 bootstrapping causes my @input and @output gone bezerks!

I hate to blog about stupid mistake, especially my own. So I created my AppComponent which loads ResetComponent. Well, everything continue to work except @Input, @Output and EventEmitter. @Input value cannot be assigned from parent to child. @Output doesn't work as event are triggered but not caught by parent. The fix is to remove ResetComponent from Bootstrap like what we have below :- @NgModule({   imports:      [ BrowserModule ],   declarations: [ AppComponent, ResetComponent ],   bootstrap:    [ AppComponent ] }) export class AppModule { }

Angular2 Components - Did you know that these are valid when defining Angular2 @Component

       selector: undefined,         inputs: undefined,         outputs: undefined,         host: undefined,         exportAs: undefined,         moduleId: undefined,         providers: undefined,         viewProviders: undefined,         changeDetection: ChangeDetectionStrategy.Default,         queries: undefined,         templateUrl: undefined,         template: undefined,         styleUrls: undefined,         styles: undefined,         animations: undefined,         encapsulation: undefined,         interpolation: undefined,         entryComponents: undefined

Adding images to readme.md in github

You can use the following text to include images to readme.md as shown below :- ![alt tag](http://url/to/img.png) To get the url, well that's abit tricky. There is a quick way to get the link to image. All you have to do is browse github to your image. Click on that image and your browser will load. At this point, copy this link and paste it to the command text above and you get your image. Easy stuff!:)

npm unable to start - getting TS2304 error

One fine day, i tried to start my project with npm start and bump into this error :- node_modules/@angular/common/src/directives/ng_class.d.ts(46,34): error TS2304: Cannot find name 'Set'. Yes it is a typing error and just issue the following command to fix it. npm install --save-dev @types/core-js Try npm start again.

Asp.net core integration with angular2

This is a tutorial to get your aspnet core project integrated with Angular2.  I'm using VS2015 community edition. Code can be download from  here . Press F5 and browse to http://localhost/index.html to see your Angular2 in action. Long story ......begins. First thing you gotta do is create an ASP.Net core project. Here I just used MVC project and click next till the project is created. I did this because this project automatically includes static files configuration in the owin pipeline. It hard to setup using blank project because you need to get the dependencies right. Next you need to modify startup files to allow serving of index.html static files. Next I created the package.json file. It's pretty much the same as Angular2 Quickstart example. VS2015 might try to resolve project dependencies from now and you probably have to wait for a bit. Add another file called tsconfig. Again copy and paste job. Next create a gulp.js files as shown below :- We

Using Powershell DSC to set IIS recycle time

I have a task to set IIS recycle time to say "5:00:00" am in the morning.  So here is how i do it using Powershell DSC and if you want to find more information about xWebAdministration, you can go here . Sample code I came out with :-

Pretty cool tools for Android development online

Found some pre-tt-y interesting tools online that's helpful for Android development Android asset studio  https://romannurik.github.io/AndroidAssetStudio/index.html Material design palette with sample layout  https://www.materialpalette.com/grey/brown Will be updating from time to time.

android recycleview and fragment

Creating Android Recycleview is pretty straight forward. All I need to do is :- a) Setup Adapter b) Set Layout Let's walk through the process. First we need to include proper information in gradle Then we need to layout our recycleview Now lets create some adapter. Noticed that we our adapter contains a view holder - just think of viewholder as your android row level layout file that has been inflated. We are able to get a reference to our control as shown in the code below :- public ViewHolder (View itemView) { super (itemView) ; title = (TextView) itemView.findViewById(R.id. title ) ; description = (TextView) itemView.findViewById(R.id. description ) ; fullNews = (TextView) itemView.findViewById(R.id. fullNews ) ; } To get it to work we need the code below. All we need here is to configure data adapter and set our layout. Here, I am using DividerItemDecoration that comes with Android. recyclerView = (RecyclerView) view.findViewById(R.id

Android Studio 2.0 start up error : java.lang.NullPointerException

Earlier this week, I had a crash while developing on Android Studio 2.0 and i get NullPointerException trying to restart. It was a really confusing situation. The fix is to edit  Android  Studio\bin\idea.properties  and add the following and restart Android Studio. disable . android . first . run = true

Powershell New-WebServiceProxy giving underlying connection is closed

When using powershell to invoke a webservice using new-webserviceproxy, you might encounter the following message, 'The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. To solve this, all you gotta do is type the following in Powershell. [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true} And then you can go ahead to invoke your web service using something like this $svc = New-WebServiceProxy -Uri 'https://servername:9091/QuoteManager/QuoteManagerService.svc?wsdl' That solved the issue for me.

Owin component : Modifying owin response

Writing Owin component is really easy. Changing response's body content can be tricky. Let's say you need to strip out confidential information from your http/https response before passing it to the client. Sounds pretty easy but tricky at the same time. Key points to note is that :- 1. Must invoke the next owin component in the pipeline before reading response as string. (maybe that's obvious) Try to use filter to control flow to your owin component. As you can see below, code 21, i running a check on Request.Path to prevent application to flow through (modifying anything in my Owin component). 2.When modifying content, you need to set context.Response.ContentType, StatusCode and ContentLength to the size of data you're trying to push across. I used memorystream to channel my output to context.response.body 3. Must use code starting from Line 69 to copy content to context.Response.Body. Your owin pipeline can get pretty unable if you don't do this.

Some malware analysis sandboxes

REMnux: A Linux Toolkit for Reverse-Engineering and Analyzing Malware https://remnux.org/ SANS Investigative Forensic Toolkit (SIFT) Workstation Version 3 http://digital-forensics.sans.org/community/downloads Drakvuf - DRAKVUF is a virtualization based agentless black-box binary analysis system. DRAKVUF allows for in-depth execution tracing of arbitrary binaries (including operating systems), all without having to install any special software within the virtual machine used for analysis. SANS Investigative Forensic Toolkit (SIFT) Workstation Version 3 https://github.com/appcoreopc/drakvuf https://drakvuf.com/ Caine http://www.caine-live.net/page5/page5.html DEFT Linux http://www.deftlinux.net/ PlainSight http://www.plainsight.info/download.html Helix3 http://www.e-fense.com/products.php Paladin Forensic Suite (commercial) https://sumuri.com/software/paladin/

Some malware analysis sandboxes

REMnux: A Linux Toolkit for Reverse-Engineering and Analyzing Malware https://remnux.org/ SANS Investigative Forensic Toolkit (SIFT) Workstation Version 3 http://digital-forensics.sans.org/community/downloads Drakvuf - DRAKVUF is a virtualization based agentless black-box binary analysis system. DRAKVUF allows for in-depth execution tracing of arbitrary binaries (including operating systems), all without having to install any special software within the virtual machine used for analysis. SANS Investigative Forensic Toolkit (SIFT) Workstation Version 3 https://github.com/appcoreopc/drakvuf Caine http://www.caine-live.net/page5/page5.html DEFT Linux http://www.deftlinux.net/ PlainSight http://www.plainsight.info/download.html Helix3 http://www.e-fense.com/products.php Paladin Forensic Suite (commercial) https://sumuri.com/software/paladin/

Some malware analysis sandboxes

REMnux: A Linux Toolkit for Reverse-Engineering and Analyzing Malware https://remnux.org/ SANS Investigative Forensic Toolkit (SIFT) Workstation Version 3 http://digital-forensics.sans.org/community/downloads Caine http://www.caine-live.net/page5/page5.html DEFT Linux http://www.deftlinux.net/ PlainSight http://www.plainsight.info/download.html Helix3 http://www.e-fense.com/products.php Paladin Forensic Suite (commercial) https://sumuri.com/software/paladin/

Some malware analysis sandboxes

REMnux: A Linux Toolkit for Reverse-Engineering and Analyzing Malware https://remnux.org/ SANS Investigative Forensic Toolkit (SIFT) Workstation Version 3 http://digital-forensics.sans.org/community/downloads Caine http://www.caine-live.net/page5/page5.html DEFT Linux http://www.deftlinux.net/ PlainSight http://www.plainsight.info/download.html Paladin Forensic Suite (commercial) https://sumuri.com/software/paladin/

How do you get the Linux version you're working on?

Believe it or not, this does the trick. It's that easy. :) cat /etc/*release

Resource interpreted as Stylesheet but transferred with MIME type text/plain

Image
Getting this error "Resource interpreted as Stylesheet but transferred with MIME type text/plain". Solution : Ensure you IIS is enabled to load "Static Content" - Go to Turn Windows Features on or off and look for static content as show in diagram below :- Once you have installed it, you're ready to go.

MSSQL - Recovering user account when you accidentally delete relevant login account

I had the good experience of removing local domain account (windows authenticated user) from my mssql database and you guess it, i was not able to login at all using windows authenticated users. Instead  of reinstall my database, here's what i did :- a) stop "Sql Server (MSSQL Server service) b) net start mssqlserver /m c) fire up SQL Management studio and login using Windows Authentication. d) Perform recovery process whereby you add relevant users accounts here. e) Restart your MSSQL server service and login. That's it.

R - getting list of libraries installed

to get a list of installed packages in your R, just use the following command :- installed.packages() You can also list core libraries by using the following command installed.packages(priority = "base") "base"  must be lower case. 

Reading css specification

Image
As long as I can remember, i don't really read html / css specifications. Maybe I should get into that habit. Think today is a good start, as i have the know-how to read css specification. was trying to figure out if min-width is applicable to table. Found the answer here. Hopefully no more TLDR thingie ! :)

OpenCover code coverage for .Net Core

Image
I know there are many post out there getting code coverage for .dotnetcore. I'm using opencover to address this needs. In case, you do no want to use opencover and wanted to stick with vs2015 code coverage, you can try to copy  Microsoft.VisualStudio.CodeCoverage.Shim.dll  from  C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\coreclr\  and drop it into your project " bin\Debug\netcoreapp1.0" folder.  Please note : you need to be on VS2015 Enterprise to do this.  To get started, I guess we need to add OpenCover and ReportGenerator for our test projects, as shown in diagram below :- When nuget packge gets restored, we will have some binaries downloaded to our machine and we going to use this to generate some statistics. I think the biggest issue is to getting those command lines work. In dotnetcore, we run test project using "dotnet test" (assuming you are in the test project folder - if not please go there)

Build - the parameter is incorrect

It has been quite sometime since i last blogged. Been really busy trying to get my head around R, data analysis and some of the fun it brings. If you have an issue with Visual Studio 2015 - with the following error message - The input parameter is not correct - it just happened without you doing anything, well - the solution is simply Restart your Visual Studio and then re-load the projects. I think i had this issue because i kept on switching my branch in SourceTree. (i think - reason remains unknown :)) All rite, till next time.

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

git tfs integration

Please get git for tfs from the following location . To clone a repository in tfs just execute the following command, git-tf clone http://your.server.name:8080/tfs  $/sourceToClone Then fire up your favorite git explorer - probably SourceTree. Click on " Clone/New " button and enter the destination path in  the field called " Source Path / Url " Click " Clone" when done. You can see that your tfs repository is cloned. More documentation can be found here .

A quick tutorial for OWASP ZAP tool for beginners

Image
OWASP's ZAP is a security tool and uses a proxy based approach to do its job. And because of this, the first thing we need to setup is proxy LAN settings. Please download OWASP ZAP and then fire it up. Once it is up and running, togo Tools->Options->Local Proxy. Once we have this setup, we proceed to configure your browser's proxy settings. Fire up chrome, got to Advance settings -> Change proxy settings .. -> LAN Settings and under Proxy server, please change "Address" to localhost and port to "8080". Now you're ready to go login to your website and start running scanning. What is happening that any traffic that pass through your browser get analyzed. The advantage of this approach is that, you don't have to setup username/password or oAuth token and a bunch of security stuff. Of course, you can choose and easier approach (but don't have much use case in general) which is to use "Quick start" feature.

Logistic regression

In logistic regression, we trying to get a final outcome which is either, a) TRUE / FALSE b) Between 1 to 0 Perhaps the following equation would paint the picture a little better. y = 1 / e^- (a + b1x1 + b2x2 + x3b3...) As you can see from the equation above, we will be getting a result  0 to 1 or true / false, depending on how you calculate it. We will be using our data earlier and call a very important function in R, glm with family parameter set to binomial as shown below :- And the result is as follows. Here can can see that degree is a strong influence of whether a person gets high salary or not. Residue deviance - is lack of fit of your model taken as a whole. Fisher scoring iteration is to say how a model is estimated. As for the interpretation of results, here is one great link .

Multivariate regression

Multiple regression is just as pretty straight forward too, instead of trying to predict by one variable, we predict by using multiple variable, hence multivariate / multiple regression. In linear regression we use the following formula y = ax + b In multiple regression, we need to figure out collective how are other variables affect outcome of a prediction. So we probably have something like this y = a + x1b1 + x2b2 where y is our outcome b1, b2  is our co-efficient (computed value that are know to influence our model) x1, x1 are values that we input and see the prediction To see how this can be used in R, we will see if salary is influence by age, education. To do this lets use the follow codes : From here, we can see that degree is a strong influence to our salary as compare to age. Too see, how much a person earn with no degree and age 50 we can use compute as follows :- This person would probably earn :  $ 3797.45

Beginner tutorial : Linear Regression in R

Linear regression is a common technique used to show relationship between a predictor and outcome. For example, say you are trying to predict a car acceleration (0 to 100  km) based on its engine house power. You might have a sample data shown below Car horse power       Acceleration per second 100                            120 110                            150 120                            160 150                            170 200                              x Given a car horse power 200 what would its acceleration (value x) be? Linear regression takes a straight line that pass through certain points. It can represented with the following equation y = ax + b Lets use R to help us with prediction Line #5, we can see that we are using R method called lm to create our model. lm(y ~ x) means y is a predicted by using x term. In our case, Y is acceleration per second. X is our horse power. Let try to predict using our model above. As you can see,

Sourcetree - configuring P4Merge tool

Image
P4Merge is definitely one of the best diff and merge tools around. Totally love it although it comes with a 44 megebytes overhead. Go ahead and download it from here .  Then fire up your sourcetree and goto Tools -> Options -> select Diff tab. This is where you can configure P4Merge as your Sourcetree default merge / diff tool. After you have installed P4Merge, you can just select from the drop down box highlighted above.

One of the best post for studying machine learning with R

This is definitely one of the best link to learn about machine learning using R. Although you can follow through the blog, there are some R syntax that you might not be so familiar with :- a) What is the purpose of this command line names(iris) <- c="" code="" epal.length="" epal.width="" etal.length="" etal.width="" pecies=""> This is just for naming your dataset. For example, lets create a list of bird and their size bird <- bird1="1," bird2="5)</p" list=""> Size 1, would probably be sparrow and size 5 would be a larger bird call eagle. Let change this, using names names(bird)[1] <- p="" sparrow="">names(bird)[2] <- eagle="" nbsp="" p=""> Output > bird $sparrow [1] 1 $eagle [1] 5 b) Funny looking operator " %>% " This is a pipe operator import from magrittr. which i

Angularjs Use custom attribute to customize your html behaviour

Sometimes you would like to add custom behaviour to our html markup and have a custom function invoke by it. For example, lets say you're trying to implement google analytics to track specific field that a user interacts with. So we can create a custom directive that push tracking info to google analytics as user interacts with different field. We can easily do that with angularjs directive as demostrated with code below :- We create a normal directive and under the link section (Line #18), we use "on" method to listen to specific html event. For a demo, please click here .

Embedding base64 images to a static html page

This is easier than i thought.  To get started all you need to do is :- 1. upload your image to this link here . 2. copy and paste base64 to your image html image tag as shown below :- Walla... done!

mocking defer object with jasmine

Often you come across deferred object, that looks like the following code. When you're writing unit test, you need to mock out this component. It is also a standard practice to inject external components on your constructor and then we can mock it out. This is how our mock quote service in typescript looks like. We have retrieve, then and catch function. Closer analysis (Line  #8), you can actually see that we're returning some results from then function and it sets data in our main component Line #7, result parameter in then function is a function which we can execute and sets data it needs. This allows us to fake some data -> we provide a fake quoteNumber, With this, we don't really have to use spyOn and we get to set our data as tho it is the real implementation. This is how it all ties together

Angularjs scope lifecycle

Image

chutzpah - jasmine unable find inject

if you're getting some weird message "reference error: inject is not defined", This very likely means required.js is not loading angular mock library for you. To fix that, declare a variable and reference it. import * as mock from "angular-mocks/ngMock"; var load = mock; Yeap, the fix is that simple. :)

Note about requirejs - require, define, shim and config.js

 Just a quick recap of what's theses terms means 1, define - allows you to load module and its dependencies asynchronously. Assuming that your script supports  AMD . 2. shim - allows you to add support for older script that does NOT support AMD. It has a few options like configuring deps, exports, Configuring dependencies - here we are saying we need moduleA and moduleB too. Configuring exports - here we are saying we need moduleA and from now onwards it will be known as ModA. 3. require() is to load modules. define() is to expose functions in a module to promote code reuse.

inject is not defined when running unit test with jasmine + chutzpah

If you face issued with running unit test with error message " inject method not found ", then you might be missing angular-mocks.js in your chutzpah.json configuration file. All you need to do is include it in, like so....

Creating a really basic angular directive with typescript

Image
We're going to build a simple search angular directive using typescript. So it is going to look like this. As you type through, your search text changes. When you hit, search it fakes search results. This is how our typescript look like.  It is not so complicated and extensively documented, in case you have any question. Please spend some time go  through the code. It is as basic as it can get.  Lets walk through anyway.   Line #1 - we import all angular's 1 typings.  Line #5 - we declare an interface ISimpleSearchScope for the scope (this is the $scope - that you would use in angular1), just so we can put some intelli-sense to our code. :) Line #11 - is where we define our SimpleSearchDirective. It inherits from ng.IDirective.  Line #12 - binds a controller to our directive. If we do not do this, Search() function will not work but your, filter expression will {{}}. Just so we know the difference.  Line #14 - controllerAs gives our contr

Mocking angularjs and typescript

First of all, lets get some details straight, 1. ngmock is for mocking angularjs internal components like $scope, $http and other services and that's all it does. 2. mocking typescript, you gotta use something like typemoq . Probably a good place to start as it support npm, bower and nuget out of the box. But you still need to create dummy mock ( base instance of your interface - which is kinda drag! :( In fact if you're going to use something like typemoq, you end up writing manual mock object (literally typing out and implementing the required interface). Perhaps better to use jasmine spy. Let me know what you're thoughts are on this.

Going back to Angularjs 1

Definitely not an expert when it comes  to Angular. This is part of my 1 week learning experience and i hope i pick up as much angular, typescript as a i can. In general, Angularjs1 works in 2 phases :- a) Configuring b) Binding / Runtime During the configuration phases, Angular has concepts like module, controller, services, providers and components (ui components) Typically we worked with App -> Controller -> Services / Factory etc Why use Factory and Value recipes?  Long, long time ago, we have factory and we have values recipes. These becomes the cornerstone for laying down other components in angularjs (again we are repeating ourselves - module, controller, services, providers and components (ui components) Because Angular injects various dependencies. Factory recipes allows :- - Lazy initialization - Leverage on other services from a module or modules - Service initialization Value recipes is something like a key value pair that gives key / value