How to setup raspberry pi zero w with MacOS X

Step 1 Prepare tools

To setup a brand new raspberrypi zero w you need prepare following tools:

  • A raspberrypi zero w
  • mini HDMI to HDMI convert
  • Micro SD card
  • USB OTG
  • Mouse & Keyboard
  • An external SD card reader

All coneectors can come from seller when you purchase Raspberrypi zero w.

[[Picture]]

Step 2 Download Raspbian Image

You can download official Raspbian OS from here. If you want use other operation systems, it is same setup setups.

Step 3 Write Image to Micro SD card

Be aware, writing image to micro sd card will wipe all data on it

Connect micro sd card to your mac through micro sd card reader.

Picture

Once you can see your sd card in finder, you need find out the disk in system.

Open a terminal and run diskutil list:

Picture

Find your sd card disk by its name. On my machine, the /dev/disk2 in red rectangle is the disk in system and copy disk2 only (not /dev/disk2) into clipboard.

Unmount the sd card from finder but do not unplug it.

Picture

Now, we need flash the image downloaded to sd card. You may need unzip it if the downloaded file is zipped by double click the file in finder. Below is the command to use:

1
sudo dd bs=4M if=<path to downloaded .img file> of=/dev/r<disk>

Replace the path and <disk> to your own one.

Pic

Step 4 Plugin and setup

Now insert the flashed micro sd card to Raspberrypi Zero W and connect everything and you are ready to go.

[Picture]

General Problems

  • Resource busy: You need unmount the partitions mounted before you could use dd to write the disk. See above.
  • Permission denied: Make sure write protection on your sd card is open. Also use external SD card reader instead of Mac built-in one which could cause this issue.
  • Operation not permitted: Make sure your device exists in system (check /dev/diskN)

how to change MacOSX screenshot location

Taking screenshots with MacOSX is very useful when writting blogs or documents. The system has powerful built-in screenshot function. However, the default location to store the screenshot files is Desktop.

This blog will go through how to change the location of screenshots to another folder.

Step 1 Create a folder

Create a new folder anywhere using finder or terminal. Here I created blog_statics folder in my Google Drive folder.

Picture

Step 2 Change default location of screenshots

Click the created folder in last step and press Command+C to copy the full path to clipboard.

Press Command + Space and type terminal to open terminal

In terminal, type following command:

1
defaults write com.apple.screencapture location <Folder Location>

Note the is the location of your create folder. You could Command+V to paste it from clipboard

It should give following result:

img

Now all new screenshots should be stored in that place.

run docker in docker

Run docker in docker

1
docker run --privileged -i -t -d --restart=unless-stopped -p 2376:2376 -p 10000-11000:10000-11000 -p 10000-11000:10000-11000/udp -v /mnt/opt:/opt:rw -v /etc/docker:/etc/docker:ro -v /mnt/var/lib/docker:/var/lib/docker --name=docker docker:dind -H tcp://0.0.0.0:2376 --storage-driver=aufs --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem

Customised select styles

e.g.

1
2
3
4
5
6
7
8
9
10
11
12
13
.select-type-1{
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding:1em;
border:1px solid #ee7122;
color:white;
text-align: center;
border-radius: 0px;
-webkit-border-radius: 0px;
background: rgba(255, 255, 255, 0.12) url("../img/arrowdown.png") no-repeat 90% 50%;
background-size:10%;
}

self-explained.

Docker multi-hosting network quick note

To create an overlay network on multiple hosts over swarm, following are required:

  • a key-value store service: this is used for broadcasting hosts / swarm agents. It can be same kv store swarm used for discovery
  • Run docker daemon with following parameters:
    • cluster-store: where the store is
    • cluster-advertise: what network interface to be advertised

Setup consul KV store

1
2
3
4
5
6
docker run -d \
-p "8500:8500" \
-h "consul" \
--restart=unless-stopped \
--name="kv_store"\
progrium/consul -server -bootstrap

Daemon Options

1
2
--engine-opt="cluster-store=consul://$(docker-machine ip mh-keystore):8500"
--engine-opt="cluster-advertise=eth1:2376"

All swarm-agents should have these options otherwise it will be likely get this error:

1
Error response from daemon: 500 Internal Server Error: failed to parse pool request for address space "GlobalDefault" pool "" subpool "": cannot find address space GlobalDefault (most likely the backing datastore is not configured)

Create overlay network

If using docker-compose, there is nothing need to do. As docker-compose will automatically create defaul network if:

  • Single host: it will create a bridge
  • Multiple host: it will create a overlay

Once docker-compose file finished, just run docker-compose up -d which will create network correspondingly.

otherwise simply use following command at your swarm:

1
docker network create --driver overlay --subnet=10.0.9.0/24 my-net

Docker-compose build on Swarm

There is limitation for docker-compose build as it cannot find the target node to build the image.
The only way currently is to build on the node and tag it rather than on swarm.

1
docker build -t <tag name> path/to/dockerfile

Quick Note for Unit Tests in Angularjs

Testing with web app is always fun. Angularjs makes it even better.
This quick note bootstrap any angular.js projects embracing with unit tests.

Tools

Unit testing in Angularjs is using (by default) Jasmine and Karma.

Also, angular-mocks needs to be installed. It is needed for injection and some other mock objects.

1
bower install --save angular-mocks

more >>