Logo

Who is talking?

Archive

Linear Regression – Relation and Prediction

over 2 years ago | Ajay Mittal: R Handbook

A simple linear regression model that describes the relationship between two variables x and y can be expressed by the following equation. y= α + βx+ ε If we choose the parameters α and β in the simple linear regression model so as to minimize the sum of squares of the error term ϵ, we will have the […]

Ubuntu 14.04.2 (32 bit) installation with VirualBox on Windows

over 2 years ago | Gourav Tiwari: easy_software = Agile.find(ruby_on_rails)

In my current project, I happen to work on Windows again (sadly). But there is no point in beating the bush, when you know you have to get the job done anyway. I preferred to embrace constraints and take it up as a challenge.I started exploring options and if you are in similar situation, you may want to follow below steps.Before I proceed, let me share my system configuration:Lenovo latest seriesRAM 8GHard Disk 120GIntel processor 64 bit Crucial part: No admin level accessVMware Player + Ubuntu did not work for meI downloaded and installed VMware Player: http://www.vmware.com/products/playerI picked up Ubuntu 14.04.2 a 64-bit OS: http://www.ubuntu.com/download/desktopThen I got error in installation: SMBus base address uninitialized - upgrade BIOS or use force_addr=0xaddrSince I had no admin level access, I give up here on VMware + UbuntuVirtualBox + Ubuntu worked for me:1. Download VirtualBox x86 version (not amd64)Installation is simple, step-by-step through wizard.2. Download Ubuntu 32-bit3. Create Virtual Machine using UbuntuI just took step-by-step, screenshot, if this helps to someone. Select 'Ubuntu-downloaded-image4. 'Install' rather than 'Try Ubuntu'Now, when setup a new Virtual Machine, Boot from the downloaded Ubuntu 32-bitSelect 'Install' option, which might take extra 10-15 mins but it's worth it. 'Try Ubuntu' will not save anything installed once you log out, I burnt my hands there :( 5. When prompted, select 'Erase data and create partition' since, it's only doing everything in VirtualBox and no harm to your system's configuration.6. Once Ubuntu is installed, you will see 4x3 screen, which is very small for development work. Let's change it.I followed: http://askubuntu.com/a/451879/398044Simply run on terminal:sudo apt-get install virtualbox-guest-dkms \virtualbox-guest-utils virtualbox-guest-x11Then in VirtualBox Settings select 'InsertGuest Addition CD image' Once this is done, restart system.7. Slowness of VirtualBox + UbuntuI noticed the Ubuntu Virtual Machine was very slow, so I enabled 3-D acceleration8. Share folder bi-directional between Windows and VirtualBox's Ubuntu systemRun below command to fix permission denied on 'shared' directory in Ubuntu:adduser xxxxxxx vboxsf 9. That's it!If you are in similar situation, give these steps a try and add more if some steps do not work here.

Delete duplicate records from table in single statement (SQL Server)

over 2 years ago | Sumit Bajaj: Sumit Bajaj's Blogs

Deleting duplicate records is very common requirement therefore multiple options are available to delete duplicate records. However this article provides the solution to delete the duplicate records using single statement.Delete from <TABLE_NAME> where <ID> not in ( select max(<ID>) from TABLE_NAME> group by <DUPLICATE_COLUMN>) For example:Employee table EmpId EmpFullName EmpSalary EmpTitle 1 Sumit Bajaj 5000 Dev 2 Amit 10000 SDev 3 Sumit Bajaj 5000 Dev 4 Priyanka 50000 Mgr 5 Umesh 10000 SDev 6 Umesh 10000 SDev 7 Amit 10000 SDev 8 Geetika 5000 Dev where few records are duplicate and need to be removed.For this table, delete query would be Delete from Employee where EmpId not in (select max(EmpId) from Employee group by EmpFullName)After executing this query you will left with only unique records as shown below. EmpId EmpFullName EmpSalary EmpTitle 3 Sumit Bajaj 5000 Dev 4 Priyanka 50000 Mgr 6 Umesh 10000 SDev 7 Amit 10000 SDev 8 Geetika 5000 Dev Thanks for reading and hope this article helped.

What is 'this' in Javascript?

over 2 years ago | Gourav Tiwari: easy_software = Agile.find(ruby_on_rails)

