2018/10/25

gvm GoのVersion管理を楽に

GoのVersion管理を楽に
<(curl -s -S -L https://raw.githubusercontent.com/moovweb/gvm/master/binscripts/gvm-installer)
source /Users/xxx/.gvm/scripts/gvm
gvm version
gvn listall
//-B binary only,no source file
gvm install go1.9.5 -B
gvm install go1.11.1 -B
gvm use go1.11.1 --default

go version

///Users/kouha.shu/.gvm/gos/go1.11.1
echo $GOROOT

///Users/xxx/.gvm/pkgsets/go1.11.1/global
echo $GOPATH

2018/10/19

gorm transaction

TransactionsTo perform a set of operations within a transaction, the general flow is as below.
// begin a transaction
tx := db.Begin()

// do some database operations in the transaction (use 'tx' from this point, not 'db')
tx.Create(...)

// ...

// rollback the transaction in case of error
tx.Rollback()

// Or commit the transaction
tx.Commit()

2018/10/16

Graphql


more easier than RESTAPIClient側のRequestを柔軟に対応できる感じで
 QueryLanguage!条件は自分で指定し、結果を返す
 QueryLanguageをサポートするServicesTypeFieldFunctions

What kinds of objects might they return? What fields are available on those sub-objects? That's where the schema comes in.

A GraphQL service is created by defining types and fields on those types,then providing functions for each field on each type.

Once a GraphQL service is running (typically at a URL on a web service), 
 it can be sent GraphQL queries to validate and execute. 
 A received query is first checked to ensure it only refers to the types and fields defined, then runs the provided functions to produce a result.

Learn more about GraphQL—the query language, type system, how the GraphQL service works, 

Like many type systems, GraphQL supports interfaces

the query has exactly the same shape as the result. This is essential to GraphQL, because you always get back what you expect, and the server knows exactly what fields the client is asking for.==>後で統計、分析できるね!

GraphQL queries can traverse related objects and their fields, 
 letting clients fetch lots of related data in one request, 
 instead of making several roundtrips as one would need in a classic REST architecture.

GraphQL, every field and nested object can get its own set of arguments, making GraphQL a complete replacement for making multiple API fetches. 
↓↓heightFOOT単位で返す
{
  human(id: "1000") {
    name
    height(unit: FOOT)
  }
}

have reusable units called fragments. Fragments let you construct sets of fields, and then include them in queries where you need to.
=>重複する部分をFragmentとして定義し、使うところでIncludeする感じ
    …some Fragement


・「query HeroNameAndFriends
  query->operation type
      HeroNameAndFriends—>operation name


 GraphQL has a first-class way to factor dynamic values out of the query, and pass them as a separate dictionary. These values are called variables.
    can have default value
    @include—>directive 
     @skip(if: Boolean)—>directive 
 query HeroNameAndFriends($episode: Episode = XXX,$withFriends) {
    hero(episode: $episode) {
            name
            friend @include(if: $withFriends)
   }
    }


mutationー>POST it (更新) then  GET 更新結果
mutation CreateReviewForEpisode($ep: Episode!, $review: ReviewInput!) {
  createReview(episode: $ep, review: $review) {
    stars
    commentary
  }
}

While query fields are executed in parallel, mutation fields run in series, one after the other.


inline Fragment
query HeroForEpisode($ep: Episode!) {
  hero(episode: $ep) {
    name
#__typename, a meta field, when you dont know the type, you can use it 
# when ep is Droid
    ... on Droid {
      primaryFunction
    }
# when ep is Human
    ... on Human {
      height
    }
  }
}


query HeroNameAndFriends {
  hero {
    name
    friends {
      name
    }
  }
}

query(request) Sample

{
  human(id: "1000") {
    name
    height
  }
   # Queries can have comments!
    friends {
      name
    }
}

DataResponse
{
  "data": {
    "hero": {
      "name": "R2-D2",
     height: 170.2
      "friends": [
        {
          "name": "Luke Skywalker"
        },
        {
          "name": "Han Solo"
        },
        {
          "name": "Leia Organa"
        }
      ]
    }
  }
}


docker gae EMPTRY_RESPONSE


docker+gaeの構成で、Admin Consoleを見たいが、EMPTRY_RESPONSEで見えない。。

EMPTRY_RESPONSE means that the TCP connection into the docker container seemed to be sucessful, 
however the server side closed the connection without sending anything back. 

curl -v http://localhost:8000 


Your issue is that you are binding to the 127.0.0.1:8025 inside your code. This makes the code work from inside the container but not outside.
You need to bind to 0.0.0.0:8025 to bind to all interfaces inside the container. So traffic coming from outside of the container is also accepted by your Go app

When you get this error it means youve exposed the right port in your Dockerfile, 
but you have to make sure the app within your container is binding to 0.0.0.0 instead of localhost or 127.0.0.1.
I got this error using Angular CLIng serve within a container. 
I had to add –host=0.0.0.0 to the ENTRYPOINT arguments. 
If youre using a different framework check for a similar command-line argument, configuration parameter or setting.

・解決!—port 8080 --admin_port 8000 --skip_sdk_update_check yes --host 0.0.0.0
--admin_hostデフォルトはlocalhost—admin_host 0.0.0.0 を追加して見える
--admin_host=ADMIN_HOST
ローカル開発用サーバーの管理コンソールがバインドするホスト名(デフォルト: localhost)。
--admin_port=ADMIN_PORT

2018/10/11

window7 テザリング 制限付き接続

家のAU光が接続障害になり、
携帯でテザリングし、Macはすぐ上手く行くが、
window7 テザリング 制限付き接続になり、ネットアクセスできない。。一瞬できたこともあり、

電源プランを高パフォーマンスにし、上手くできた。。。意味が何となくわからない。。

2018/09/30

gae log

"google.golang.org/appengine/log"を使う
golangの標準のlogではなく。 

2018/09/29

go project .ignore

.DS_Store
*.[56789ao]
*.a[56789o]
*.so
*.pyc
._*
.nfs.*
[56789a].out
*~
*.orig
*.rej
*.exe
.*.swp
core
*.cgo*.go
*.cgo*.c
_cgo_*
_obj
_test
_testmain.go

/VERSION.cache
/bin/
/build.out
/doc/articles/wiki/*.bin
/goinstall.log
/last-change
/misc/cgo/life/run.out
/misc/cgo/stdio/run.out
/misc/cgo/testso/main
/pkg/
/src/*.*/
/src/cmd/cgo/zdefaultcc.go
/src/cmd/dist/dist
/src/cmd/go/internal/cfg/zdefaultcc.go
/src/cmd/go/internal/cfg/zosarch.go
/src/cmd/internal/objabi/zbootstrap.go
/src/go/build/zcgo.go
/src/go/doc/headscan
/src/runtime/internal/sys/zversion.go
/src/unicode/maketables
/test.out
/test/garbage/*.out
/test/pass.out
/test/run.out
/test/times.out

# This file includes artifacts of Go build that should not be checked in.
# For files created by specific development environment (e.g. editor),
# use alternative ways to exclude files from git.
# For example, set up .git/info/exclude or use a global .gitignore.

2018/09/25

Python class method return None

cat = Cat()
print(cat.sound())

-->
--miao--
None
が出力される。class's method will return None defaultly,that means method executed successfully!
詳しく↓

On the actual behavior, there is no difference. They all return None and that's it. However, there is a time and place for all of these. The following instructions are basically how the different methods should be used (or at least how I was taught they should be used), but they are not absolute rules so you can mix them up if you feel necessary to.

Using return None

This tells that the function is indeed meant to return a value for later use, and in this case it returns None. This value None can then be used elsewhere. return None is never used if there are no other possible return values from the function.
In the following example, we return person's mother if the person given is a human. If it's not a human, we return None since the person doesn't have a mother (let's suppose it's not an animal or so).
def get_mother(person):
    if is_human(person):
        return person.mother
    else:
        return None

Using return

This is used for the same reason as break in loops. The return value doesn't matter and you only want to exit the whole function. It's extremely useful in some places, even tho you don't need it that often.
We got 15 prisoners and we know one of them has a knife. We loop through each prisoner one by one to check if they have a knife. If we hit the person with a knife, we can just exit the function cause we know there's only one knife and no reason the check rest of the prisoners. If we don't find the prisoner with a knife, we raise an the alert. This could be done in many different ways and using return is probably not even the best way, but it's just an example to show how to use return for exiting a function.
def find_prisoner_with_knife(prisoners):
    for prisoner in prisoners:
        if "knife" in prisoner.items:
            prisoner.move_to_inquisition()
            return # no need to check rest of the prisoners nor raise an alert
    raise_alert()
Note: You should never do var = find_prisoner_with_knife(), since the return value is not meant to be caught.

Using no return at all

This will also return None, but that value is not meant to be used or caught. It simply means that the function ended successfully. It's basically the same as return in void functions in languages such as C++ or Java.
In the following example, we set person's mother's name, and then the function exits after completing successfully.
def set_mother(person, mother):
    if is_human(person):
        person.mother = mother
Note: You should never do var = set_mother(my_person, my_mother), since the return value is not meant to be caught.

2018/09/24

Great! get source code in Python

Google BloggerのPythonLibを使って、Bloggerを操作したいですが、Docはどこにもない。。Great! get source code in Python
http = credentials.authorize(http = httplib2.Http())
service = build('blogger','v3',http=http)
posts = service.posts() 
#for x in inspect.getmembers(posts,inspect.ismethod or inspect.isfunction):
# print(x)
  print(inspect.getsource(posts.update))

Difference between Method and Function in Python

Python Method
  1. Method is called by its name, but it is associated to an object (dependent).
  2. A method is implicitly passed the object on which it is invoked.
  3. It may or may not return any data.
  4. A method can operate on the data (instance variables) that is contained by the corresponding class  
Functions
  1. Function is block of code that is also called by its name. (independent)
  2. The function can have different parameters or may not have any at all. If any data (parameters) are passed, they are passed explicitly.
  3. It may or may not return any data.
  4. Function does not deal with Class and its instance concept. 
Difference between method and function
  1. Simply, function and method both look similar as they perform in almost similar way, but the key difference is the concept of ‘Class and its Object‘.
  2. Functions can be called only by its name, as it is defined independently. But methods can’t be called by its name only, we need to invoke the class by a reference of that class in which it is defined, i.e. method is defined within a class and hence they are dependent on that class.

2018/04/20

有感于AWS

市场最下层存在着最本质,最难以解决的特征。
有了好的方案,怎么迅速从最下层发展到最上层,值得研究

2018/04/03

2018/03/28

spring的想法

能不能用spring的想法来服务现实世界呢!?让控制反转来减轻客户的负担!能实现的话真是太棒了!

一般的买东西==去买,自己行动
定期便==cron,定时的执行,没有什么新意

仔细分析一下:
需要的时候就被提供。怎么知道需要呢?用到了,用的时候直接取,已经准备好了,提供了。。。

比如说厕所手纸,
基本上可以实现,使用的频率,家族构成,日程,分析一下,判断什么时候需要买手纸了。
手纸的话,价格,品牌可以事先设定。。。
数据分析,AI?!!
世界还在发展中。。。

对,准备一个特定的容器,刚开始是满的,没有了的话,自动补充。。。。!

这个容器是象征性的还是实物呢?
实物的话,就变成仓库了。
象征性的话,得想办法反应现实世界。。
自动并且准确的反应现实世界,然后行动

2018/03/27

TypeConverterDelegate.doConvertTextValue

目的是想解决gcs的resource数组对应问题。

editer.setAsText()
这个地方很重要啊,好像是做一些转换
不同类型的resource被不同的类处理?
Resource[]被安排到了ResourceArrayPropertyEditor了
这里面没有对应的protocolReslover是问题点。
对比单个gcs resource 的流程可以洞晓

在GoogleStorage Protocol Resolver
里添加相应的处理就可以了?!

Google_application_credentials

好像是gcloud或者机器登录帐号,或者安装gcp sdk的时候,这个变量被设置了。
gcloud auth login
设置了之后,eclipse还是用另外一个账号。。
为什么呢?以前解决了,又忘记了。。。
写在笔记本上也找不着了。

细细地查了一下

gcloud auth application-default login

试了一下,可以了。。。

在我可以理解的范围之内,我只能理解成故弄玄虚。。