Posts

Showing posts from April, 2019

angular ng-template, ng-content, ng-container and ngTemplateOutlet

ng-template - give you a templated layout and supports ngdirective such as ngIf.



<ng-template[ngIf]="showIt"> <div> template world </div> </ng-template>
ng-content - is react context api - ability to transfer markup from parent to child

ng-container - provide a better way to render complex and nested mark up. Please refer to code below for how to use a container.

<ng-container*ngIf="showIt">
<p>come see it </p>
</ng-container>

ng-templateOutlet - use with ng-container, it provide a way to render content conditionally and a way to reuse template if you have repetitive layout or design.



<ng-template#home> Default </ng-template> <ng-template#custom> custom </ng-template>
<ng-container*ngTemplateOutlet="showIt ? home : custom">




angular viewchild and viewchildren

you use viewchild when you want to select a single element and viewchildren for referencing multiple element. There element are normally mounted on a template.




content here!
<div> <div#div> 11111</div> <div#div> 222222</div> <div#div> 333333</div>
<button(click)="run()">Execute</button> </div>

Using Viewchild return single element

@ViewChild("div") divs: QueryList<any>;

Using ViewChildren return multiple element


@ViewChildren("div") divs: QueryList<any>;

Doing a bit of console logging on ngAfterViewInit.



ngAfterViewInit() { console.log(this.divs); }

Trick for faster npm

1. Don't use progress bar by

npm set progress = false

To confirm changes are set

npm get progress


2. Quick way to check if your package dependencies is outdated by issuing command below:
 npm outdated

3. List all dependencies

npm ls --depth=0

4. Inspect package

npm view jquery-package

5. Find package

npm search vue

6. List configuration settings

npm run env | grep npm


7. Run without installation

npx create-react-app my-app







Azure function error : Missing value for AzureWebJobsStorage in local.settings.json

You might get a detail error message  as follows :-

Missing value for AzureWebJobsStorage in local.settings.json. This is required for all triggers other than httptrigger, kafkatrigger. You can run 'func azure functionapp fetch-app-settings ' or specify a connection string in local.settings.json.


The fix, just add this in to your local.settings,json




fakeiteasy :- raising event

Fakeiteasy support mocking by raising event too.

You can easily do so, using the following code construct, WithEmpty (if you want a quick and dirty way of doing things).



This is what your interface looks like :-

xunit record exception : asserting messaging and exception thrown

Probably less used method to work with exceptions. The following code example, shows how you can capture exception and then assert it.

Azure function 2 :- Testing trigger Azure function type

You can easily test out non http Azure function (atleast in V2) easily by posting data to the following url, where ClaimValidationFunction is my function name.

Please note : - don't forget to spell plural case  /functions and not function correctly.


http://localhost:7071/admin/functions/ClaimValidationFunction





Azure function :- Microsoft Azure WebJobs SDK ServiceBus connection string. Empty

Was having Azure function service bus queue issues when i tried to start up my app.

Microsoft Azure WebJobs SDK ServiceBus connection string is empty.

Turn out that Azure Functions requires specific setup in the code and local settings's connection string. Notice that we have to match connection name = Connection="MyServiceBus" below





To out settings file in the connection string section.





docker image for azure function

You can get a ready to go docker image from her :- great stuff!


FROM microsoft/azure-functions-dotnet-core2.0:v2.0.11961-alpha

Azure function : No job functions found

Got this error message, trying to get test my function locally on my Windows machine,

The fix is to add the following property to your csproj files.


netcoreapp2.1
v2

For some reason, running func host start on Windows, will not make your function  visible.
On Linux it is fine.

So I created a empty solution, add in my functions and then press F5 and it works.




azure storage emulator common account

This is the global account used for Azure storage Emulator :-

Account name: devstoreaccount1

Account key: Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==

azure function tool quick start

func init MyFunctionProj cd MyFunctionProj func new - func new --template "Queue Trigger" --name QueueTriggerJS - func new --template "Http Trigger" --name MyHttpTrigger func host start func azure functionapp publish

Git How do you force a normal branch after forking (not doing with pull request)

Strange requirement but in case you still need it..

Lets say you forked a repo and for some reason instead of creating a PR, you wanted to push that as a normal branch.

Please ensure you created a branch first and then check out

git branch mytarget 

git checkout mytarget

git push mynewBranch.git

git branch by commit id

This is great for branch toooo....

git branch branchname

docker service create with port definition doesn't really cut it

When you run a typically docker service create, it might not worked as expected when it comes to publishing port.

Unfortunately this does not happen in docker-compose and docker stack deploy too.

Normally this is how you would create your service. As you might already know, we create a service , add configs and publish port 5003 (host machine) to 80 (container)

Yet this might not work.
docker service create --name myapp --config src=appsettings,target=c:\settings\settings.yml -p 5003:80 -e SETTINGS.SHAREDPATH=c:\settings myapp:image-0297

To force this

docker service create --name myapp --config src=appsettings,target=c:\settings\settings.yml -p mode=host,target=80,published=5003-e SETTINGS.SHAREDPATH=c:\settings myapp:image-0297



Azure function quick start

Please make sure you have installed :- Azure Core Tools 2.xInitialize your project func init MyFunctionProj Create a new function
func new --name MyHttpTrigger --template "HttpTrigger" Other valid templates are :- EventHubTrigger

docker swarm configs

To create a docker swarm config (allows sharing of configuration across application) when you runs a container, these config are 'mounted' into local container folder.

All you need to do is run the following command :-

docker config create "your_config_name" physical_settings_file

Then it will be registered into your system.


Using Configs. 

To use it you can

Manual

docker service create --name redis --config your_config_name redis:alpine With this command, you are placing your settings files on the root of a running container.


With Docker-compose

docker stack deploy --compose-file docker-compose.yml myApplicationDeployment 


This is a windows container deployment on a swarm. And config files will be mounted on c:\Settings with filename settings.shared.yml.







docker http rest - passing in filters into task endpoint

This post show an example how to post query parameters into a dockers REST http service, specifically the swarm service task list.

The code below shows an example :- please replace "lalaland" with the name of your swarm service.

http://my-docker-swarm:2375/v1.35/tasks?filters={"name":{"lalaland":true}}



Azure topic error :- It is not possible for an entity that requires sessions

I think to resolve this, all you need to do is provide a value to message, like so :-



varcontent = "Tradedata" + i; varmessage = newMessage(Encoding.UTF8.GetBytes(content)); message.SessionId = Guid.NewGuid().ToString();

Newtonsoft - how to reliably parse JObject

Giving out some code reliably flatten Newtonsoft JObjet into custom object call JsonNodeValue.
There are 2 main method exposed

- FlattenJsonObject - which is to flatten jobject.

- LookForJsonKey - allow you to search though Json property path / object structure, like
e,g. data.result which basically means root->data->result of your json object.

To use it, you can potentially just do something like so,

var srcObject = objectJson.FlattenJsonObject();

srcObject.LookForJsonKey