Posts

Showing posts from 2017

Using Material design with Angular 5

Getting your material installed using the following command, this basically install most of the stuff you need.  :- npm install --save @angular/material @angular/cdk Next make sure you're using the pre-built theme or you can define your own. @ import '~@angular/material/prebuilt-themes/deeppurple-amber.css' ; Next, load the required module in your app module. For example, if you're using import { MatButtonModule , MatInputModule , MatCheckboxModule } from '@angular/material' ; In this line above, we're going to be using material button, input (textarea, etc) and checkbox. Finally we will be applying this to our component, by adding "mat-button" to my button object. < button mat-button ( click )= "save()" > Save </ button > Further application can be found here with the documentation. https://material.angular.io/components/radio/overview

Typescript : How do you clear an array?

Answer :  this.cities.length = 0, given this.cities is your array.

Typescript array and getting error property 'push' of undefined

If you ever bump into this error, well it just you forgot something really basic and the solution is pretty straight forward too. In case, you're wondering why, it is because you didn't initialize it well 'enough' :)

Module cannot find HttpModule

When trying to load ngrx effects into my application, i encountered the following error message - ERROR in src/app/app.module.ts(29,20): error TS2304: Cannot find name 'HttpModule'. Having a closer look, i need to add the following code All i need to do is to include HttpModule into my app.module.ts as shown in code below :-

Working with Angular5 with ngrx - Getting an exception import 'xxxx.ts' is not a module

While working with Angular5/ngrx i got this error "xxxx.ts" is NOT a module.  Didn't really know what the heck is going on. Finally restarting VSCode and ng serve --open i was able to get rid of this error. If anyone still trying out using this example here : https://github.com/ngrx/store, well, it works. You can use this example for ngrx 4 and Angular. It's all good.

Modularizing route into different file using flask blueprint

Flask provides a function call blueprint to help you place / manage your route file into different files. This makes your code more manageable and  modular. Controller.py in different folder / directory. App.py

Flask working with post query string, form data and json post

Flask provides the following method to work with query string, form data and json. For query string use request.args.get('textinput') For Form use request.form.get('textinput') For Post json jsonData = request.json

Modularizing your flask app

For complex and larger flask project, you probably want to structure you application well. for example, ROOT- ---> app.py ---> /tour --->/tour/controllers.py --->/tour/__init__.py ---> /user --->/user/controllers.py --->/user/__init__.py For me, i rather put my starter code into app.py instead of __init__.py so clearly my intention are clearly shown. Sample of my app.py looks like this. This is where i reference my other controllers and hooked up into flask blueprint. Flask blueprint allow us to modularize our app. Sample of my app.py looks as follow :- From line 10 and 11, you can see that i am importing my controllers and modularizing it. My controllers typically looks like this :- Now you can go and browse http://localhost:port/tour

python wheel quick guide

To create a wheel python setup . py bdist_wheel To create your requirements.txt file pip wheel - r requirements . txt To install a wheel pip install some - package . whl

importing python custom library

Trying out custom library in python. I think the better way to write is basically to have different object into a specific file. For example, paymentMethod in a file instead of nested paymentMethod, payee, account into a single py file. Let's say we are creating a custom library called payment and placed it under a folder called payment. First we need to create a "payment" folder. Create a file called __init__.py. a) __init__.py file b) payment.py c) then import it using the following code

Getting windows docker directory mount on your container image

Image
Let's say you want to use docker image as your development machine. So you would like to build a docker container and you like to mount a windows path so your changes can be persisted and directly reflected in your container. Also if you see bloggers are saying you can run something like "docker exec it -v /app:/app" - well there are additional steps require, discussed below :- So you have Windows -->  Docker (Virtualbox) Your VM -> Container Dev_Folder -> Map to VM Box as shared folder -> Mount it using docker -v command Let's map your windows folder first (a shared folder in virtual box) In your virtual box goto Settings -> Shared Folders -> Please note :- this mapping is case sensitive, perhaps i should use all lowercase as a demo. Next, if you open your docker default virtual machine, you should see "miacucinaCms" folder. All this happening before you run your container. Setting up your container To mount thi

