Python | Toolbox

Introduction

Update Python Environment

Update all Python packages

pip3 list| cut -f1 -d' '|xargs -I {} pip3 install {} --upgrade

Debugging and Tracing

def tracefunc(frame, event, arg, indent=[0]):
      if event == "call":
          indent[0] += 2
          print "-" * indent[0] + "> call function", frame.f_code.co_name
      elif event == "return":
          print "<" + "-" * indent[0], "exit function", frame.f_code.co_name
          indent[0] -= 2
      return tracefunc

import sys
sys.settrace(tracefunc)

main()

Arduino | Getting started

Introduction

I just want do learn and work with a new technology, so i bought a 3D printer based on an Arduino Mega 2560. (More on this in the following Blog entry)

To be prepared with the Arduino, i want to play with it. So i started with a starter kit and a sensor kit from elegoo.com

Set / Kit für Arduino MEGA2560
Most complete Ultimate Starter Kit with german tutorial, MEGA2560 R3 Mikrocontroller and many additionals for the Arduino Mega2560 R3

Upgraded 37 in 1 Sensor Modules Kit
With english tutorial for the Arduino UNO R3 MEGA 2560 Nano

First Steps

Setup and illuminate the lab

Start with a simple project

After installing and setting up everything, i started with my first small project: Measure the distance with a sonic sensor and display it through a lcd panel: 

Arduino Ultrasonic Sensor with distance displaying on a LCD Panel

Arduino IDEs

Scratch for Arduino

ArduBlock

Appendix

Set / Kit für Arduino – Elegoo MEGA2560

1 x MEGA2560 R3 Mikrocontroller
1 x MB-102 Versuchsaufbau
1 x Prototyp-Erweiterungsplatine
1 x LCD1602 Anzeige(mit Pin Header)
1 x DHT11 Modul
1 x Joystick-Modul
1 x 5V Relais
1 x Schallsensor-Modul
1 x DS3231 Echtzeituhren-Modul
1 x Drehgeber modul
1 x Membranschalter-Modul
1 x Versuchsaufbau
1 x HC-SR501 PIR-Modul
1 x ADXL335 Modul
1 x MAX7219 Modul
1 x Wasserfüllstanderkennung-Sensormodul
1 x RC522 RFID-Modul
1 x Servomechanismus (SG90)
1 x Schrittmotor
1 x ULN2003 Schrittmotor-Treibermodul
1 x Power Supply Module
1 x Ultraschall-Sensor-Modul
1 x IR-Empfängermodul
1 x IR-Fernbedienung
1 x 3V Gleichstrommotor
1 x USB Kabel
1 x 65 M-M Kabel
1 x 10 Female-to-Male Kabel
1 x 9 V Akku mit DC
1 x 9 V 1 A Netzteil
1 x Kugelschalter
1 x Segmentanzeige
1 x 4-stellige 7-Segmentanzeige
1 x IC L293D
1 x IC 74HC595
1 x Aktiver Summer
1 x Passiver Summer
2 x Potentiometer
1 x Thermistoren
5 x Diode Rectifier (1N4007)
5 x NPN Transistor (pn2222)
5 x NPN Transistor (S8050)
2 x Fotozelle
5 x 22pF Keramikkondensator
5 x 104pF Keramikkondensator
2 x Elektrolytkondensator (10uF 50 V)
2 x elektrolytischen Kondensator (100uF 50 V)
1 x RGB LED
5 LEDs, jeweils in weiß, gelb, blau, grün, rot
5 x Druckschalter
10 Widerstände (Ohm): 10, 100, 220, 330, 1k,  2k, 5k1, 10k, 100k, 1m

Upgraded 37 in 1 Sensor Modules Kit

1 x JoystickModule
1 x RelayModule
1 x Rotary EncoderModule
1 x DS-3231 RTC Module
1 x Ultrasonic SensorModule
1 x HC-SR501 PIR sensor Module
1 x Flame SensorModule
1 x Linear HallModule
1 x Metal TouchModule
1 x Digital TemperatureModule
1 x Big SoundModule
1 x Small SoundModule
1 x RGB LEDModule
1 x SMD RGBModule
1 x Two-tone ColorModule
1 x 7 Color FlashModule
1 x Laser EmitModule
1 x ShockModule
1 x IR ReceiverModule
1 x IR EmissionModule
1 x Tilt SwitchModule
1 x ButtonModule
1 x Active BuzzerModule
1 x Passive BuzzerModule
1 x 18B20 tempModule
1 x Photo-resistorModule
1 x Temperature and HumidityModule
1 x GY-521 Module
1 x Photo-interrupterModule
1 x Tap ModuleModule
1 x Membrane SwitchModule
1 x AvoidanceModule
1 x TrackingModule
1 x Magnetic SpringModule
1 x Water Lever Sensor
1 x Power Supply Module
1 x LCD1602 Module (with pin header)

