Tuesday, August 7, 2018

AngularJs Style Guide

Recent I have come up with my angularJs knowledge shaping up with a style guide. I have found a tutorial to make it possible as follows:

https://github.com/toddmotto/angularjs-styleguide

it may help me or someone later :)

Saturday, July 21, 2018

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithDexBuilderForDebug'. > java.io.IOException: Could not delete path

I was working in a ReactNative project and while setting up it's environment was getting error as follows:

FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ':app:transformClassesWithDexBuilderForDebug'. > java.io.IOException: Could not delete path


After removing the build directory from root directory -> android -> app 

it just did the trick :)

Error: Incompatible HAX module version 3, requires minimum version 4 in Android Studio


Sometimes it is needed to create virtual device while working on android studio that I did on working in an android project. But when tried to launch the device some errors occurred as follows:

Emulator: Incompatible HAX module version 3, requires minimum version 4
Emulator: No accelerator found.
Emulator: failed to initialize HAX: Invalid argument

So found the solution to sort this out as follows:

Steps:

Android Studio: Tools -> SDK Manager

Under Default Settings:

Appearance & Behavior -> System Settings -> Android SDK:

You should see “Android SDK Location” with text field. Copy that location and search through in your windows explorer. For me the location is: “C:\Users\YourUser\AppData\Local\Android\Sdk” in this location navigate through other segment like: 

\extras\intel\Hardware_Accelerated_Execution_Manager so the full path is: 

C:\Users\YourUser\AppData\Local\Android\Sdk\extras\intel\Hardware_Accelerated_Execution_Manager

And there find the file name “intelhaxm-android.exe” and click on it to install. 

After installing it launch again the AVD device.

Cool! It’s done J

Wednesday, July 18, 2018

Sort array of objects by property name in javascript

I was working with javascript sort method to sort out an array of objects with a scenario like I needed to sort by object property 'name' but using only sort method didn't fullfill my requirements so I came with additional method implemented as a middleware of sort method like below:

Current Result:
const objArray = [
{ name: 'Z', age: 32},
{ name: 'B', age: 23},
{ name: 'C', age: 45},
{ name: 'E', age: 33},
{ name: 'A', age: 53}
];

Expected result:
const objArray = [
{ name: 'A', age: 53}
{ name: 'B', age: 23},
{ name: 'C', age: 45},
{ name: 'E', age: 33},
{ name: 'Z', age: 32}
];

objArray.sort(sortBy('name', false));


function sortBy(key, reverse) {
 var moveSmaller = reverse ? 1 : -1;
 var moveLarger = reverse ? -1 : 1;
 return function(a, b) {
  if (a[key] < b[key]) {
    return moveSmaller;
  }
  if (a[key] > b[key]) {
    return moveLarger;
  }
  return 0;
 };
 
}

It may help someone like me :)

Tuesday, June 5, 2018

Some necessary git commands

While working on git I had to follow some git commands to execute some tasks which are following:

git Add -A //(add to stage)

git commit 'message' //(commit stage files)

git commit -am 'message' //(add to stage and commit stage files in one command)

git push origin branchName //(push all your local changes to production in specific branch)

git branch branchName //(create branch)

git checkout master //(switch branch to master branch)

git merge branchName //(merge specific branch with selected branch)

git pull origin master //(pull changes from master branch from production)

git branch //(list all created branch)

git branch -d branchName //(delete a specific branch)

git checkout -b branchName //(create and switch to a specific branch in one command)

Hope it may helps someone or me later :)

Tuesday, January 2, 2018

More than one DbContext was found while updating sql database in EF

While updating my sql database after adding migration I have got error from console like below:
More than one DbContext was found. Specify which one to use. Use the '-Context' parameter for PowerShell commands and the '--context' parameter for dotnet commands.
because I have two dbcontext in my project. so here is the solution for it if someone face such problem:
Update-Database -Context MyContext1 

Monday, December 25, 2017

How To Delete Child Table's Rows While Deleting Parent Items in Mysql in a Single Request

While working in a php and mysql project I have faced to remove child table's rows while deleting it's parent table's items and here is my solution for such kind of functionality:
 Suppose that I have two tables named user_roles and users:

CREATE TABLE `user_roles` (
      `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
      `name` varchar(64) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

    CREATE TABLE `users` (
      `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
      `name` varchar(128) NOT NULL,
      `address` varchar(255) DEFAULT NULL,
      `email` varchar(128) NOT NULL,
      `password` varchar(64) NOT NULL,
      `role_id` int(11) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;


and below is the code to obtain such above functionality:

    ALTER TABLE users
    ADD CONSTRAINT FK_RoleUser
    FOREIGN KEY (role_id) REFERENCES user_roles(id)
    ON DELETE CASCADE


 so now if you delete any row of table user_roles then all the users related to that role id will be deleted automatically.