Conda environment cheat sheet

Creating environment in conda conda create --name myAppName Listing all your python environment conda env list Activating your environment activate myAppName Enabling pip in this environment conda install -n myenv pip Working with flask command in Windows Start off flask with port 3000 flask run -h localhost -p 3000

Using command prompt to connecting to docker toolbox running on a Window Host

I am trying to automate my container images using script. The GoLang SDK (Docker Engine API) helps but only if i can get into docker shell. So how do I do it? Create a docker machine and then gain access to docker ssh. From there, we can execute any scripts we wants. a) Create a docker machine called " default " - If you already have one, please use this one. :)   docker-machine create --driver virtualbox autodocker b) Executing docker command from Dos Command via docker-machine. docker-machine ssh default "docker run hello-world" This will execute docker command to download an image called 'hello-world'. Longer way to do it. First you run 1. docker-machine.exe env --shell cmd default 2. It gives me alot of info as shown below :- SET DOCKER_TLS_VERIFY=1 SET DOCKER_HOST=tcp://192.168.99.100:2376 SET DOCKER_CERT_PATH=C:\Users\User\.docker\machine\machines\default SET DOCKER_MACHINE_NAME=default SET COMPOSE_CONVERT_WINDOWS_PATHS=tru

AWS Light Sail - connecting using Putty or PuttyGen

How you can use Putty to access Light Sail Linux machine? Go and read up this link. https://lightsail.aws.amazon.com/ls/docs/how-to/article/lightsail-how-to-set-up-putty-to-connect-using-ssh

Registering more developer finger printing for your android development

Image
Let's say you have more than one developer working on your android app. Good news is your can easily set this up using firebase console as shown below. Just thought you want want to know.

android error 12500 - trying to setup google single sign on

If you're hitting this messages and getting error code 12500 then please ensure your emulator supports google play. You emulator would generally ask you to login to gmail account ...blah blah blah.. if you don't get that, it is almost certain you need to install it. :) The funny thing is I have emulator with Android 4.4, SDK 19 ad that doesn't work. So I created another emulator with Android 6.0 (Google API) and SDK 23. Most people don't run into this issue. But if you do, you're sorted now.

facebook single sign on using android sdk

This the best place to get started :- https://developers.facebook.com/quickstarts/124695344865811/?platform=android#

Getting started with Docker Engine API on Windows with Go (Golang)

Make sure you installed 1. Docker ToolBox 2. Go language from Google. 3. Create the following script and call it "listimage.go" 4. Fire up "Docker command prompt". And then run "go run listimage.go". This will list all the image in your current container.

Cloud design pattern

These are pretty common design pattern for cloud pattern. Availability  - End point Availabity - Throttling - Queue resource leveling Database  - CQRS - Event Sourcing - Index Table - Sharding - Cache Aside -

Excel File 0xC020801c issue

I encountered a couple of issue with :- a) DTS_E_CANNOTACQUIRECONNECTIONFROMCONNECTIONMANAGER - Excel Source Failed validation and return error code  0xC020801c. b) Microsoft.Jet.OLEDB.4.0 is not registered. If the driver is not installed, run package in 32bit mode. An OLEDB Service componet :- 0x80040154 description - Class not registered. This really points to 32 bit vs 64 bit incompatibility issues. Solution: Install 64 bit driver or redeploy your SSIS package in 32 bit.

What is the difference between .net core, .net standard and .net framework

Check out this site here and it gives a detail list of comparison :- https://github.com/dotnet/standard/tree/master/docs/comparisons

SSIS - "Microsoft JET Database Engine" error - Hresult: 0x80004005 Description: "Unexpected error from external database driver (1)

