Google Cloud Next

Google Cloud Next conference is for year 2020 online, see https://cloud.withgoogle.com/next/sf/onair#infrastructure

Here is a play list of the presentations in the last few years:
2019
2018
2017

Posted in Blogroll, workday | Tagged | Leave a comment

REGEX at awk file

More complex awk text processing is better to put in the file. And there can be regex filter as well. Below is a simple example utilizing awk code in the file xml-info.awk, which prints information only for XML files.

$ ls -l
total 24
-rw-r--r-- 1 User User 9223 Jul 26 11:06 alpha.html
-rw-r--r-- 1 User User 6173 Jul 29 10:03 alpha.xml
-rw-r--r-- 1 User User 3227 Jul 29 10:43 beta.xml
xml-info.awk:
BEGIN { print "Hello at BEGIN"}
/\.xml$/{
 printf("filename: %s, size: %s\n", $9, $5);
}
END { print "Hello at END"}
$ ls -l | awk -f ../bin/xml-info.awk
Hello at BEGIN
filename: alpha.xml, size: 6173
filename: beta.xml, size: 3227
Hello at END
Posted in Blogroll, workday | Leave a comment

ssh password-less

Here are steps, how to do it in Linux type environment on LOCAL host:

  1. USER_REMOTE=username@remote-host
  2. ssh-keygen -t rsa #no password
  3. ssh $USER_REMOTE mkdir -p .ssh
  4. cat .ssh/id_rsa.pub | ssh $USER_REMOTE ‘cat >> .ssh/authorized_keys’
  5. ssh $USER_REMOTE ‘chmod 700 .ssh; chmod 640 .ssh/authorized_keys’
  6. ssh $USER_REMOTE

Step 2 is necessary only if you don’t have id_rsa.pub file yet
Steps 3,4,5 need remote password
Steps 3 and 5 are not necessary, if the file .ssh/authorized_keys with appropriate access rights is already on remote host
Step 4 actually transfers the public key
Step 6 does not need password, you are there already, congratulations!

Posted in workday | Leave a comment

Hello Website on GKE Cluster

Let’s explore, how deploy web application “Hello Website” written in go language at Google Kubernetes Engine Cluster.

Source code for “Hello Website” in the file helloweb.go

package main

import (
    "fmt"
    "net/http"
)

func main() {
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hello website! You've requested: %s\n", r.URL.Path)
    })

    http.ListenAndServe(":80", nil)
}

Source code for dockerfile

# image environment definition
# 
FROM golang:1.14

WORKDIR /go/src/app
#copy current dir on local host to current dir on image, in this case workdir
COPY . .

#get all packages in current dir (.) and all subdirs (...), just download (-d)
RUN go get -d -v ./...
RUN go install -v ./...

CMD ["app"]

Steps:

  1. At https://console.cloud.google.com/apis/library search for Kubernetes (k8s) and then enable k8s Engine API
  2. Create Docker image
    At authenticated terminal or cloud shell go to the directory with helloweb source files and do:
    docker build -t helloweb-container-image .
    docker images
    gcloud auth configure-docker
    docker tag helloweb-container-image gcr.io/<MY_PROJECT_ID>/helloweb-container-image:v1
    docker push gcr.io/<MY_PROJECT_ID>/helloweb-container-image:v1
    gcloud container images list
    gcloud container images list –repository=gcr.io/<MY_PROJECT_ID>
  3. Create Kubernetes Engine cluster:
    gcloud config set compute/zone us-central1-a
    gcloud container clusters create helloweb-cluster1 –num-nodes=4
    gcloud container clusters get-credentials helloweb-cluster1
    kubectl create deployment hello-website –image=gcr.io/<MY_PROJECT_ID>/helloweb-container-image:v1
  4. Expose deployed workload
    kubectl expose deployment hello-website –type=LoadBalancer –name=hello-website-service –port=80 –target-port=80
    kubectl get services
  5. With your web browser, go to the EXTERNAL-IP to see Hello Website!

							
Posted in golang, workday | Tagged | Leave a comment

GCP notes

Setup

  1. Creating an account
  2. Creating a new project
    No org, org(G Suite, Cloud Identity)
    Project-id is unique
  3. Deleting project
    Project settings: Shutdown
    IAM & Admin / Manage resources: Delete
  4. Creating users
    IAM: Add user@companyGSuite_gserviceaccount_googlegroups_gmail.com
    IAM: Add user@nonGoogle_AD_LDAP / Google Cloud Directory Sync
  5. Assigning roles
    Primitive(Owner,Editor,Viewer)
    Predefined (~500 roles)
    Custom
  6. Enabling APIs
    API & Services: … Enable Try This API
  7. Cloud Shell
    GCloud: Google Cloud SDK installed
  8. Operations
    Monitoring(Metrics, Alerting, Uptime…), Debugger, Logging, Profiler, Trace,…

