Posts

aws .net nuget packages

Nuget packages for working with AWS specific services :-

a) AWS DynamoDB -

b) AWS SNS - Install-Package AWSSDK.SimpleNotificationService -Version 3.3.0.28

c) AWS RDS -

d) S3 - Install-Package AWSSDK.S3 -Version 3.3.18.1

e) AWS SNQ - Install-Package AWSSDK.SQS -Version 3.3.3.6

reactjs quick project setup with local server

I have been going around searching for some cli to setup and start development on react app, which can be time consuming. It is not as complete as angular but hey reactjs is really fast. You can just get started with this project here. It support ES6 (via Babel) not typescript.

Remember to get your project started, quickly clone

https://github.com/facebook/create-react-app


Run npm install  (please make sure you have latest npm install

npm install npm@latest -g (basically gives you npx which is required)

To start the local server, run 'npm start'

That's it! Reactjs ready to worked on.

Entity framework core entity - self referential table

Image
Say you have a self referencing table, that looks something like this (Root nodes points to null which signifies end of hierarchical organization.




We defined our Process model using code below :-




Next we need to tell EF our relationship

In the OnModelCreating method, use the following code to define relationship


modelBuilder.Entity().HasMany(p => p.SubNodes).WithOne(p => p.ParentNode).HasForeignKey(p => p.ParentId);

It basically says that we can have many SubNodes, one Parent node - which make sense right. We can have many parent.

Full code can be found here.







This code retrieve all the Process and its child (subnodes)


var result = p.Process.Include(a => a.SubNodes).Include(c => c.ProcessViewingHistory).AsNoTracking().ToList();

The code to pull out all, is show below :-








working with alexa skills - right places to get info

First up, if you're developing from Alexa Blueprint Skill you can change much. Pretty much use it out of the box. For example, Q&A skillset :-

User : How to apply leave?

Alexa : Go to this page, then navigate to ....etc.

That's it.

If you need to call a custom endpoint, you need to create custom skillset which can be found in the Alexa Console.  The right place to get info is from here. This will give you an understanding of AWS Built in intents etc.


Ethereum : Create a greeter

In the ethereum's greeter sample, if you following it here,  it requires user to save the following code into a file, say greetcontract.js


contract Mortal { /* Define variable owner of the type address */ address owner; /* This function is executed at initialization and sets the owner of the contract */functionMortal() { owner = msg.sender; } /* Function to recover the funds on the contract */functionkill() { if (msg.sender == owner) selfdestruct(owner); } } contract Greeter is Mortal { /* Define variable greeting of the type string */ string greeting; /* This runs when the contract is executed */functionGreeter(string _greeting) public{ greeting = _greeting; } /* Main function */functiongreet() constantreturns (string) { return greeting; } }


To run it, you fire up your geth console.

Then type the followings :-

loadScript("greetcontract.js")      // case sensitive

if you get an error saying  invalid account try…

golang - different ways of initializing your struct /class

Different ways of initializing your struct

// Util.go

package main type StringHelper struct { } func (sh StringHelper ) ToUpper() string{ return "TOUPPER"}Different ways of initializing :// 1st var a StringHelpera.ToUpper()// 2nd b := new(StringHelper) b.ToUpper()// 3rdc := StringHelper{} c.ToUpper()I kinda prefer 3rd way of doing it.

golang - getting top libraries used in the community

Click on the following link to get all this info.

building kubernetes on your local machine - docker

Image
In case you would like to build kubernetes on your docker machine, please do the following :-

a) Download and run the following Dockerfile.




b) Next, run the following comand - "docker run -it /bin/bash

c) apt-get update

d) apt-get install rsync

e) go get -d k8s.io/kubernetes

f) cd $GOPATH/src/k8s.io/kubernetes

g) make 


And if all things goes well, you will get the following screen :-





That's it! :)

first golang package

I created my first golang package (library - not an executable). My code which i ripped off the internet can be found here.

https://github.com/appcoreopc/gomath

Then i do a "go get github.com/appcoreopc/gomath" - (without the https) and it gets build and move to a folder called package in Golang environment.

You can try to rebuild it by trying "go install".


using nsubstitute to mock dbset

I thought this is going to be a one off thing until i realized that i have to do this quite often. Using nsubtitute to mock my database layer.

So here are the codes that i wanna share, as i know it is going to be the same (most of the time)


javascript slice vs splice

In English, slice is used to get portion of a string without modifying the original array, for example :-
It takes 2 parameter, start and end. Very different from splice.

Say we have the following array :-

Slice 


a = [1,2,3,4,5]

a.slice(0,1)
[1] // return

a.slice(0,2)
(2) [1, 2] 

a.slice(1,2)
(2) [2, 3]

a => values stay intact

(5) [1, 2, 3, 4, 5]


Splice 

This function takes portion of the string and change original value of your array. Splice accepts

index - which position to start

howmany

optional item to be added into the list

You will also notice that value of a is changed.


a.splice(1,2)
(2) [2, 3]
a
(3) [1, 4, 5]


It is quite different function.