Saturday 31 October 2020

AlphaGo - The Movie

go web app 14 session cookies

 
log in as bob with chrome browser
user name is encrypted and stored in browser cookies

cookie is loaded and decrypted


open the same page with firefox browser, cookie is not found cause cookie is stored on chrome

//cmd - install session
C:\Users\bob\golang1>go get github.com/gorilla/sessions

//tutorial.go
package main

import (
"html/template"
"net/http"

"github.com/gorilla/mux"
"github.com/gorilla/sessions"
)

type car struct {
Color   string
Mileage int
Model   string
}

var templates *template.Template
var store = sessions.NewCookieStore([]byte("secret"))

var truck = car{
Color:   "black",
Mileage: 12345,
Model:   "F-150",
}

var sedan = car{
Color:   "white",
Mileage: 321,
Model:   "Corolla",
}

func indexGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "index.html", []car{truck, sedan})
}

func loginGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "login.html", nil)
}

func loginPostHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
username := r.PostForm.Get("username")
session, _ := store.Get(r, "session")
session.Values["username"] = username
session.Save(r, w)
}

func testGetHandler(w http.ResponseWriter, r *http.Request) {
session, _ := store.Get(r, "session")
untyped, ok := session.Values["username"]
if !ok {
return
}
cookie, ok := untyped.(string)
if !ok {
return
}
w.Write([]byte(cookie))
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
//r.HandleFunc("/", indexPostHandler).Methods("POST")
r.HandleFunc("/login", loginGetHandler).Methods("GET")
r.HandleFunc("/login", loginPostHandler).Methods("POST")
r.HandleFunc("/test", testGetHandler).Methods("GET")
fs := http.FileServer(http.Dir("./static/"))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

---------------------
//login.html
<html>

<head>
    <title>Login</title>
</head>

<body>
    <form method="POST">
        Username: <input name="username">
        <div>
            <button type="submit">Login</button>
        </div>
    </form>
</body>

</html>

reference:

Friday 30 October 2020

go web app 13 static files

 
click file icon will open vehicle picture

//tutorial.go
package main

import (
"html/template"
"net/http"

"github.com/gorilla/mux"
)

type car struct {
Color   string
Mileage int
Model   string
}

var templates *template.Template

//var colors = []string{"red", "green", "blue"}

var truck = car{
Color:   "black",
Mileage: 12345,
Model:   "F-150",
}

var sedan = car{
Color:   "white",
Mileage: 321,
Model:   "Corolla",
}


func indexGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "index.html", []car{truck, sedan})
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
fs := http.FileServer(http.Dir("./static/"))
r.PathPrefix("/static/").Handler(http.StripPrefix("/static/", fs))
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

----------------------
//templates/index.html
<html>

<head>
    <title> Templates</title>
    <link rel="stylesheet" type="text/css" href="/static/index.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>

<body>
    <h1>Cars</h1>

    <ul>
        {{range .}}
        <li>{{.Color}} {{.Model}} - {{.Mileage}} Miles
            <i class="fa fa-file" onclick="window.open('http://localhost:8000/static/{{.Model}}.jpg','_blank')"></i>
        </li>
        {{end}}
    </ul>
</body>

</html>

-----------------------------
//static/index.css
body > ul {
    padding : 0.5em;
    width: 200px;
    margin: 1em 0em;
    background:#ccc;
    border: 1px solid rgb(202, 48, 48);
}

i{
    cursor: pointer;
}

reference:

大兴机场投运

Thursday 29 October 2020

go web app 12 json response

 
get json response from go server
//main.go
package main

import (
"encoding/json"
"html/template"
"net/http"

"github.com/gorilla/mux"
)

type car struct {
Color   string
Mileage int
Model   string
}

var templates *template.Template

var truck = car{
Color:   "black",
Mileage: 12345,
Model:   "F-150",
}

var sedan = car{
Color:   "white",
Mileage: 321,
Model:   "Corolla",
}

func indexGetHandler(w http.ResponseWriter, r *http.Request) {
//templates.ExecuteTemplate(w, "index.html", []car{truck, sedan})
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
json.NewEncoder(w).Encode([]car{truck, sedan})
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
//r.HandleFunc("/", indexPostHandler).Methods("POST")
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

Sydney: Inside Australia's Suburbs

Tuesday 27 October 2020

go web app 11 template advanced

 

struct
//tutorial.go
package main

import (
"html/template"
"net/http"

"github.com/gorilla/mux"
)

type car struct {
Color   string
Mileage int
Model   string
}

var templates *template.Template

var truck = car{
Color:   "black",
Mileage: 12345,
Model:   "F-150",
}

func indexGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "index.html", truck)
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