Disclaimer: This is not a new topic and there are several authors/writers have explained it in various ways. My intention to write this post is to understand it better, in my own words. JavaScript is a mystery language for me. One of the most confusing feature is, what is the value of this in a function. When I learnt it, I found I develop good sense of understanding closures too.Let’s try to understand this behavior. The value of this is dynamic and it depends on how a function is invoked (reference: "JavaScript: The Good Parts”).Method Invocation pattern: When a function is defined as a part of current object’s property and called on the object via ‘.’ (dot), then this always refers to the current object, here is an example:var myObj = {  value: 5,  square: function(){    console.log(this); // this refers to current object i.e. myOb    console.log(this.value); // this.value is 5 here    return this.value * this.value; // return 5 * 5 = 25  }}myObj.square(); // Method InvocationFire up your browser’s (Chrome / Safari / FF) developer tool and see it in action.Function Invocation pattern:  When function can be called without object’s reference, it’s called ‘Function Invocation’. Notice that previously we referenced myObj, when calling square function. Here is a different variation using 'Function Invocation’, pay attention to internalFun():var myObj = {};myObj.square = function(a){  console.log(this); // this is still referring to myObj as here   // we are adding square function, as a property to the myObj  console.log(a); // The value we passed to square function here  var internalFun = function(b){    console.log(a); // value of a is still accessible, ‘closure’ feature    console.log(b); // value of b is what is passed to this internalFun function    console.log(this); // Surprise! It’s not myObj even though it is in ‘closure’,     // instead of window, why?  }  internalFun(a + 5); // Function Invocation: value of a is same, which is passed directly  return a * a; // square value}myObj.square(5) // Method InvocationinternalFun(6 + 5); // Function Invocation, but invoked outside of the closure hence ‘Reference Error: internalFun() is not definedThis is the most confusing nature I saw for this. Why is such a behavior? Let’s look little deeper in console log response.We see that this refers to ‘window’ object. Even though internalFun() is inside square closure, 'it refers to global object’. Reason is, since it is not tied up to any object, it cannot hang in middle :) It needs to reference to something and that something is a kind of ‘default’ in JavaScript language, which is known as 'global object'.Note that if you try to call outside the square closure, you will see internalFun() is ‘undefined'Constructor Invocation: This is more obvious than Function Invocation. When you create an instance of an object, value of this becomes 'new instance'. The object which can be instantiated has to be an 'anonymous function'. Let’s see an example.var MyObj = function(){  console.log(this); // If we invoke directly this function via Function Invocation,                              // it will reference to global object                              // If we invoke via ‘new’, this refers to newly constructed object,                             // in our case ‘squareOfTwo'  this.value = 5;}// adding method to prototypeMyObj.prototype.square = function(a){  console.log(a); // ‘undefined' if not passed as parameter  console.log(this); // this refers to MyObj  var a = (a == undefined ? this.value : a); // get a default value from constructor  return a * a;}MyObj(); // This refers to global object// MyObj.square(); will throw error 'undefined function',// since prototype functions can be accessed by constructors only.squareOfTwo = new MyObj();squareOfTwo.square(2);squareOfFive = new MyObj();squareOfFive.square();Apply Invocation: This is very powerful way to invoke any method on objects, even though those objects may or may not have this method. What will be value of this here? This is the most definitive invocation style where ‘you’ know the value of this and actually you set what would be value of this.‘apply’ is a special method in JavaScript, which takes two parameters, value of this and array of parameters.value of this is null:var add.apply(null, [1,2,3]) // value of ‘this' is passed as null to add function and                                         // [1,2,3] are arguments to add integers.value of this is user defined:var Hello = function(){  this.greeting = 'Hello';  this.message = 'World';}Hello.prototype.sayHello = function(){ return this.greeting + ' ' + this.message; }// ‘this’ will be the object we are applying the function on, e.g. ‘hi'var hi = { greeting: 'Hi', message: 'Buddy!' }Hello.prototype.sayHello.apply(hi); // value of ‘this' we are passing as ‘hi', output: "Hi Buddy!”SummarySo, now I understood that:Method invocation, this refers to current objectFunction invocation, this refers to global objectConstructor invocation, this refers to new objectApply invocation, this refers to the object we pass to apply function Please share your thoughts/feedback/perspectives.

Runit in Docker

over 2 years ago | Rocky Jaiswal: Still Learning

While Docker containers can themselves be run as daemons, I really want my applications to run as monitored services inside (or outside) Docker. This gives me the peace of mind that if the container is running, my app would be running and it is being monitored active ...