Bump into this error a couple of days ago. The root causes - Windows Update. To way to resolve this is look at your windows update and check against Microsoft website to see what is the patch about. For example, KB4041693 provides a list of components affected and possible resolution. If you cannot quickly repair your connection string from Jet to ACE,. then you might try uninstalling windows updates and restart your machine.  This could be different on your machine, there could be additional updates you need to un-installed compare to the list below :- KB4041681 - Windows 7 Update  KB4041693 (Window 8 and Window Server 2012 ) /  KB4041678 (Windows 7 and Win 2008 Server)   - Both stated it will affect Microsoft.Jet driver  SQL-Management studio -> SSIS package -> The specific package -> Report -> All Execution and try to see what other error messages you're getting. Do not focus on the DRIVERS. Re-installing the database driver is the last option. You

android - great resource for working with material design

Should definitely check out this site here to get more information and tips on working with different android components. https://materialdoc.com/components/autocomplete/

Docker - How to configure IIS (Web server) feature in docker image

The following scripts gives an example of how we can configure our windows server to add web server feature into our docker image.

use powershell.exe to run a script with space in its path

If you run into a situation whereby you need to execute a powershell script that has a space in it using powershell.exe. just add a -File parameter in there. Otherwise you will get error message and putting quotes in between the "xxx.ps1" script won't work. Example is shown below :- %SYSTEMROOT%\system32\WindowsPowerShell\v1.0\powershell.exe  -File "%APP%deployControlService.ps1" -projectPath "%~dp0"

Android facebook integration

Getting Android app integrated with facebook application is pretty straight forward. If you follow the guide here, it will guide to from start until end. https://developers.facebook.com/docs/facebook-login/android/ The only point that i would like to emphasis here is, this line of code in "onActivityResult". You will get resultCode = -1 even though you have signed in successfully. That is why, forwarding result to callbackManager is important as it will be able to tell for sure if your user did signed in, signed out or cancel. protected void onActivityResult( int requestCode, int resultCode, Intent data) { super .onActivityResult(requestCode, resultCode, data); callbackManager .onActivityResult(requestCode, resultCode, data); }

Android using theme for your UI development

We're gonna define theme to use in our app. This means we do not have to manually 'write up' a bunch of "style=" attribute and assigned a custom value to it. The only major code change we need to do is in our manifest.xml as shown below :- Declaring theme in manifest  Here we are assigning a theme called AppTheme/NoActionBar (ok maybe its not a good name) Default Styling of UI Component in style.xml Here we have two customer style which we would like to apply to our controls. These are call Widget.TextView.Custom and Widget.Spinner.Customer respectively.    

Trying to run powershell from command and you get - “execution of scripts is disabled on this system.”

First off, you can enable powershell execution script for good. The only problem is powershell comes in 32bit and 64bit. This probably cuz Windows itself allow this. In order to ensure you're able to run powershell in both environment without problem, you need to do the following :- For 32 bit machine Open  C:\Windows\SysWOW64\cmd.exe Execute this line   powershell Set-ExecutionPolicy RemoteSigned For 64 bit machine  Open  C:\Windows\system32\cmd.exe Execute this line   powershell Set-ExecutionPolicy RemoteSigned

Powershell - Creating and unpacking a zip (archieve file)

Here are some way to create an archive Compress-Archive -Path .\bin\ $ targetBuild \* -DestinationPath .\ $ serviceName .zip To add to this archive, use the -update parameter Compress-Archive -update -Path .\deployControlService.ps1 -DestinationPath .\ $ serviceName .zip To unzip your achieve, use the following command Expand-Archive -Path .\ACC.IDS.ControlService.zip -DestinationPath $ servicePath

10 min Android Braintree (Paypal) integration