----------------------------
//index.html
<html>

<head>
    <title> Templates</title>
</head>

<body>
    <h1>Ford {{.Model}}</h1>
    <p>Mileage: {{.Mileage}}</p>
    <p>Color: {{.Color}}</p>
</body>

</html>
array
//tutorial.go
package main

import (
"html/template"
"net/http"

"github.com/gorilla/mux"
)

var templates *template.Template

var colors = []string{"red", "green", "blue"}

func indexGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "index.html", colors)
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

-------------------------
//index.html
<html>

<head>
    <title> Templates</title>
</head>

<body>
    <h1>Colors</h1>

    <ul>
        {{range $index, $item := .}}
        <li>{{$index}} - {{$item}}</li>
        {{end}}
    </ul>
</body>

</html>

map
//tutorial.go
package main

import (
"html/template"
"net/http"

"github.com/gorilla/mux"
)

var templates *template.Template

var grades = map[string]int{
"homework": 100,
"quize": 100,
"midterm": 100,
"final": 100,
}

func indexGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "index.html", grades)
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

-------------------------
//index.html
<html>

<head>
    <title> Templates</title>
</head>

<body>
    <h1>Grades</h1>

    <ul>
        {{range $key, $val := .}}
        <li>{{$key}} - {{$val}}</li>
        {{end}}
    </ul>
</body>

</html>
struct array
//tutorial.go
package main

import (
"html/template"
"net/http"

"github.com/gorilla/mux"
)

type car struct {
Color   string
Mileage int
Model   string
}

var templates *template.Template

var truck = car{
Color:   "black",
Mileage: 12345,
Model:   "F-150",
}

var sedan = car{
Color:   "white",
Mileage: 321,
Model:   "Corolla",
}

func indexGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "index.html", []car{truck, sedan})
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

----------------------------
//index.html
<html>

<head>
    <title> Templates</title>
</head>

<body>
    <h1>Cars</h1>

    <ul>
        {{range .}}
        <li>{{.Color}} {{.Model}} - {{.Mileage}} Miles</li>
        {{end}}
    </ul>
</body>

</html>

reference:

go web app 10 post

page loaded

post request, server save comment in memory, then page get updated comments from server


//tutorial.go
package main

import (
"html/template"
"net/http"

"github.com/gorilla/mux"
)

var templates *template.Template
var comments = []string{"line1", "line2", "line3"}

func indexGetHandler(w http.ResponseWriter, r *http.Request) {
templates.ExecuteTemplate(w, "index.html", comments)
}

func indexPostHandler(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
comment := r.PostForm.Get("textarea1")
comments = append(comments, comment)
templates.ExecuteTemplate(w, "index.html", comments)
}

func main() {
templates = template.Must(template.ParseGlob("templates/*.html"))
r := mux.NewRouter()
r.HandleFunc("/", indexGetHandler).Methods("GET")
r.HandleFunc("/", indexPostHandler).Methods("POST")
http.Handle("/", r)
http.ListenAndServe(":8000", nil)
}

---------------------------
//index.html
<html>

<head>
    <title> Comments</title>
</head>

<body>
    <h1>Comments</h1>
    <form method="POST">
        <textarea name="textarea1"></textarea>
        <div>
            <button type="submit">Post Comment</button>
        </div>
    </form>
    {{range .}}
    <div>{{.}}</div>
    {{end}}
</body>

</html>

reference:

Monday 26 October 2020

go web app 9 mongodb delete

 
record deleted
//cmd
C:\Users\bob\golang3>go run main.go
deleted  1

//main.go
package main

import (
"context"
"fmt"
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://bob:password@cluster0.yvyo2.mongodb.net/test?retryWrites=true&w=majority"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)

deleteGrade, err := gradesCollection.DeleteOne(ctx, bson.M{"student_id": 123, "class_id": 456})
if err != nil {
log.Fatal(err)
}
fmt.Println("deleted ", deleteGrade.DeletedCount)
}

reference:

Sunday 25 October 2020

CasaBlanca, Woman In Love



How Does Microsoft Make Money?

go web app 8 mongodb update

