Go go go programming facts 2

現在說一下關於Go的數據結構

Arrays - 固定大小

slices - 不固定大小

maps - 一個Hashtable

宣告一個Array

用數據來宣告和初始化一個Array

由Go來計算Array的數量

指定特定位置的數據

Points of array, 0和1初始化為一個int pointer

Array複製, 有兩份數據

Array pointer複製, 雖然有兩份數據, 但pointer指向同一組string

二維數組

以Pointer來傳Array入函數中

創建一個slice,長度和容量皆為5

長度為3,容量為5

slice帶內容

指定某一位置的內容

nil slice

空的slice

取得部份slice,兩個slice指向同一份數據,newSlice的長度為2,容量為4

為slice增加數據,append後slice為[10,20,30,60,50]

append會增加slice的長度和容量,現時當容量小於1000時,會以100%來增加容量,當超過1000時會以25%來增加

three-index slice,i為開始,j為結束,k-i為容量

定義長度和容量一致可以令到不會重寫原slice數據

Append另一個slice

for range

range的value為複製品

range ignore index

傳統for loop

多維度slice

傳送slice到function可以直接傳,因數據在底層Array,slice只包含pointer,長度和容量

創建一個Map

取得數值,檢查key是否存在

Loop map

移除項目

map傳入function,直接傳就可以

 

Go go go playground

Pointer & value

http://play.golang.org/p/VDvDqfAz7O

Go go go programming facts 1

  • 所有代碼文件都屬於一個package,package的名字應該同代碼所在文件夾名一致
  • Go提供好多不同宣告和初始代變量的方法,如果變量沒有被初始化,會設定為Zero
  • 指針是一種在func/goroutines間共用數據的方法
  • Concurrency和Synchronization使用goroutines和Channel來實現
  • Go提供Built-in func來支持內部數據結構
  • Go標準庫提供強大的功能
  • Interfaces令你可以寫一些通用代碼和框架

#所有變量都係passed by value,你可以pass pointer,(All variables are passed by value);

func f(pointer *Type)

#Map可以返回第二個返回值來確定這個key, value是否存在;

value, exists := map[key]

#For loop使用range來進行assigment,第一個返回值為index,使用_來ignore;

for _, value := range array {

}

#用go來運行go routine;

go func(matcher Matcher, feed *Feed) {

}(matcher, feed);

#讀取json文件,先定義結構

type Feed struct {
Name string `json:”site”`
URI string `json:”link”`
Type string `json:”type”`
}
var feeds []*Feed

err = json.NewDecoder(file).Decode(&feeds) // &feeds get pointer of feeds

#Decode這個func,由於使用特殊的參數,可以接受所有種類的值

func (dec *Decoder) Decode(v interface{}) error

#用defer來設定當Func返回後要運行的代碼

func somefunc() {
// open file
defer file.Close()
}

#Interface如果只有一個Func,以er結尾

type Matcher interface {
Search(feed *Feed, searchTerm string) ([]*Result, error)
}

#實現Interface,可以使用 func (m defaultMatcher) 或 func (m *defaultMatcher)來定義,最佳做法是使用 func (m *defaultMatcher)

func (m defaultMatcher) Search(feed *Feed, searchTerm string) ([]*Result, error) {
return nil, nil
}

#func call例子

// Method declared with a value receiver of type defaultMatcher
func (m defaultMatcher) Search(feed *Feed, searchTerm string)

// Declare a pointer of type defaultMatch
dm := new(defaultMatch)

// The compiler will dereference the dm pointer to make the call
dm.Search(feed, “test”)

// Method declared with a pointer receiver of type defaultMatcher
func (m *defaultMatcher) Search(feed *Feed, searchTerm string)

// Declare a value of type defaultMatch
var dm defaultMatch

// The compiler will reference the dm value to make the call
dm.Search(feed, “test”)

#init func,據聞會做一些init工作

func init() {
var matcher defaultMatcher
Register(“default”, matcher)
}

#Custom error message

return nil, fmt.Errorf(“HTTP Response Error %d\n”, resp.StatusCode)

#Create and append value to a pointer array

results = append(results, &search.Result{
Field: “Description”,
Content: channelItem.Description,
})

Go go go programming language

等我來玩一下Go language,首先她是opensource,有Google大神背後加持的新型法式巴黎鐵塔反轉再反轉程式語言。

