Tuesday, June 13, 2017

How do you get id of a record newly inserted into the database with only one query .

In my project I was inserting a project into a database and I need to assign the "id" created when project is inserted into database.

r.db("DatabaseName").table("TableName").insert("Values")


{
"deleted": 0 ,
"errors": 0 ,
"generated_keys": [
"6538d988-f8e8-4ab0-bf71-f363fce91b9f"
] ,
"inserted": 1 ,
"replaced": 0 ,
"skipped": 0 ,
"unchanged": 0

}



The query to insert will provide a response as shown above and we can make use of the generated_keys to use for our purpose.

The database used is rethinkdb and query is written in reql language.



Sunday, June 11, 2017

get in rethinkdb

In rethink db when we want to have a row selected we can make use of this get.

table.get(key) will give us a single row. if there are no documents null is returned.

Saturday, June 10, 2017

Building your C# application

I am going to describe how to create a basic C# console application in which we generate a random number and then guess it.Before diving in I am just giving an introduction on C# and .NET and also which tools we will be using in building this application.

          C# is an object oriented programming language created by Microsoft and it is one of the many languages used along with .NET framework. There is generally a confusion between C# and .NET, I will try to clear this. C# is basically a programming language and we use it along with .NET framework to build applications for Windows and we can also use C# to build applications for other platforms like Linux  by making use of Mono, which is a open source implementation of Microsoft .NET Framework.
          .NET is a framework for building windows applications and web applications and this is not limited to one language. We can use C#, VB.Net, F#, C++, J# and many more like around sixty languages. It has two important components say Common Language Run-time and Class Library. CLR is a virtual machine component and manages execution of .NET programs. Common Language Runtime or CLR is the run-time execution environment of .Net Framework. Converting MS-IL into platform or OS specific code is done by the CLR. CLR is responsible for bringing application to life and its also the CLR’s job to tear down application when its finished executing or if it has an unrecoverable error. CLR actively tracks all the memory a program uses and it knows when the program is finished with memory so it will clean things up and allows program to have enough memory as it runs. 

We make use of an IDE(Integrated Development Environment) to build our application. We use Visual Studio (Community edition) as it is free.

First we should decide the algorithm on how we are writing our program. The algorithm is as follows:

1.Generate a random number .
2.Take input from user.
3.Check whether both are equal.
4.Make user know whether value he entered is greater or lesser than the secret number.
5.Continue steps 2 ,3,4 until guess is correct.
6.If user quits close or else continue from step 1 again.

Get Microsoft Visual Studio installed and Create a new project. In creating new project select Console Application and select location where you want
 to save the project.



Once you click on OK you have a new screen with defaults loaded. We have a program.cs file created for us with an empty main method which is our entry point.


Now we can start writing our application. First we need to generate a random number for this we make use of Random class .


After generating this number we should prompt the user to guess a value.


Now we should check whether the guess and secret number are equal or not. We should do this until user enters the correct value.


We should allow user to play the game until he wants to quit.


now the application is done and we can start using it to play with your friends.

Friday, June 9, 2017

Nancy

Nancy is a light-weight ,low ceremony framework for building HTTP-based services on .NET. It provides a super-duper-happy-path to all interactions.

You might be wondering what the super-duper-path is. Here I will explain things clearly.


  • It just works
  • Easily Customizable
  • Low ceremony
  • Low friction

Thursday, June 8, 2017

Cors

CORS introduces a standard mechanism that can be used by all browsers for implementing cross-domain requests. The spec defines a set of headers that allow the browser and server to communicate about which requests are (and are not) allowed. CORS continues the spirit of the open web by bringing API access to all.

Wednesday, June 7, 2017

how to pass a javascript object to be written to a database

I have an Address object from my user interface like below

Address:{address1:"Franklin",address2:"Warrensburg",adress3:"Missouri}

so as i am sending an object i should be able to capture all the fields.

so i define a class as

public class Address
    {
        public string Address1 { get; set; }
        public string Address2 { get; set; }
        public string Address3 { get; set; }
    }

and now when we get an object ,we get values as follows

["Address"] = new JObject
                {
                    ["Address1"] = _customer.Address.Address1, ===>Franklin
                    ["Address2"]= _customer.Address.Address2, ===>Warrensburg
                    ["Address3"] = _customer.Address.Address3 ===> Missouri
                }

Tuesday, June 6, 2017

Monday, June 5, 2017

Err address in use

this error occurs when we are using a port and try to bind the same port again. I have this error when I was using react and using 9080 port and tried to run server on same port. We have to kill the process first and then we have to bind the port again.

In windows you can use the following command to kill all instances of node server running

taskkill /f /im node.exe

Saturday, June 3, 2017

Use the `defaultValue` or `value` props on select instead of setting `selected` on option error in using react

This error can be solved by making use of select Value={this.state.option} which we are going to use , instead of making use of selected on option values.

Call a function in child component from parent component in React

Consider the following parent component class Parent extends React.Component { constructor(props) { super(props);         thi...