Braintree is a paypal payment portal which provides sdks for android, ios, .net core to help you pay via paypal. How you do it? There are 3 main steps to do it 1. Add BrainTree Drop-In 2. setup onActivityResult 3. Add Braintree activity to your manifest file. 1. Drop In Drop-in is a quickest way to enable paypal in your app. It handle UI and application from. Say a user clicks on "pay using paypal", it should run the following codes private void OpenDropIn() { DropInRequest dropInRequest = new DropInRequest() .clientToken( mAuthorization ) .amount( "1.00" ) .requestThreeDSecureVerification(Settings. isThreeDSecureEnabled ( this )) .collectDeviceData(Settings. shouldCollectDeviceData ( this )) .androidPayCart(getAndroidPayCart()) .androidPayShippingAddressRequired(Settings. isAndroidPayShippingAddressRequired ( this )) .androidPayPhoneNumberRequired(Settings

git discard un-committed changes

Easy way to do this, with sourcetree, is to open up terminal and then run the following command git clean -df git checkout -- .

.NetCore getting configuration sections

To do that with code, all you need to do is

.Net core HttpClient Proxy with WinHttpHandler

Have to use a proxy with WinHttpHandler that day and here is the code that does it Also not forgetting the proxy class.

Powershell script to detect .Net Core Web Hosting bundle installed

I got hold of a script that helps me to check if .net core web hosting bundle is installed, saves me alot of time. :)

How do you run .net core during deployment / after publishing it.

You must be thinking it is dotnet run?  Nope. The actual answer is dotnet xxxxxx-your-service.dll name I know it's kinda stupid but sometimes i get it wrong.

choclatey supports .netcore installation

Yay! This is really good. Choclatey supports .net core installation.To get started just use the following command. choco install dotnetcore-sdk

EF Core :- Getting request using dbcontext from stored procedure that returns "SELECT"

Let's say i have the following stored procedure, which return results using "SELECT" instead of RETURN. I use the following codes to get results from my stored procedure :- If you're trying to get value from a stored procedure which give back result using "return", you can use this piece of code. That's it! :)             

What : ExecuteSqlCommand not found in EF core?

If you get this, all you need is, LOL ... using Microsoft.EntityFrameworkCore;

Scaffold-DbContext build failed

Image
If you're getting build failed running "Scaffold-DbContext" (as shown below) Then you need to ensure that your entire project build successfully. Not just the project that you're working on. Once you have your project errors all fixed, continue running the scaffold command.

asp.net core error to "could not find file or assembly with custom assembly"

Image
If your .net core project throws an exception saying "could not find file or assembly. File not found". Even though you have added it into the project. To fix this, convert your class .dll into a nuget package. A pix worth a thousands words! :)

asp.net core self hosted application not running

When you run your application, particularly the startup.cs, and if you faces problem hitting into methods such as a) public void ConfigureServices(IServiceCollection services)     Then what you can do is try to go to command line and run "dot net run" to see if you have any exception on the console. Possible reason could be exception trying to load certain dll file that is not there.

Kurbenetes : Retrying. E0611 12:40:36.428003 9060 start.go:133] Error starting host: Error getting state for host: machine does not exist

Image
I face this issue running minikube on Window on my J drive. When i switch it to c drive things seems to be working fine.

webapi streaming

If you need to stream a video from webapi, you can use the following codes. The code is taken from stackvoerflow. I did not write it. If you're using .net core, use the following code. There are loads of sample in the internet, but i think this works well for .net 4.6. You probably need to know that if you not sure exact size of your files, try PushStreamContent. Otherwise, you can just use StreamContent.

HttpStatusCode Details.....

        //         // Summary:         //     Equivalent to HTTP status 100. System.Net.HttpStatusCode.Continue indicates that         //     the client can continue with its request.         Continue = 100,         //         // Summary:         //     Equivalent to HTTP status 101. System.Net.HttpStatusCode.SwitchingProtocols indicates         //     that the protocol version or protocol is being changed.         SwitchingProtocols = 101,         //         // Summary:         //     Equivalent to HTTP status 200. System.Net.HttpStatusCode.OK indicates that the         //     request succeeded and that the requested information is in the response. This         //     is the most common status code to receive.         OK = 200,         //         // Summary:         //     Equivalent to HTTP status 201. System.Net.HttpStatusCode.Created indicates that         //     the request resulted in a new resource created before the response was sent.         Created = 20

differences between dotnet pack vs dotnet publish

dotnet publish build and ensure your application is ready for deployment and ready for runtime - it comes with all the necessary dll, project dependencies. dotnet pack on the other hand, ensure that you application is build as a nuget package and allows your users to pull down only this .dll. Nuget will resolves dependencies but only your dll is packaged and distributed.

my ruby rails cheat sheet

