Posts

Showing posts from January, 2019

Aspnetcore 2 getting Http2 to run on krestel

Image
You can get the sample code from here.

Some setup instruction.

git clone https://github.com/appcoreopc/netcoreHttp2.git

Build it and then when you got it running, hit localhost:5001.

If all works fine, you get the following screen layout.




Http2 doesn't only work for https, you can serve it over http using the following command :-









installing pip on linux

If you doing this, this means you don't have python3 install.


To get started all you need to do is :-


apt update

apt install python3-pip 


Then you can proceed to install python based packages using

pip3 install conda 




C# Mismatch between the processor architecture of the project being built "MSIL"

Image
Hitting this error

Warning  There was a mismatch between the processor architecture of the project being built "MSIL" and the processor architecture of the reference "WhatsAppApi, Version=1.0.0.0, Culture=neutral, processorArchitecture=AMD64", "AMD64". 

So i used the following setup / configuration to resolve this issue :-






Fixing up a bunch of .net warnings and solutions

NU1701 Warnings

Example of disabling it.


NU1701



















C++ Passing lambda as function parameter

The following code gives an example of how to pass function code as  lambda parameters.







docker communicating over Http with a docker container

We can talk to docker container via Http port by enabling it using the following command :-
Here, we going to be using REST to talk to docker container via port 2375.

docker -H tcp://0.0.0.0:2375

nuget.config - unauthorized 401 when trying to get nuget packages

I was having some issue with getting nuget packages and getting 401. Then i added nuget.config in my source repository and it has the following configurations :-



The only mistake i made was using an incorrect tags for my <packageSourceCredentials>

This works for me.  Also this is not the only problem, it turn out one of the nuget repository that i have in my configuration no longer 'online' / active. So i have to remove it to get the rest of nuget package working.

FakeItEasy - changing results return for the same method call.

FakeIteasy allow us to specify different results to return depending on your test cases.
In this example,

#3, we are saying we will return this result if called. 

#5, we are saying for the first 2 call, we like a differen results. It has to be said, that the order of code execution is important. 






Libvips :- Getting the libvips binaries for windows

Probably not updated, but you can actually do a quick search on google to get the windows binaries here.

Install Libvips and get the sample code working

Install Libvips


Start the compilation process. First download the source file and then follow compilation instruction.


$ tar xf vips-x.y.z.tar.gz $ cd vips-x.y.z $ ./configure

If you have permission issue, chmod +x configure as we need to make it executable.

$ make $ sudo make install $ sudo ldconfig


Install glib2-dev, pkg-config, build-essential, libexpat1-dev

sudo apt-get install  glib2-dev


Image format support


You might need libjpeg-dev, libp-dev and some other libraries that you required when u run configure.sh above.


If you do not install libraries above, you might get "jpg format is not supported".

