Skip to content

Instantly share code, notes, and snippets.

View yudai's full-sized avatar

Iwasaki Yudai yudai

View GitHub Profile
func someCaller () error {
err := CopyFile(src, dst)
if err != nil {
return fmt.Errorf("copy file failed: %s %s: %v", src, dst, err)
func CopyFile(src, dst string) error {
r, err := os.Open(src)
if err != nil {
func (t *Periodic) Run() {
t.ctx, t.cancel = context.WithCancel(context.Background())
interval := t.getInterval()
num := int(t.period / interval) // number of revs to keep for t.period
notify := make(chan struct{}) // interval is defined as "duration from the last successfull compaction"
// notify := make(chan struct{}, 1) // interval is defined as "duration from the last expexcted time of compaction nethersless its result"
retryInterval := interval / 10
// periodically updates t.revs and notify to the other goroutine
go func() {
// Collect rev 10 times frequently than the actual interval
// so that we can retry in error case with a shorter delay
const intervalCoefficient = 10
func (t *Periodic) Run() {
t.ctx, t.cancel = context.WithCancel(context.Background())
interval := t.getInterval()
subInterval := interval / intervalCoefficient
// expected amount of revs after t.period
expectedNum := int(math.Ceil(float64(t.period) / float64(subInterval)))
yudai / stale_tcp.go
Created January 24, 2018 04:44
Reproducer for stale tcp sessions
package main
// Build and run as root since this code uses iptables to emulate a network outage.
// Make sure rules in iptables are cleared:
// sudo iptables -D INPUT -j DROP -p tcp --destination-port 2379; sudo iptables -D INPUT -j DROP -p tcp --source-port 2379
import (
yudai /
Created November 29, 2017 01:04
tmux + mosh OSC 52 clipboard paste hack


Now tmux, mosh and iTerm2 support the OSC 52 sequence that enables clipboard sharing. However, there is a trap that prevents them from working together.

Mosh accepts OSC 52 sequences with the c; option. However, tmux doesn't send that option when it emits OSC 52 sequences, which means you cannot use tmux and mosh together with the default configuration.


You can override the OSC 52 sequence generated by tmux by adding the following line to your tmux.conf.

// ForwardResponseStream forwards the stream from gRPC server to REST client.
func ForwardResponseStream(ctx context.Context, marshaler Marshaler, w http.ResponseWriter, req *http.Request, recv func() (proto.Message, error), opts ...func(context.Context, http.ResponseWriter, proto.Message) error) {
// f, ok := w.(http.Flusher)
// if !ok {
// grpclog.Printf("Flush not supported in %T", w)
// http.Error(w, "unexpected type of web server", http.StatusInternalServerError)
// return
// }
md, ok := ServerMetadataFromContext(ctx)
yudai / client_factory.go
Created March 22, 2017 21:58
custom factory
package somepackage
import (
libcomposeclient ""
type clientFactory struct {
client *client.Client


Oracle v. GoogleのAPI著作権裁判の話(連邦最高裁)

Oracle v. Google API Fair Use訴訟の話(連邦地裁編)

2016年5月26日付で、合衆国連邦地裁(Federal District Court)において、いわゆる「Java API著作権裁判」について、「GoogleのJava API使用はフェアユースである」という陪審員評決が出たと報道されている。


func (r *Runner) Start(handler func([T]), channel chan [T]) {
go func() {
for {
select {
case i := <-runner.Interrupt:
case msg := <-channel
yudai / gist:6f8f44ac878c41eaf7dc
Last active November 7, 2023 08:35
Google v. Oracle API著作権裁判

Oracle v. GoogleのAPI著作権裁判の話


全体の内容としては比較的単純で「あらゆるプログラムのコードは著作権で保護される。ただしFair Useによる合法的な利用に関しては差し戻し審で審議せよ」という事のようだ。実は「API」という言葉は一切判決文には出てこないため、内容を良く読む必要がある。

17 U.S.C. 102(b)を巡るGoogleの主張