Billing

  1. Billing accounts – cloud (needed Payments profile – google)
  2. Budget

Storage

Structured data:
+ For analytics
++ Low latency: Cloud BigTable
++ No: BigQuery
+ Not for analytics:
++ Relational data:
+++ Horizontal scaling: Cloud Spanner
+++ No: Cloud SQL
++ Not relational:
+++ Mobile SDK: Firebase
+++ No: Datastore
Not structured data:
+ Mobile SDK: Firebase
+ No: Cloud Storage (class: Standard, Nearline<M, Coldline<Q, Archive<Y)

Posted in Blogroll, workday | Leave a comment

Rotating prompt color

If one has more that one terminal window opened, it’s sometimes hard to tell what is where. Here is example of the file ~/.bash_profile, which is always executed, if new terminal window is opened. Numeric value of the previous prompt is saved in the file ps1-color.num. Script also defines environment variable _TERM_START with value set to the start time and it can be helpfull to identify terminal window as well.

#date command is in back-ticks
export _TERM_START=date +"%a_%Y-%m-%d_%H:%M:%S"
export PS1COLOR=34

input=”/home/joedoe/.bash_sessions/ps1_color.num”
IFS= read -r PS1COLOR < “$input”
PS1COLOR=$(expr ${PS1COLOR} + 1)
if (( $PS1COLOR > 37 ))
then
PS1COLOR=30
fi

echo ${PS1COLOR} > $input
export PS1=”\[033[1;${PS1COLOR}m\]\h \W \$ \[\033[0;30m\]”

Posted in workday | Leave a comment

Elapsed time on bash

Once a while is nice to measure elapse time on Linux on bash command line.
Here is an example how to count elapsed seconds:

$ time1=`date +"%Y-%m%d-%H:%M:%S";time1s=`date +"%s"`

$ time2s=`date +"%s"; echo Elapsed time since $time1 is `expr $time2s - $time1s` seconds

Elapsed time since 2019-1213-19:03:24 is 55 seconds
Posted in workday | Leave a comment

Marketing

“Marketing isn’t about shortcuts, hustle or deception. Marketing is the art (and the science) of serving the people you seek to serve, to do better work by finding and satisfying needs. Marketing is the practice of making things better by making better things.”

Seth Godin

Posted in workday | Leave a comment

Short decimal ASCII characters table

Seven bit characters ASCII table is with us long time. Once a while we need to know value of ASCII character, mostly out of the alphabet characters. For example on Windows it’s possible to type any character by pressing <ALT> and typing decimal character value on numeric keyboard. Character A can be typed by <ALT>+65. Can be useful in remote environment. Below is golang program (or with hex columns), which is printing shortened ASCII characters table, mostly witch special characters. From 40 printed characters, there are actually 32 “special” characters, not counting A-Z, a-z, 0-9, space and del.

package main

import (
	"fmt"
)

func main() {
	fmt.Println("Short decimal ASCII characters table")
	a := [8][5]int{
		{32, 40, 48, 64, 96},
		{33, 41, 57, 65, 97},
		{34, 42, 58, 90, 122},
		{35, 43, 59, 91, 123},
		{36, 44, 60, 92, 124},
		{37, 45, 61, 93, 125},
		{38, 46, 62, 94, 126},
		{39, 47, 63, 95, 127},
	}
	for i := 0; i < 8; i++ {
		for j := 0; j < 5; j++ {
			fmt.Printf("%3d %s   ", a[i][j], string(a[i][j]))
		}
		fmt.Println()
	}
}
Short decimal ASCII characters table
 32      40 (    48 0    64 @    96 `   
 33 !    41 )    57 9    65 A    97 a   
 34 "    42 *    58 :    90 Z   122 z   
 35 #    43 +    59 ;    91 [   123 {   
 36 $    44 ,    60 <    92 \   124 |   
 37 %    45 -    61 =    93 ]   125 }   
 38 &    46 .    62 >    94 ^   126 ~   
 39 '    47 /    63 ?    95 _   127    
Posted in golang, workday | Tagged , | Leave a comment

data:text/html, <html contenteditable> … and CTRL+S … in Chrome!

See Handy notepad in Chrome tab or window, this time in title what one could have in bookmarks. CTRL+<S> can save file into the file system.

Posted in workday | Leave a comment