Skip actions  skip_before_action : verify_authenticity_token protect_from_forgery : except => : create Create an API project  rails new my_api --api Create a normal project  rails new blog Create Model  $ bin/rails generate model Article title:string text:text Start server  bin/rails server Controller  bin/rails generate controller Welcome index Running Migration  rails db:migrate Rollback Migration  rake db : rollback STEP = 1

Scaffold-DbContext update existing model if database changes.

Simple and nice answer -> use Force options as shown below :- Scaffold-DbContext "Server=localhost;Database=MyDatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir DataModel - FORCE Anyways if you would like to find out more about that, please jump into the following link .

Installing Ruby 2.4 without Tears on Windows

Image
First we need to 1. Download ruby installer from here , 2. Download msys2 installer  and install it. It is all right if you don't. Step 3 will force you to do it. :) 3. Run ruby installer. At the end of it, installer is intelligent enough to prompt you to install MSYS2. You basically need to go through all 3 option prompted. 1. MSYS base installation 2. MSYS2 System update 3. MSYS2 and MingGW development toolchain Once you have done that, open up command prompt and start installing your gems, for example :- gem install rails.

Scaffold-DbContext context not found error for .net core 2 / net core 1.1.2

I assumed you have already installed a)  Install-Package Microsoft.EntityFrameworkCore.SqlServer b)  Install-Package Microsoft.EntityFrameworkCore.Tools c)  Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design For example, my .net core app is target for 1.1, so Install-Package Microsoft.EntityFrameworkCore.SqlServer -version 1.1.2 Install-Package Microsoft.EntityFrameworkCore.Tools -version 1.1.1 Might need to restart your VS2017, depending on how convulated your project is. I have a simple project that i just created from scratch i don't eve need to restart. For one for the projects, i did restarted my VS2017. You will need to get this packages correctly installed depending on what .net project (.netcore 2, .netcore 1.1) Remember to restart your visual studio, goto Nuget Package Manager console and try running scaffold-dbcontext, for example :- Scaffold-DbContext "Server=(localdb)\.;Database=IDS_ODS;Trusted_Connection=True;" Microsoft.

docker - connecting your host to a container

Image
Phew! Spent a few hours on this and finally i was able to get it right. Task :- Spin up a new docker container running my app and connect to it from my windows host.  Sounds simple enuff, I think the biggest gotcha is setting your application port to "0.0.0.0" instead of "localhost", as shown in diagram below. My app is a .net core app - of course it is, how else would u want to host it in docker. :) Here is my docker file And then i use the following command to spin up my docker. docker build . -t accmicroserve docker run -P accmicroserve (if you do it this way, you might get a random PORT from your container) docker run -p 5000:5000 accmicroserve (here we're saying we're fixed the port to 5000). Your docker instance already started, and ready to go.

weird things can go wrong with asp.net core configuration

Image
Been working on .net core configuration lately and take me a bit longer to wire up this up. When you create the configuration, create a configuration that matches the entire appsettings.json file. For example, We have a configuration called AppConfig which contains a property called BlommbergAimConfiguration.(highlighted in orange) Under this, we have some other tokens settings (highlighted in green) Once you have this, as long as you call Configure (Configuration), any configuration will be populated accordingly.

tls1.2 support in .net core

When you trying to support tls1.2 in .net core or porting existing application from .net 4.6, these might not work :- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; You need to make the change from this to WinHttpHandler. First, you need to install nuget package. Install-Package System.Net.Http.WinHttpHandler -Pre Next you need to run dotnet build (somehow my VS2017 Express wasn't able to recognize this nuget package that i've ran) Once you have done that, you should be able to write this piece of code.

Reactive extesion for .Netcore.

To get it running on your system, just try adding it into your project. Install-Package System.Reactive -Version 3.1.1

async ValueTask gives performance improvement

Instead of using Task, might be good that add a value in what we call by calling ValueTask. It's suppose to be faster. Hopefully i can get some numbers out here. Essentially to call it, just simply use the followings :- async ValueTask TestValueTask ( int d ) { await Task . Delay ( d ); return 10 ; }