Ionic: Troubleshooting

Handling build errors

How to fix TypeError: Cannot read property ‘Private’ of undefined

$

How to fix TypeError: AppScripts.serve is not a function

$ npm install --save-dev @ionic/app-scripts@latest

How to fix Error: Cannot find module ‘@ionic/app-scripts’

$ npm install --save-dev @ionic/app-scripts@latest

How to fix Error: Cannot find module ‘@angular/tsc-wrapped/src/tsc’

$ npm install --save-dev @angular/tsc-wrapped@latest

How to fix Error: Cannot find module ‘@angular/compiler-cli’

$ npm install --save-dev @angular/compiler-cli@latest

How to fix Error: Cannot read property ‘replace’ of undefined

Read here for details

$ npm install ios-sim@latest

Or edit line 283 in file lib.js and follow https://github.com/phonegap/ios-sim/pull/213/files

vi platforms/ios/cordova/node_modules/ios-sim/src/lib.js

Change to

list.push(util.format('%s, %s', name_id_map[ filterDeviceName(devicename) ].replace(/^com.apple.CoreSimulator.SimDeviceType./, ''), runtime.replace(/^iOS /, '')));

How to fix Error: spawn EACCES

$ ionic hooks add

Homebrew | Getting started

Installation

Install on macOS

Install

An important dependency before Homebrew can work is the Command Line Tools for Xcode. These include compilers that will allow you to build things from source.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Setup environment

echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.bash_profile

Check installation

brew doctor

Using Homebrew

To install a package (or Formula in Homebrew vocabulary) simply type:

brew install <formula>

Update

To update Homebrew’s directory of formula, run:

brew update

To see if any of your packages need to be updated:

brew outdated

To update a package:

brew upgrade <formula>

Homebrew keeps older versions of packages installed, in case you want to roll back. That rarely is necessary, so you can do some cleanup to get rid of those old versions:

brew cleanup

To see what you have installed (with their version numbers):

brew list --versions

Homebrew Cask

Let’s see if we can get the elegance, simplicity, and speed of Homebrew for the installation and management of GUI Mac applications such as Google Chrome and Adium.

brew cask install google-chrome

Configure brew on macOS

If you want to use tools such as ruby or gem, you can configure brew to use this tools without the need of superuser permissions: Use environment variable:

export RBENV_ROOT="$(brew --prefix rbenv)"
export GEM_HOME="$(brew --prefix)/opt/gems"
export GEM_PATH="$(brew --prefix)/opt/gems"

Look here

Installation of a Package

Install a specific ruby version

brew update
brew install rbenv
brew install ruby-build

Once you have rbenv and ruby-build installed, you can run the following command to get Ruby 2.3.0 installed.

rbenv install 2.3.0

Now if you’d like to use 2.3.0 by default, you can run the following command:

rbenv global 2.3.0

Finally, add this to your .bashrc

eval "$(rbenv init -)"

Docker | Getting started

General Information

Installation

Install with Homebrew

brew install bash-completion
brew cask install docker
brew install kubectl
brew cask install minikube

After Installation, check versions

docker version
docker-compose version
docker-machine --version
kubectl version --client

First steps

Start a docker image with a given name

$ docker run --interactive --tty --name ubuntu ubuntu /bin/bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
af49a5ceb2a5: Pull complete 
8f9757b472e7: Pull complete 
e931b117db38: Pull complete 
47b5e16c0811: Pull complete 
9332eaf1a55b: Pull complete 
Digest: sha256:3b64c309deae7ab0f7dbdd42b6b326261ccd6261da5d88396439353162703fb5
Status: Downloaded newer image for ubuntu:latest
root@a5b411d609f0:/#

Run a command

root@a5b411d609f0:/# uname -a
Linux a5b411d609f0 4.4.27-moby #1 SMP Wed Oct 26 14:21:29 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
root@a5b411d609f0:/# id
uid=0(root) gid=0(root) groups=0(root)
root@a5b411d609f0:/# hostname
a5b411d609f0
root@a5b411d609f0:/#

Leave image

root@a5b411d609f0:/# exit
exit
$

 Show running images

$ docker ps -a
CONTAINER ID  IMAGE   COMMAND      CREATED        STATUS                   PORTS  NAMES
b01ba9bfef78  ubuntu  "/bin/bash"  41 seconds ago Exited (0) 2 seconds ago        ubuntu