scores are updated
//cmd

C:\Users\bob\golang3>go run main.go
map[_id:ObjectID("5f9433922ba504d267c1aad3") class_id:456 scores:[map[exam:100] map[quize:100] map[homework:100] map[homework:100]] student_id:123]
1  updated

//main.go

package main

import (
"context"
"fmt"
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://bob:password@cluster0.yvyo2.mongodb.net/test?retryWrites=true&w=majority"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)

filterCursor, err := gradesCollection.Find(ctx, bson.M{"student_id": 123, "class_id": 456})
defer filterCursor.Close(ctx)
if err != nil {
log.Fatal(err)
}

var grades []bson.M
if err = filterCursor.All(ctx, &grades); err != nil {
log.Fatal(err)
}
fmt.Println(grades[0])

gradeUpdate, err := gradesCollection.UpdateOne(
ctx,
bson.M{"_id": grades[0]["_id"]},
bson.D{
{"$set", bson.D{{"scores",
bson.A{
bson.D{{"exam", 99}},
bson.D{{"quize", 99}},
bson.D{{"homework", 99}},
bson.D{{"homework", 99}},
}}},
},
},
)
if err != nil {
log.Fatal(err)
}
fmt.Println(gradeUpdate.ModifiedCount, " updated")
}

reference:

无人机快递

Saturday 24 October 2020

final presidential debate 2020

go web app 7 mongodb query bson array

data contains bson array
//cmd

C:\Users\bob\golang3>go run main.go
student ID:  123
class ID: 456
grades:
exam :  100
quize :  100
homework :  100
homework :  100

package main

import (
"context"
"fmt"
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://bob:password@cluster0.yvyo2.mongodb.net/test?retryWrites=true&w=majority"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)

filterCursor, err := gradesCollection.Find(ctx, bson.M{"student_id": 123, "class_id": 456})
defer filterCursor.Close(ctx)
if err != nil {
log.Fatal(err)
}
for filterCursor.Next(ctx) {
var grade bson.M
if err = filterCursor.Decode(&grade); err != nil {
log.Fatal(err)
}
fmt.Println("student ID: ", grade["student_id"])
fmt.Println("class ID:", grade["class_id"])
fmt.Println("grades: ")
scores := grade["scores"].(bson.A)

for _, score := range scores {
for k, v := range score.(bson.M) {
fmt.Println(k, ": ", v)
}
}
}
}
 
reference:

go map

go web app 6 mongodb insert

 
object inserted
//cmd
C:\Users\bob\golang3>go run main.go
&{ObjectID("5f9433922ba504d267c1aad3")}

package main