有一個叫做 The Go Playground 的地方,可以等程序猿進行測試,分享代碼。

Go語言的特點:

  • 編譯快,據聞編譯整個Go source不用20秒(本人未試過)
  • Concurrency,據聞對Concurreny支持很好
  • Goroutines,應該是對Concurrenty的支持,可以在一個Thread運行多個Goroutines

  • 使用Channel來對Goroutines間Data進行同步,據聞是Goroutine 1經Channel來傳Data到Goroutine 2 … 其間兩個Goroutines都是同步的
  • Go的類型系統崇尚composition,基本上包含其他細類型到大類型中
  • Go的Interface描述簡單的行為,以下為一個常用Interface io.Reader需要實現數據讀取,接受byte array,返回一個int和是否有錯誤

  • 內存管理,據聞Go有一個好好用的內存管理系統

等我玩下先,完

iMac (Retina 4K, 21.5-inch, Late 2015) 安裝Windows 10後更新Intel Iris Pro Graphics 6200引致死機

今日係2016年4月2號,星期六,由於放假既關係,人一得閒就想搞下呢樣,搞下個樣,我幫部iMac安裝Microsoft最新既系統Windows 10,其實我係尋日開始已經進行緊呢個工作,唔知係咪因為4月1日既關係,每次當我完成安裝,更新後重新開機總會死機,Reboot要入Automatic Recovery,經歷過兩次重新安裝之後,我揾到呢個Post。

https://discussions.apple.com/thread/7441338?tstart=0

Windows-10-crashing-but-not-sure-why

元兇好有可能係Windows 10自己既Intel Iris Pro Driver(實際上應該係某個或多個Intel Driver造成,當有網絡Windows 10自動更新引起不定時死機),所以我又再一次重新安裝一次,以下為今次安裝步驟:

  • 使用BootCamp安裝前會以斷開網絡連線,正常使用Boot Camp來安裝Windows 10,安裝時要繼開所有USB硬碟/ThunderBult硬碟,我第一次安裝就由於無繼開所以不能安裝
  • 正常安裝Windows 10
  • 完成安裝Windows 10後,安裝BootCamp Driver
  • 在設定中關閉自動更新或刪除Intel Iris Pro更新,在設定不能關閉自動更新的
  • 建立還原點
  • 嘗試去Intel網站更新最新Intel Iris Pro Driver,實際上使用最新的Intel Iris Pro Driver都有可能引起問題

好吧,以上為測試過程,實際上可以肯定是由於Intel相關的Driver引致死機,所以解決方法為Block左Driver更新,以下為真。安裝步驟:

  • 正常使用Boot Camp安裝Windows
  • 開始安裝Windows 10,呢個時候要斷開網絡,因為安裝完成後隨時會自動更新,引發死機
  • 正常進入Windows 10,安裝Boot Camp相關程式,會安裝需要的Driver,安裝完成後係一個好時機去建立還原點
  • 按Win+R,輸入services.msc,揾到Windows Update,停用呢個service,Windows就唔會更新,此時此刻可以連接網絡
  • 在系統,在進階設定,硬件,裝置安裝設定,選擇否,呢招可以Block Driver更新,據聞係甘
  • 下載好Show/Hide Update呢個工具先,呢個工具用黎隱藏某啲更新,Window就唔會下載(曾經試過單純用呢招,安裝完更新後reboot,正常,過一段時間又有問題)
  • 在services.msc中,重新啓用Windows Update呢個service,啓用後立即使用Show/Hide Update呢個工具,選擇所有Intel相關既更新
  • 在設定中正常更新,更新時應該唔會見到Intel相關項目,reboot,完成

以下為Block Driver的相關文章,我都係用左其中一招,後續需要關心Intel/Microsoft/Apple係咪有解決方法,而家只係Block左Driver,唔算係治本方法。

本人回復左Windows大概有五六次,重新由Boot Camp安裝三四次,用左大半日終於可以玩Windows 10。

Privacy Policy

Your privacy is critically important to us. At DandaLab we have a few fundamental principles:

  • We don’t ask you for personal information unless we truly need it. (We can’t stand services that ask you for things like your gender or income level for no apparent reason.)
  • We don’t share your personal information with anyone except to comply with the law, develop our products, or protect our rights.
  • We don’t store personal information on our servers unless required for the on-going operation of one of our services.
  • In our blogging products, we aim to make it as simple as possible for you to control what’s visible to the public, seen by search engines, kept private, and permanently deleted.