Start image

$ docker start ubuntu
ubuntu
$ docker ps -a
CONTAINER ID  IMAGE   COMMAND      CREATED        STATUS                 PORTS   NAMES
b01ba9bfef78  ubuntu  "/bin/bash"  2 minutes ago  Up 1 seconds                   ubuntu

Attach to image, e.g. “enter” the image

Don’t forget to press enter after you entered the command do display the shell in the image again

$ docker attach ubuntu
root@b01ba9bfef78:/#

Working with Docker

$ docker run -it --name ubuntu ubuntu bash

You are in a terminal with ubuntu and can do whatever you like.

To start again after a reboot:

$ docker start ubuntu
$ docker exec -it ubuntu bash

If you want save your changes:

$ docker commit ubuntu
$ docker images

See the unnamed image and:

$ docker tag <imageid> myubuntu

Then you can run another container using your new image.

$ docker run -it --name myubuntu myubuntu bash

Or replace the former

$ docker stop ubuntu
$ docker rm ubuntu
$ docker run -it --name ubuntu myubuntu bash

Docker Components

Machines

Create machine

$ docker-machine create --driver=virtualbox default
$ docker-machine ls
NAME         ACTIVE   DRIVER       STATE     URL                         SWARM   DOCKER    ERRORS
default      -        virtualbox   Running   tcp://192.168.99.100:2376           v1.12.2   
virtualbox   -        virtualbox   Stopped                                       Unknown 

Show environment of machine

$ docker-machine env
export DOCKER_TLS_VERIFY="1"
export DOCKER_HOST="tcp://192.168.99.100:2376"
export DOCKER_CERT_PATH="/Users/docker/.docker/machine/machines/default"
export DOCKER_MACHINE_NAME="default"
# Run this command to configure your shell: 
# eval $(docker-machine env)

Stop machine

$ docker-machine stop default
Stopping "default"...
docker-Machine "default" was stopped.

Start  machine

$ docker-machine start default
Starting "default"...
(default) Check network to re-create if needed...
(default) Waiting for an IP...
Machine "default" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the docker-machine env command.

Set environment of a machine

$ eval "$(docker-machine env default)"

Create machine from iso image

$ docker-machine create -d virtualbox --virtualbox-boot2docker-url https://releases.rancher.com/os/latest/rancheros.iso <MACHINE-NAME>
$ docker-machine env rancheros

Images

Images are just templates for docker containers.

List all images

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              latest              f753707788c5        5 days ago          127.2 MB

Remove images

$ docker rmi <IMAGE ID>

Remove all images

$ docker rmi $(docker images -q)

Container

List all container

$ docker ps -a

Run command in container

$ docker run -it ubuntu bash
Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
6bbedd9b76a4: Pull complete 
fc19d60a83f1: Pull complete 
de413bb911fd: Pull complete 
2879a7ad3144: Pull complete 
668604fde02e: Pull complete 
Digest: sha256:2d44ae143feeb36f4c898d32ed2ab2dffeb3a573d2d8928646dfc9cb7deb1315
Status: Downloaded newer image for ubuntu:latest

Run command and delete container after running

$ docker run -it --rm ubuntu hostname

Check environment in container

$ docker run -it ubuntu bash
# hostname
c26fc567f552
root@c26fc567f552:/# uname -a
Linux c26fc567f552 4.4.24-boot2docker #1 SMP Fri Oct 7 20:54:27 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

Remove all container

$ docker rm $(docker ps -a -q)

Commit container as new image

$ docker ps -a
CONTAINER ID        IMAGE                  COMMAND                  CREATED             STATUS                     PORTS               NAMES
e4a50905aa9c        continuumio/anaconda   "/usr/bin/tini -- /bi"   22 minutes ago      Exited (0) 5 minutes ago                       pedantic_kirch
164daaac2349        4f3b088e1307           "/bin/sh -c 'apt-get "   4 hours ago         Exited (100) 4 hours ago                       happy_jang
817bb15d3171        i_electron             "/bin/bash"              2 weeks ago         Exited (0) 2 weeks ago                         cranky_wilson
$ docker commit e4a50905aa9c r14r_anaconda

Tipps and Tricks

Use npm as a comand wrapper

Create a  empty npm package

$ npm init --yes

Add this lines to the package.json file

