Posts

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 this "miacucinaCms"…

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=true
REM Run this command to conf…