This Privacy Policy is based on the one at http://automattic.com/privacy/ – thanks very much to the kind people at WordPress.com for allowing the world to re-use their content via a Creative Commons Attribution Sharealike license. Naturally, this policy is also under the same licence.

DandaLab Ltd (“DandaLab“) operates several websites including DandaLab.com as well as the Chinese Utility Android app, MathLink IOS app, SearchBox IOS app, Photofog IOS/Android app, ClipRx Android App. This privacy policy specifically relates to the DandaLab.com and the Chinese Utility Android application, MathLink IOS app, SearchBox IOS app, Photofog IOS/Android app, ClipRx Android App (collectively “DandaLab“). It is DandaLab’s policy to respect your privacy regarding any information we may collect while operating our websites and applications.

Website Visitors and App Users

Like most website and app operators, DandaLab collects non-personally-identifying information of the sort that web browsers and servers typically make available, such as the browser type, language preference, referring site, and the date and time of each visitor request. DandaLab’s purpose in collecting non-personally identifying information is to better understand how DandaLab’s visitors and customers use its products. From time to time, DandaLab may release non-personally-identifying information in the aggregate, e.g., by publishing a report on trends in the usage of its services.

Gathering of Personally-Identifying Information

Certain users or visitors of DandaLab choose to interact with DandaLab in ways that require DandaLab to gather personally-identifying information. The amount and type of information that DandaLab gathers depends on the nature of the interaction. For example, we ask customers who sign up for an account within the DandaLab mobile applications to provide an email address. In each case, DandaLab collects such information only insofar as is necessary or appropriate to fulfill the purpose of the user’s interaction with DandaLab. DandaLab does not disclose personally-identifying information other than as described below. And visitors can always refuse to supply personally-identifying information, with the caveat that it may prevent them from engaging in certain website-related activities.

Aggregated Statistics

DandaLab may collect statistics about the behavior of visitors to its websites and users of its iOS and Android applications. For instance, DandaLab will monitor usage of meditations as well as the information entered by users as part of their self-assessment “check-in” process.  DandaLab may display this information publicly or provide it to others. However, DandaLab does not disclose personally-identifying information other than as described below.

Protection of Certain Personally-Identifying Information

DandaLab discloses potentially personally-identifying and personally-identifying information only to those of its employees, contractors and affiliated organizations that (i) need to know that information in order to process it on DandaLab’s behalf or to provide services available on DandaLab, and (ii) that have agreed not to disclose it to others. Some of those employees, contractors and affiliated organizations may be located outside of your home country; by using DandaLab, you consent to the transfer of such information to them. DandaLab will not rent or sell potentially personally-identifying and personally-identifying information to anyone. Other than to its employees, contractors and affiliated organizations, as described above, DandaLab discloses potentially personally-identifying and personally-identifying information only when required to do so by law, or when DandaLab believes in good faith that disclosure is reasonably necessary to protect the property or rights of DandaLab, third parties or the public at large. If you have supplied your email address, DandaLab may occasionally send you an email to tell you about new features, solicit your feedback, or just keep you up to date with what’s going on with DandaLab. We primarily use our various blogs and social media accounts  to communicate this type of information, so we expect to keep this type of email to a minimum. If you send us a request (for example via a support email or via one of our feedback mechanisms), we reserve the right to publish it in order to help us clarify or respond to your request or to help us support other users. DandaLab takes all measures reasonably necessary to protect against the unauthorized access, use, alteration or destruction of potentially personally-identifying and personally-identifying information.

Ads

Ads appearing on any of our websites or apps may be delivered to users by advertising partners, who may set cookies. These cookies allow the ad server to recognize your computer each time they send you an online advertisement to compile information about you or others who use your computer or devices. This information allows ad networks to, among other things, deliver targeted advertisements that they believe will be of most interest to you. This Privacy Policy covers the use of cookies by DandaLab and does not cover the use of cookies by any advertisers.

Privacy Policy Changes

Although most changes are likely to be minor, DandaLab may change its Privacy Policy from time to time, and in DandaLab’s sole discretion. DandaLab encourages visitors to frequently check this page for any changes to its Privacy Policy. Your continued use of this site after any change in this Privacy Policy will constitute your acceptance of such change.