import (
"context"
"fmt"
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://bob:password@cluster0.yvyo2.mongodb.net/test?retryWrites=true&w=majority"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)

trainingDatabase := client.Database("sample_training")
gradesCollection := trainingDatabase.Collection("grades")

gradeInsert, err := gradesCollection.InsertOne(ctx, bson.D{
{"student_id", 123},
{"class_id", 456},
{"scores", bson.A{
bson.D{{"exam", 100}},
bson.D{{"quize", 100}},
bson.D{{"homework", 100}},
bson.D{{"homework", 100}},
}},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(gradeInsert)
}

reference:

Thursday 22 October 2020

go web app 5 mongodb retrive and query 2 filter sort

 //cmd - filter to find grade for student_id 0 in class_id 339

C:\Users\bob\golang3>go run main.go
[map[_id:ObjectID("56d5f7eb604eb380b0d8d8ce") class_id:339 scores:[map[score:78.40446309504266 type:exam] map[score:73.36224783231339 type:quiz] map[score:46.980982486720535 type:homework] map[score:76.67556138656222 type:homework]] student_id:0]]

//cmd - sort students in class_id 300 by descending order
C:\Users\bob\golang3>go run main.go
student ID:  9997
class ID: 300
grades:  [map[score:84.6558160678415 type:exam] map[score:41.03001163294812 type:quiz] map[score:76.39566038690292 type:homework] map[score:85.77890468455877 type:homework]]
student ID:  9975
class ID: 300
grades:  [map[score:8.252253589187186 type:exam] map[score:87.52808439331315 type:quiz] map[score:45.721796079306706 type:homework] map[score:27.86540394846814 type:homework]]
student ID:  9911
class ID: 300
grades:  [map[score:3.7139974722820157 type:exam] map[score:17.524760736805213 type:quiz] map[score:94.58247304193233 type:homework] map[score:11.05313964531678 type:homework]]
student ID:  9838
class ID: 300
grades:  [map[score:18.44047824370092 type:exam] map[score:40.223658996168865 type:quiz] map[score:62.644015337567836 type:homework] map[score:17.7905378078307 type:homework]]
student ID:  9733
class ID: 300
grades:  [map[score:77.00121051953168 type:exam] map[score:82.42737364488491 type:quiz] map[score:3.4209383539206994 type:homework] map[score:14.579084592497582 type:homework]]

//main.go

package main

import (
"context"
"fmt"
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://bob:password@cluster0.yvyo2.mongodb.net/test?retryWrites=true&w=majority"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)

/*
err = client.Ping(ctx, readpref.Primary())
if err != nil {
log.Fatal(err)
}
databases, err := client.ListDatabaseNames(ctx, bson.M{})
err = client.Ping(ctx, readpref.Primary())
if err != nil {
log.Fatal(err)
}
fmt.Print(databases)
*/
trainingDatabase := client.Database("sample_training")
gradesCollection := trainingDatabase.Collection("grades")

cursor, err := gradesCollection.Find(ctx, bson.M{})
/*
if err != nil {
log.Fatal(err)
}
var grades []bson.M
if err = cursor.All(ctx, &grades); err != nil {
log.Fatal(err)
}
fmt.Println(grades)
*/
defer cursor.Close(ctx)

/*all
for i := 0; cursor.Next(ctx) && i < 5; i++ {
var grade bson.M
if err = cursor.Decode(&grade); err != nil {
log.Fatal(err)
}
fmt.Println("student ID: ", grade["student_id"])
fmt.Println("class ID:", grade["class_id"])
fmt.Println("grades: ", grade["scores"])
}
*/

/*filter
filterCursor, err := gradesCollection.Find(ctx, bson.M{"student_id": 0, "class_id": 339})
defer filterCursor.Close(ctx)
if err != nil {
log.Fatal(err)
}
var gradeFiltered []bson.M
if err = filterCursor.All(ctx, &gradeFiltered); err != nil {
log.Fatal(err)
}
fmt.Println(gradeFiltered)
*/

//sort
opts := options.Find()
opts.SetSort(bson.D{{"student_id", -1}})
sortCursor, err := gradesCollection.Find(ctx, bson.D{
{"class_id", bson.D{
{"$eq", 300},
}},
}, opts)
/*
var gradeSorted []bson.M
if err = sortCursor.All(ctx, &gradeSorted); err != nil {
log.Fatal(err)
}
fmt.Println(gradeSorted)
*/
for i := 0; sortCursor.Next(ctx) && i < 5; i++ {
var grade bson.M
if err = sortCursor.Decode(&grade); err != nil {
log.Fatal(err)
}
fmt.Println("student ID: ", grade["student_id"])
fmt.Println("class ID:", grade["class_id"])
fmt.Println("grades: ", grade["scores"])
}
}

reference:

加拿大准备实施电子证件

在加拿大生活,被大家吐槽最多的无外乎几件事:没有国内扫码支付方便,看病难,出门办事效率慢...

然而就在昨天10月19日,安省政府正式宣布,将致力于把包括看病预约,延期驾照等几十个政府服务全部转为线上办理!

更方便的是,加拿大终于也可以用手机电子身份证件了!无论是健康卡,驾照还是其他省府证件全部可以安全的存档手机内,出门可以像国内那样不带驾照了。而且申请和延期驾照,健康卡和车牌贴纸等,全部可以轻松在网上操作!再也不用去排大队了。

福特在昨天的新闻会上表示,自己和安省政府都致力于应对因新冠疫情而受影响的政府服务,希望通过这个大规模的“安省向前:以人为本行”的便民计划,让大家的生活更方便。

项目当中包括30个改善大家生活便利度和与帮助企业的项目,其中最引人瞩目包括:“电子身份”项目,看医生可以在线“云面诊”,医生可从手机上调出患者健康记录,以及小企业可以在线注册各种许可证等,简化以往需要亲自前往排队等候办理的各种复杂手续。

我们来看下省府公布的各项具体计划:

1. 数字身份证(Digital identity)
健康卡,驾驶执照和出生证明等都可以安全的存在只能手机的数字钱包中。这些经过认证关于你的身份信息以电子方式安全存储在手机,需要时简单出示即可。

2. 健康为先(Digital first for health)
看病更方便!一线护理医务人员可以从任何地方,通过电子设备快速安全地访问患者的健康记录。先进的病人健康数据库对医务人员和病人都带来方便。

3. 改善网络快带和蜂窝数据服务(Improve access to broadband and cellular services)
加强整个安省的扩展宽带服务,让大家上网速度更快服务区域更广。

4.用于培训和专上教育的虚拟学习策略(Proposing a virtual learning strategy for training and post-secondary education)
对加拿大的学生和国际学生提供更好的网课策略,增强高质量的专上教育和再培训。

5. 车牌,驾照,健康卡等服务改进(ServiceOntario enhancements)
申请或者延期驾照,车牌贴纸,健康卡等,全部可以在ServiceOntario的网上轻松搞定。省府并会确保网上服务的质量和速度。

6  司法刑事数字化(Criminal Justice Digital design)
目前安省刑事司法系统在依靠书面材料推动案件向前发展。但是以后将通过警察,皇家检察官,法院和惩戒合作伙伴进行数字化连接共享,可以实现数据,文档等实时数据调用,大大提高处理案件和官司的效率。

7 伸张正义(Moving Justice forward strategy)
在疫情期间及以后建立更易于访问,反应更迅速和更具弹性的司法系统。目前总检察长部正建立一个全新有创意的方式来提供远程,面对面和在线服务。比如在线陪审团预筛选和签到工具等。

8. 运输服务增强(Transportation services enhancements)
提高运输服务的安全性,提供改善的驾驶体验。例如,新的511应用程序为卡车司机提供即时信息比如高速旁的美食中心和和休息站的位置等以确保安全驾驶。让安省运送服务更安全快捷。

9 安省官网改良(Ontario.ca enhancements)
省府的官网会进一步改进,让大家最方便地拿到实用信息。比如疫情中实时更新的学校确诊数字和情况等。

10. 电子化的成熟政府服务(Digital maturity model)
建立数字时代,政府公共服务全面电子化的清晰理念。让安省成为全球领先的使用电子化传递政府信息和提供服务的省份。

11.支付系统更高效(Transfer payment consolidation)
使用电子支付模型,向服务供应商(例如市政当局和非营利组织)的付款。用更高效,成本更低的方式轻松交付人们每天依赖的服务。

除此之外,政府对不少华人都会碰到的流程和服务也有新方案!比如:简化建筑开放申请审批程序,可以网上申请(运输和住房项目更快得到审批,开工);允许药房的药剂师为小病开处方药(不用看家庭医生);允许老年人在线与医生进行“云面诊”;政府还将结合本地商家企业采购资源,为省内提供必须的防疫物资。等等。

据悉,其实这些工作在2018年福特上任后已经展开,但受到新冠疫情的影响有所延误,但目前政府正全力加快步伐。省政府表示,这些便民计划还有更多细节和条例,将于未来几周及几个月内宣布。

福特表示,电子证件将使民众的生活更便捷,更轻松,还可以证件丢失和身份冒充。从明年1月份开始,政府将开始咨询如何安全引入“电子证件” 开始与相关企业合作,希望在明年年底前就实现省内居民“身份电子化”。

到时候,在加拿大的你也可以像国内一样,出门只带手机,警察查ID也不用怕没带驾照,急着去医院看病也不怕忘戴健康卡,出示身份秀手机一招搞定!简直太方便。期待!

Las Vegas, Lake Mead, Hoover Dam, and Valley of Fire

手机定位和导航原理

Wednesday 21 October 2020

go web app 5 mongodb retrive and query 1

database structure
//cmd -first 5 dataset

C:\Users\bob\golang3>go run main.go
student ID:  0
class ID: 339
grades:  [map[score:78.40446309504266 type:exam] map[score:73.36224783231339 type:quiz] map[score:46.980982486720535 type:homework] map[score:76.67556138656222 type:homework]]
student ID:  0
class ID: 350
grades:  [map[score:91.97520018439039 type:exam] map[score:95.80410375967175 type:quiz] map[score:89.62485475572984 type:homework] map[score:51.621532832724846 type:homework]]
student ID:  0
class ID: 149
grades:  [map[score:84.72636832669608 type:exam] map[score:7.8865616909793435 type:quiz] map[score:22.860114572528147 type:homework] map[score:80.85669686147487 type:homework]]
student ID:  0
class ID: 39
grades:  [map[score:6.267513889635468 type:exam] map[score:23.8466262779109 type:quiz] map[score:42.52700970652198 type:homework] map[score:76.22758120978754 type:homework]]
student ID:  0
class ID: 391
grades:  [map[score:41.25131199553351 type:exam] map[score:91.7351500084582 type:quiz] map[score:24.198828271948415 type:homework] map[score:79.77471812670814 type:homework]]

//main.go
package main

import (
"context"
"fmt"
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://bob:password@cluster0.yvyo2.mongodb.net/test?retryWrites=true&w=majority"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 100*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)

/*
err = client.Ping(ctx, readpref.Primary())
if err != nil {
log.Fatal(err)
}
databases, err := client.ListDatabaseNames(ctx, bson.M{})
err = client.Ping(ctx, readpref.Primary())
if err != nil {
log.Fatal(err)
}
fmt.Print(databases)
*/
trainingDatabase := client.Database("sample_training")
gradesCollection := trainingDatabase.Collection("grades")

cursor, err := gradesCollection.Find(ctx, bson.M{})
/*
if err != nil {
log.Fatal(err)
}
var grades []bson.M
if err = cursor.All(ctx, &grades); err != nil {
log.Fatal(err)
}
fmt.Println(grades)
*/
defer cursor.Close(ctx)

for i := 0; cursor.Next(ctx) && i < 5; i++ {
var grade bson.M
if err = cursor.Decode(&grade); err != nil {
log.Fatal(err)
}
fmt.Println("student ID: ", grade["student_id"])
fmt.Println("class ID:", grade["class_id"])
fmt.Println("grades: ", grade["scores"])
}
}

Cottage Rose by Tim Janis

Monday 19 October 2020

坐哈大高铁看中华粮仓

go web app 4 mongodb 1

mongodb compass displays several database on mongodb cloud cluster
 
//cmd - install driver
go get go.mongodb.org/mongo-driver/mongo

//cmd - connect to database
C:\Users\bob\golang3>go run main.go
[sample_airbnb sample_analytics sample_geospatial sample_mflix sample_restaurants sample_supplies sample_training sample_weatherdata admin local]

//main.go
package main

import (
"context"
"fmt"
"log"
"time"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
)

func main() {
client, err := mongo.NewClient(options.Client().ApplyURI("mongodb+srv://bob:password@cluster0.yvyo2.mongodb.net/test?retryWrites=true&w=majority"))
if err != nil {
log.Fatal(err)
}
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
err = client.Connect(ctx)
if err != nil {
log.Fatal(err)
}
defer client.Disconnect(ctx)
err = client.Ping(ctx, readpref.Primary())
if err != nil {
log.Fatal(err)
}
databases, err := client.ListDatabaseNames(ctx, bson.M{})
err = client.Ping(ctx, readpref.Primary())
if err != nil {
log.Fatal(err)
}
fmt.Print(databases)
}

Sunday 18 October 2020

go web app 3 mysql

//cmd - install mysql driver

C:\Users\bob\golang2>go get -u github.com/go-sql-driver/mysql

//cmd - insert

C:\Users\bob\golang2>go run main.go
Go MySQL Tutorial
Successfully Connected to MySQL database
Successfully inserted into table1

names inserted into mysql table

 // cmd - select

C:\Users\bob\golang2>go run main.go
Go MySQL Tutorial
Successfully Connected to MySQL database
Bob
Jack
Sam

//main.go

package main

import (
"database/sql"
"fmt"

_ "github.com/go-sql-driver/mysql"
)

func main() {
fmt.Println("Go MySQL Tutorial")

db, err := sql.Open("mysql", "root:password@tcp(127.0.0.1:3306)/testdb")

if err != nil {
panic(err.Error())
}

defer db.Close()

fmt.Println("Successfully Connected to MySQL database")

/*
insert, err := db.Query("INSERT INTO table1 (name) VALUES('Bob'), ('Jack'), ('Sam')")

if err != nil {
panic(err.Error())
}

defer insert.Close()

fmt.Println("Successfully inserted into table1")
*/

results, err := db.Query("SELECT name FROM table1")

if err != nil {
panic(err.Error())
}

for results.Next() {
name := ""

err = results.Scan(&name)

if err != nil {
panic(err.Error())
}

fmt.Println(name)
}
}