Compiling the code
To compile this :- 
try running the following code :- 
pkg-config vips-cpp --cflags --libs`
It will generate something like this :- 
-pthread -I/usr/local/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -L/usr/local/lib -lvips-cpp -lvips -lgobject-2.0 -lglib-2.0


Then all you need to do is append it to g++ -g -Wall example.cc

Final com…

pkg-config - the goodness

Seems like pkg-config is great tool when we're working with c/c++ codes. Normally we will use

pkg-config vips-cpp --cflags --libs
-pthread -I/usr/local/include -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -L/usr/local/lib -lvips-cpp -lvips -lgobject-2.0 -lglib-2.0


To generate list of flags for compilation. This makes life for developer so much easier. It is very time consuming to get the include and object file linked up.

Next, up is the, which show us list of package installed.


 pkg-config --list-all


This list allows us to plug into code above to generate compilation flags for other libraries.











Handing Flurl.Http exception

I found the best way to capture and handle proper http status code from a Flurl.Http Exceptions is by harness its Call.Response property as shown in code below :-








Returning asyn task with tuple value

A quick code to show how we can return multiple values / tuple from async task.





Docker image http API - how to pull down an image using http api

Image
To download or pull down an image you just have to do a POST to the url below :- (please change that to your server name) with an empty ( {} ) json body.

http://YourdockerInstance:2375/v1.35/images/create?fromImage=bitnami/redis:latest


Please checkout my postman post.



creating container using docker http api with port configuration (ExposedPorts and PortBindings)

I was trying to create docker container using http REST service with the option to configure port bindings. The documentation is great but somehow doesn't work as when we post, it has to be really specific / small json footprint is required.

So I use postman for this and post to the following url. I am spinning up a container called MyContainer

http://mydocker-host:2375/v1.35/containers/create?name=MyContainer

You probably will be able to create the container but might not get port bindings to work correctly.

Here are the json that works, after so many tries. I would try to post only those stuff you required to make the change.



docker REST api

To enable docker REST API (essentially all computer that has docker installed, you can open up to the world via REST Api)

Just do a

"docker version", you can see that we have API version 1.35 installed.

Client:
 Version:       17.12.1-ce
 API version:   1.35
 Go version:    go1.10.1
 Git commit:    7390fc6
 Built: Wed Apr 18 01:23:11 2018
 OS/Arch:       linux/amd64


Then exposed your docker REST API via tcp using the following command :- 
sudo docker -H tcp://0.0.0.0:2375
You're ready to interact with it. 
http://cap-docker-poc:2375/v1.35/images/json



azure storage account requires shared access signature

In azure it is not sufficient to create your own storage account, you need to add "shared access signature to it. And then use this settings and append it your file url.

It will look like this, anything appended to intro.mp3 are your shared access key.

Go to Home->Storage Account -> somestorage -> Then you will be able to find "shared access signature"





https://somestorage.file.core.windows.net/audio/intro.mp3?sv=2018-03-28 &ss=bfqt&srt=sco&sp=rwdlacup&se=2019-01-17T14:07:02Z&st=2019-01-17T06:07:02Z &spr=https,http&sig=ij2IGonmAQnp4inkHDRIRiHMFXf1kiZRD7p6IR3sHD0%3D


NU1605 - Project downgrade detected e.g. 'Microsoft.AspNetCore.Mvc.Core, Version=2.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.Core' with identity 'Microsoft.AspNetCore.Mvc.Core, Version=2.0.0.0, Culture=neutral

Bump into this error and i wasn't able to upgrade the version using vs2017.

If you would like to target specific version, you are better off using the following settings. Please reference this in your project, as it can be confusing when Unit Tests are the ones who seems to be issuing this message








React native - Creating circular play button

Image
In this example, i will show you how to create a circular border around play button as shown below :-






The setup is pretty basic :-






The trick is use backgroundColor as white.
BorderWidh is 2. Then you will get the effect shown above.











git checkout, reset and revert

git revert - undo a commit by creating a new commit.

git reset - change the HEAD index without modifying the file if you choose - soft reset. If it is hard reset it is the same.

git checkout - basically goes to a commit and change the file content too.



always merge on a 'throw away branch'

For example, here we wanted git to merge master to development branch to prevent us from making our master branch dirty.


So its always good to resolve conflict on a throw away branch before merging back to master.


(on branch development)$ git merge master (resolve any merge conflicts if there are any) git checkout master git merge development (there won't be any conflicts now)

Typescript mixin and how to use it.

Declaring mixin in typescript




typeConstructor<T = {}> = new (...args: any[]) =>T;
functionHandler<BaseTypeextendsConstructor>(TargetType: BaseType) { returnclassextendsTargetType { isActivated = false; }; }
classUser { name = "" }
consti = Handler(User); constidec = newi


installing python3 on macOs

To install python3
brew install python3

To install pip on macOS
sudo python -m ensurepip

Using Rx.net timer to keep on running until certain condition are met

Here is a simple Rx.Net timer example which keeps on pinging a service url until a condition are met. In this case, if status is running. I think there are many ways to do it. :-





Example to call it :-







git revert specific file

this is by far one of the most important command in git and i need to have to here.

c5f567 is the commit number

-- file1/to/restore  is the file u would like to revert for commit above.

git checkout c5f567 -- file1/to/restore file2/to/restore

Dotnetcore webpi dependencies injection

Think this is something i have forgotten over and over again, doing dependencies injection in Dotnet core webapi service.

All i have to to do look for this method and add whatever services that i'm going to be using :-

publicvoidConfigureServices(IServiceCollection services) { services.Configure(options => { options.CheckConsentNeeded = context => true; options.MinimumSameSitePolicy = SameSiteMode.None; }); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddScoped();// OperationService depends on each of the other Operation types.
}


What's the deal with

a) AddSingleton -> Create a single instance of object to be shared across session. The controller or services use same instance.

b) AddScoped -> Pass the same object if it is the same session

c) AddTransient -> Different object created and pass into controller and services

Controller action not being hit in Dotnet core based app

Debugging tips

a) Check your project sdk - this is a good thing to do in case you just converted your dll or console based application to a webapi based application.

Originally it might look like this



The correct settings :-




b) route - check your route in your controller.



react native element - removing border from your list

In your list control, you have something like this to render your list (gridbox).






This might give you a listbox with some border.

If you want to hide all those border, change your ListItem style to as follows -



<ListItemcontainerStyle={styles.listItemStyle} />


listItemStyle : { borderBottomColor:'transparent' , borderBottomWidth:0 }


Then all your borders in List Item will be removed.

asp.net core - core library

Can't believe it, but these are all the nuget package you need to start building your webapi project.





This will allow you to do all the dirty stuff like



  WebHost.CreateDefaultBuilder(args)
                .UseStartup();


Or start hosting it locally on your command prompt.

C# - Program does not contain a static - Main method for entry point

When working with Async method, you often bump into the following issues. Not all code are made 'async'.

There are 2 workarounds which are shown here.

publicstaticvoid Main(string[] args) {     MyProgram(args).RunAsync().GetAwaiter().GetResult(); }
Or with code below which does not return result (void operation)

publicstaticvoid Main(string[] args) { BuildWebHost(args).RunAsync().Wait(); }
If you're just going to return Task, you can do this 

 public async Task ProvisionService(RequestType requestType)
{
            return await Task.FromResult("ok");
 }


Formatting react-native view like a flexbox

Image
View component is a critical component in react native. Mastering how to style it and its child component are crucial being a react native developer.

Here is a guide to understand and work with flex-box.

To give you an example, in react with the following codes.



It basically lines up your view as shown below :-










react native expo using icon

There are a few icon library supported by Expo which include MaterialIcons or IconsIcons.


To use these libary



import { MaterialIcons } from'@expo/vector-icons';


or


import { Ionicons } from'@expo/vector-icons';


And you can start to render icon of your linkings simply by specifying the name, for example :-


<MaterialIconsname="play-circle-filled"size={50}color="#b0f8ec"/>

This will display a 'play icon'.

<Ioniconsname="md-checkmark-circle"size={32} color="green" />

To get a full list of icon that is supported, you can try using the following link.

install httpie for windows

If there is one thing i like about httpie, is it is easy to install and use (compare to curl)

To get it installed on windows :-

install python and then run the following command

pip install --upgrade httpie

that's it.

getting better at git

Here is an awesome link which allows us to work better with git

http://gitready.com

Setting dotnetcore csproj internally visible to unit test project

Not really sure why i didn't write this down earlier. Instead of placing this settings as an attribute in your assembly, this configuration gives us better option to configure on the csproj level.









microfrontends

Some thoughts about microfrontend architecture.

I thought web component is suppose to solve the issue of making UI footprint (libraries/css/assets) smaller.  Now we have microfrontend which is tech agnostic to solve all this issue. I don't think it is good to use angular/react/vue on the same page because it is going to be hard to integrate.
UI components talks to each other, share styles, assets. You can break up into smaller microservice, for example, cart component or product component. These component needs to talk to each other, unless you're willing to use POES.

Security is another issue. How do you deal with security across microservice?


Plain Old Event system (POES) - allows you to send events to other components. Yes it feels like we're moving back in time. Instead of store based system like redux, we use event system.

Cross framework is going to be important. You need to create your own framework to work with different tech stack.

PWA Support should just be as s…

dotnet new

So you have your dotnet installed, lets say you want to checkout what are the projects template available in your dotnet env.


dotnet new -l 


In my system, i have quite abit installed. Lets say you want to install a new template say Q# template,


dotnet new -i "Microsoft.Quantum.ProjectTemplates::0.3.1811.2802-preview"


when you need to use it, just 

dotnet new console -lang Q#