Posts

Showing posts from February, 2019

Git restore specific stash file

The see what stash available :- git stash list To restore  git checkout 'stash{0}' -- filename (filename is the file and path your want to restore - so it depends on where you are. 'stash{0}' - the quote here might be needed in some system, (i know it is needed in powershell)

Creating your dotnet global tool

Why do we need this? Well, if you're running standard stuff like nuget (at least at the time of this writing), that's not really compatible across platoform. So you might wanna create a tool that help you. Simple upload it to nugt.org and you're good to go. Create a project using normal dotnet cli  for example, dotnet new console -o myglobalTool Next do you thing! Setup your project (add them) as shown below :- And that's all! Man that was quick.

Go awesome - List of awesomeness

Loads of tools and library that you can indulge  yourself in. https://awesome-go.com

golang - working with readCloser

In so many occasion, in this case, i worked with docker ContainerStats which return a "readCloser" type. To convert this into string, you need the code below :- Sometimes can be tricky trying to figure which object and method to use.      containerStats , err := dc.targetClient. ContainerStats (context. Background (), dc.containerId, false )      buf := new (bytes.Buffer)     buf. ReadFrom (containerStats.Body)     fmt. Println (buf. String ())

setting up minikube on ubuntu 18

If you're install on Ubuntu and getting "Error creating new host: dial tcp: missing address" Or unable to find driver kvm .... .well you came to the right place. First up, yo need to do the following :- sudo apt install libvirt-dev test -d $HOME /go/src/k8s.io/minikube || \ git clone https://github.com/kubernetes/minikube.git $HOME /go/src/k8s.io/minikube cd $HOME /go/src/k8s.io/minikube git pull make out/docker-machine-driver-kvm2 sudo install out/docker-machine-driver-kvm2 /usr/local/bin sudo cp minikube /usr/local/bin && rm minikube Installing minikube (if you installed using apt-get, you might get some weir curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \ && chmod +x minikube Finally installing kubectl sudo snap install kubectl --classic

Working with Docker python Sdk for swarm services

In this example, we are going to create Get instance of a client. (Please make sure you have installed python docker library using pip docker) Get client instance  client = docker.from_env() Create an swarm service using nginx image client.services.create('nginx:latest', None, name="nginx_latest") To scale up (if you only have 1 service running)   client.services.list()[0].scale(3) For more info, please go here. https://docker-py.readthedocs.io/en/stable/services.html

Grpc - Streaming client data to server - for example, centralized loggging use case.

This sample provide a simple code to send data from a client to a server. A typical use case would be centralize logging.

XUnit some important test attribute and filters

Setting unit test priority using Trait Attribute. If you ever needed your unit test to run first before other being run, then you can change the order of execution using [Trait] as shown in diagram below. The higher the value, the higher the priority. I tried this, doesn't seems to work. [ Trait( "Priority" , "1" ) ] // Run last [ Trait( "Priority" , "5" ) ] // Definitely run this first Common filter used are :- DisplayName=MyUnitNamespace.UnitClass.UnitTest1 - Match by exact test name with equal operator DisplayName~UnitTest - Matches any unit test that contains the text 'UnitTest' - with ~ operator DisplayName!=IntegrationTest - Run all the test except those with 'IntegrationTest'   != operator

git show all remote

A couple of ways to show it Shows only remote git branch -r  Shows all local and remote branch git branch -a The most detail view git remote show origin

Setting up etcd on a docker container

You can start up etcd instance using the following command :- I am using bitnami's etcd docker image sudo docker run -d --name etcd-server  -p 2379:2379 -p 2380:2380 --env ALLOW_NONE_AUTHENTICATION=yes --env ETCD_ADVERTISE_CLIENT_URLS=http://0.0.0.0:2379 bitnami/etcd:latest To put some key value into it try using the following command :- Here we are storing a value "Hello World" to key "message" curl http://127.0.0.1:2379/v2/keys/message -XPUT -d value = "Hello world" To get back the value curl http://127.0.0.1:2379/v2/keys/message

dotnetcore list sdk and runtimes

Rather useful tools from dotnet core To list sdk :- dotnet --list-sdks To list runtimes :- dotnet --list-runtimes

golang - print all fields in a s truct

This is how to print out all fields name in a struct. import (      "fmt"      "log" ) type employee struct {     name string     email string } func main () {      a := employee{}     fmt. Printf ( "%+v \n " , a) // To get all the values fmt. Printf ( "%#v \n " , a) } This is the output {name: email:} {name: 'username' ,email:'email@address'}

Golang calling C from golang

Think the code is pretty straight forward. Have your source code in the same folder as shown below and run "go run main.go". That's all you need to do to get your golang code running. The function call is case sensitive. hello.c sum.c

Dotnet test error message: Could not find a test logger with URI or FriendlyName 'logger://teamcity'

Bump into this error trying to get teamcity to run my unit test. To resolve this, i just had to add the following packages in my unit test projects. And then my dotnet core project start to work as expected.

opencover - Using report generator to view your code coverage

Sometimes you might want to try viewing your code coverage report locally on your machine. To do that, you can download report generator   and then unzip it. Then find your opencover.xml and then use the following command to generate html report (index.html) into a directory of your choice. In this example, we are going to generate to a target directory called d:\tmp\ ReportGenerator.exe -reports:opencover.xml -targetdir:d:\tmp Sorry can't provide the screenshot - it is bad, trust me! :)

conan - installing pistache on your ubuntu

Was trying to install 2 libraries, boost and pistache using conan. However, there is no stable version available Getting boost to install wasn't such a big deal. But getting pistache install, I used the following command :- This basically clone and build pistache on my machine and install it into my home directory. conan install pistache/d5608a1@conan/stable --build pistache Create your CMakelists.txt which has the following configuration :- Executing cmake. cmake --build . 

git - restoring file that has been deleted or removed or changed

To get the actual name of tracked files, you can do the following git ls-files (so we know exact path of our files that are being tracked) Next, we will reset file using the following command (always goes to the commit where your file exist - for example if you remove this file at commit "abc123", trying to reset will do you no good. Go to previous commit and run git checkout -- filetorevert  for example, git checkout  ae9beb35694395da48ae7decaae238781e0b2e0e -- /IocRegistrator.cs Note about the path -> please make sure you know where you are ....cuz it is dependent on your current location when restoring.  :)

asp.net core krestel - how do you handle large chunk of data response?

By defining chunksize of your responses during krestle startup :) https://github.com/aspnet/AspNetCore/blob/master/src/Servers/Kestrel/samples/LargeResponseApp/Startup.cs So easy ....

C++ - Using Pistache as your web server.

Please follow the instruction to  compile and install pistache. Pretty straightforward. Compile the code below with the following command :- g++ -g -Wall main.cc  -std=c++11 -I/usr/local/include/ -L/usr/local/lib/ -lpistache -lpthread Then run your code using  ./a.out  In my setup, i need to set LD_LIBRARY_PATH to the folder i used to build pistache, as it required libpistache.so.0 to run. echo $LD_LIBRARY_PATH /home/jeremy/tmp/test/pistache/pistache/build/src Finally goto :-  http://localhost:9080/