{
  "name": "development",
   ...
  "license": "ISC",
  "scripts":  {
    "build": "docker build -t development .",
    "ssh": "docker run -i -t development /bin/bash"
}

Create a Dockerfile

FROM ubuntu
RUN apt-get update && apt-get install -y firefox

Now you can build the image with

$ npm run build
$ npm run ssh

Running XClients from Docker on macOS Host (Source)

Install Homebrew

Install requires parts

$ brew install socat
$ brew cask install xquartz

Now start XQuartz

$ open -a XQuartz

Expose local xquartz socket via socat on a TCP port.
Run this in another terminal window

$ socat TCP-LISTEN:6000,reuseaddr,fork UNIX-CLIENT:\"$DISPLAY\"

The masking of the characters ” is VERY important

Run Firefox in Docker Container

$ docker run -it -e DISPLAY=server:0.0 i_firefox firefox

Create image from scratch

Scratch image

Create image from scratch

Using Linux as Docker OS

Available Linux OS’s

Alpine LinuxHome | Github | Docker Hub 
CoreOS Container LinuxHome | Github | Docker HubISO |
Rancher Labs RancherOSHome | Github | Docker Hub 
Red Hat Project AtomicHome | Github | Docker Hub 
VMware Photon OSHome | Github | Docker Hub 

JavaScript: Guide to the JavaScript Ecosystem

Beginning – Libraries and Frameworks

UI

  • Angular
  • Ionic
  • Onson UI
  • Framework 7

Unit Testing

  • Karma
  • Jasmine

End-to-End Testing

Technologies

Unit Testing

Protractor (http://www.protractortest.org/)

Use npm to install Protractor globally with

npm install -g protractor

The webdriver-manager is a helper tool to easily get an instance of a Selenium Server running. Use it to download the necessary binaries with:

webdriver-manager update

Now start up a server with:

webdriver-manager start

Install a demo repository:

git clone https://github.com/juliemr/protractor-demo.git
npm install

Update selenium driver

node_modules/protractor/bin/webdriver-manager update

Run server in background:

node app/expressserver.js &

Now run the tests

npm test 

Error message: No selenium server jar found at the specified location

The Error

If you got this error when testing your javascript app, maybe you hate to update the selenium driver jar.

The Solution

Update the driver depending on the installation of the node module:

Check with

$ which protracto
/usr/local/bin/protractor

If installed global, then use the command

$ /usr/local/lib/node_modules/protractor/bin/webdriver-manager update

If installed in the app directory, use

$ node_modules/protractor/bin/webdriver-manager update
[17:17:13] I/update - chromedriver: file exists node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.22mac32.zip
[17:17:13] I/update - chromedriver: unzipping chromedriver_2.22mac32.zip
[17:17:14] I/update - chromedriver: setting permissions to 0755 for node_modules/protractor/node_modules/webdriver-manager/selenium/chromedriver_2.22
[17:17:14] I/update - chromedriver: v2.22 up to date
[17:17:14] I/update - selenium standalone: file exists node_modules/protractor/node_modules/webdriver-manager/selenium/selenium-server-standalone-2.53.1.jar
[17:17:14] I/update - selenium standalone: v2.53.1 up to date

Vagrant | Getting started

Installation

Installing VirtualBox

Install VirtualBox on Linux
$ sudo apt-get install virtualbox
Install VirtualBox on Mac OS
$ brew cask install virtualbox

Install Vagrant

Install VirtualBox on Linux
$ sudo apt-get install vagrant
$ sudo apt-get install virtualbox-dkms
Install VirtualBox on Mac OS
$ brew cask install vagrant
$ brew cask install vagrant-manager
$ brew cask install vagrant-completion

First Steps

Getting vagrant machine up

 $ vagrant box add precise32 http://files.vagrantup.com/precise32.box
$ vagrant box add hashicorp/precise64

Configure Project

$ mkdir vagrant_project 
$ cd vagrant_project

 

Configure Vagrant environment

Running X Clients

Allow X-Forwarding

Vagrant.configure(2) do |config|
...
config.ssh.forward_x11 = true
end

Check ssh config

$ vagrant ssh-config
Host some_site
HostName 127.0.0.1
User vagrant
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardX11 yes

Run a X client

$ vagrant ssh
vagrant@vagrant: $ sudo apt-get install xclock
vagrant@vagrant: $ exit
$ ssh -X -p 2222 vagrant

@localhost

 xclock

Setup Vagrant box

Setup with on command

$ vagrant init hashicorp/precise64

Setup manuell

$ vagrant init

Edit the Vagrantfile in this directory and replace

config.vm.box = "precise32"

Start Environment

Start Vagrant box

$ vagrant up

Connect using SSH

$ vagrant ssh

Stop working with Vagrant

$ vagrant halt