id
stringlengths
2
7
text
stringlengths
17
51.2k
title
stringclasses
1 value
c173700
{ return nil, false } return list.first.payload, true }
c173701
list.first.next list.length-- if 0 == list.length { list.last = nil } return retval, true }
c173702
list.first = nil } else { node, _ := get(list.first, list.length-1) node.next = nil } return retval, true }
c173703
comparator) if err != nil { return err } list.last = findLast(list.first) return err }
c173704
return 0, ErrUnexpectedType } return strings.Compare(castA, castB), nil }) list.last = findLast(list.first) return err }
c173705
0, ErrUnexpectedType } return castA - castB, nil }) if err != nil { return } list.last = findLast(list.first) return }
c173706
== nil || current.next == nil { builder.Truncate(builder.Len() - 1) } else { builder.WriteString("...") } builder.WriteRune(']') return builder.String() }
c173707
'x', wanted less than %d got %d", list.length, x) } if temp, ok := get(list.first, y); ok { yNode = temp } else { return fmt.Errorf("index out of bounds 'y', wanted less than %d got %d", list.length, y) } temp := xNode.payload xNode.payload = yNode.payload yNode.payload = temp return nil }
c173708
break // Don't return, stitch the remaining elements back on. } else if res < 0 { appendResults(curLeft) curLeft = curLeft.next } else { appendResults(curRight) curRight = curRight.next } } if curLeft != nil { appendResults(curLeft) } if curRight != nil { appendResults(curRight) } return }
c173709
{ prev = right right = right.next sprinter = sprinter.next.next } prev.next = nil return }
c173710
= NewLinkedList() } q.underlyer.AddBack(entry) }
c173711
defer q.key.RUnlock() return q.underlyer.Enumerate(cancel) }
c173712
q.key.RUnlock() return q.underlyer == nil || q.underlyer.IsEmpty() }
c173713
if nil == q.underlyer { return 0 } return q.underlyer.length }
c173714
return nil, false } return q.underlyer.RemoveFront() }
c173715
return nil, false } return q.underlyer.PeekFront() }
c173716
return []interface{}{} } return q.underlyer.ToSlice() }
c173717
windows.SetConsoleMode(windows.Handle(fd), st|windows.ENABLE_VIRTUAL_TERMINAL_PROCESSING) } return nil }
c173718
unquotedLen := len(unquoted) for i := 0; i < runeLen; i++ { unquoted = append(unquoted, 0) } utf8.EncodeRune(unquoted[unquotedLen:], r) } else { unquoted = append(unquoted, byte(r)) } } if len(buf) < len(unquoted) { // used buf up and resorted to memory allocation remainder = nil } else { remainder = buf[len(unquoted):] } return unquoted, remainder }
c173719
case keyvalser: return i } } return len(input) }
c173720
return terminal.IsTerminal(fd) } return false }
c173721
l.underlyer = append(l.underlyer, entries...) }
c173722
l.underlyer = append(l.underlyer[:pos], append(entries, l.underlyer[pos:]...)...) }
c173723
select { case retval <- entry: break case <-cancel: return } } }() return retval }
c173724
return nil, false } return l.underlyer[pos], true }
c173725
return 0 == len(l.underlyer) }
c173726
return uint(len(l.underlyer)) }
c173727
retval := l.underlyer[pos] l.underlyer = append(l.underlyer[:pos], l.underlyer[pos+1:]...) return retval, true }
c173728
count := uint(len(l.underlyer)) if pos > count { retval = false } else { l.underlyer[pos] = val retval = true } return retval }
c173729
} builder.WriteString(fmt.Sprintf("%v ", entry)) } builder.Truncate(builder.Len() - 1) builder.WriteRune(']') return builder.String() }
c173730
l.key.Lock() defer l.key.Unlock() return l.swap(x, y) }
c173731
bytes.Buffer l.writeToBuffer(&buf) return buf.Bytes(), nil }
c173732
0 { list = append(list, "msg", string(m.Text)) } for _, v := range m.List { list = append(list, string(v)) } *l = list return nil }
c173733
if ok { return formatFunc(t) } return formatNanoForMatch(match, t) }
c173734
} return fmtRe.ReplaceAllStringFunc(format, fn) }
c173735
t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second(), pid) return name, program + "." + tag }
c173736
monotime() return time.Duration(sec*1000000000 + int64(nsec)) }
c173737
atomic.StoreInt32((*int32)(s), int32(val)) }
c173738
if err != nil { return err } threshold = Severity(v) } *s = threshold return nil }
c173739
atomic.StoreInt32((*int32)(l), int32(val)) }
c173740
match, _ := filepath.Match(m.pattern, file) return match }
c173741
f.regexp.MatchString(path) }
c173742
i := strings.LastIndex(file, "/"); i >= 0 { file = file[i+1:] } return t.file == file }
c173743
&logging.stats.Warning logging.severityStats[ErrorLog] = &logging.stats.Error logging.logDirs = append(logging.logDirs, os.TempDir()) go logging.flushDaemon() return logging }
c173744
l.mu.Lock() defer l.mu.Unlock() l.logDirs = append([]string{logDir}, l.logDirs...) } }
c173745
defer l.mu.Unlock() l.toStderr = f }
c173746
defer l.mu.Unlock() l.alsoToStderr = f }
c173747
l.vfilepath.filter = filepaths } nfilters = len(l.vmodule.filter) + len(l.vfilepath.filter) l.vmap = make(map[uintptr]Level) } // Things are consistent now, so enable filtering and verbosity. // They are enabled in order opposite to that in V. atomic.StoreInt32(&l.filterLength, int32(nfilters)) l.verbosity.set(verbosity) }
c173748
l.freeList = b.next } l.freeListMu.Unlock() if b == nil { b = new(buffer) } else { b.next = nil b.Reset() } return b }
c173749
l.freeListMu.Lock() b.next = l.freeList l.freeList = b l.freeListMu.Unlock() }
c173750
goroutines to the files. trace := stacks(true, l.maxStackBufSize) logExitFunc = func(error) {} // If we get a write error, we'll still exit below. for log := FatalLog; log >= InfoLog; log-- { if f := l.file[log]; f != nil { // Can be nil if -logtostderr is set. f.Write(trace) } } l.mu.Unlock() timeoutFlush(l, 10*time.Second) os.Exit(255) // C++ uses -1, which is silly because it's anded with 255 anyway. } l.putBuffer(buf) l.mu.Unlock() if stats := l.severityStats[s]; stats != nil { atomic.AddInt64(&stats.lines, 1) atomic.AddInt64(&stats.bytes, int64(len(data))) } }
c173751
done <- true }() select { case <-done: case <-time.After(timeout): fmt.Fprintln(os.Stderr, "glog: Flush took longer than", timeout) } }
c173752
make([]byte, n) nbytes := runtime.Stack(trace, all) if nbytes < len(trace) { return trace[:nbytes] } n *= 2 } return trace }
c173753
instead of exiting. if logExitFunc != nil { logExitFunc(err) return } l.flushAll() os.Exit(2) }
c173754
%s\n", host) fmt.Fprintf(&buf, "Binary: Built with %s %s for %s/%s\n", runtime.Compiler, runtime.Version(), runtime.GOOS, runtime.GOARCH) fmt.Fprintf(&buf, "Log line format: [IWEF]mmdd hh:mm:ss.uuuuuu threadid file:line] msg\n") n, err := sb.file.Write(buf.Bytes()) sb.nbytes += uint64(n) return err }
c173755
l.file[s] == nil; s-- { w, err := newFlushSyncWriter(l, s, now) if err != nil { return err } l.file[s] = w } return nil }
c173756
time.NewTicker(flushInterval).C { l.lockAndFlushAll() } }
c173757
l.flushAll() l.mu.Unlock() }
c173758
file.Flush() // ignore error file.Sync() // ignore error } } }
c173759
} // On first error, cancel the context and save the error. b.errorOnce.Do(func() { b.firstError = err b.cancel() }) }() }
c173760
avoid leaking resources. Since everything is done, // to do so now is harmless. b.cancel() return b.firstError }
c173761
b.cancel = context.WithCancel(parent) return b }
c173762
result = append(result, tokens[start]) } if tokens[i+1].typ == openToken { if i, err = tokens.findClose(start + 1); err != nil { return nil, err } } else { i = start } result = append(result, &Token{openToken, "("}, &Token{symbolToken, "quote"}) result = append(result, tokens[start:i+1]...) result = append(result, &Token{closeToken, ")"}) } } if updated { result, err = result.Expand() } return }
c173763
return Cache(http.HandlerFunc(bodyHandler), expiration).ServeHTTP }
c173764
return fhttp.NewHandler(bodyHandler, expiration) }
c173765
return CacheFasthttp(bodyHandler, expiration).ServeHTTP }
c173766
== "" { r.contentType = "text/html; charset=utf-8" } return r.contentType }
c173767
method, let's save a cached entry ") // get the cache expiration via url param expirationSeconds, err := getURLParamInt64(r, cfg.QueryCacheDuration) // get the body from the requested body // get the expiration from the "cache-control's maxage" if no url param is setted if expirationSeconds <= 0 || err != nil { expirationSeconds = int64(nethttp.GetMaxAge(r)().Seconds()) } // if not setted then try to get it via if expirationSeconds <= 0 { expirationSeconds = int64(cfg.MinimumCacheDuration.Seconds()) } cacheDuration := time.Duration(expirationSeconds) * time.Second // store by its url+the key in order to be unique key among different servers with the same paths s.store.Set(key, statusCode, contentType, body, cacheDuration) } else { // update an existing one and change its duration based on the header // (if > existing duration) entry.Reset(statusCode, contentType, body, nethttp.GetMaxAge(r)) } w.WriteHeader(cfg.SuccessStatus) } case methodDelete: { // remove the entry entirely from the cache // manually DELETE cache should remove this entirely // no just invalidate it s.store.Remove(key) w.WriteHeader(cfg.SuccessStatus) } default: w.WriteHeader(cfg.FailStatus) } }
c173768
return &http.Server{ Addr: addr, Handler: h, } }
c173769
*ResponseRecorder if v != nil { res = v.(*ResponseRecorder) } else { res = &ResponseRecorder{} } res.underline = underline return res }
c173770
= nil res.statusCode = 0 res.chunks = res.chunks[0:0] rpool.Put(res) }
c173771
// for this specific request, then skip the whole cache for _, shouldProcess := range v.preValidators { if !shouldProcess(r) { return false } } return true }
c173772
nothing passed then use the allow-everyting rule r = rule.Satisfied() } h.rule = r return h }
c173773
} if contentType != "" { e.response.contentType = contentType } e.response.body = body // check if a given life changer provided // and if it does then execute the change life time if lifeChanger != nil { e.ChangeLifetime(lifeChanger) } e.expiresAt = time.Now().Add(e.life) }
c173774
reqCtx.Response.Header.Set(cfg.NoCacheHeader, "true") }
c173775
Tokens: tokens, BaseUrl: config.BaseUrl, Client: http.Client{ Transport: &http.Transport{ Dial: dialTimeout, }, }, } return &a }
c173776
are expired. Use refreshTokens to refresh them") } req.Header.Set("Authorization", "Bearer "+a.Tokens.AccessToken) return nil }
c173777
Transport: &http.Transport{ Dial: dialTimeout, }, }, } return &a }
c173778
per Coinbase Documentation req.Header.Set("ACCESS_KEY", a.Key) h := hmac.New(sha256.New, []byte(a.Secret)) h.Write([]byte(message)) signature := hex.EncodeToString(h.Sum(nil)) req.Header.Set("ACCESS_SIGNATURE", signature) req.Header.Set("ACCESS_NONCE", nonce) return nil }
c173779
a := serviceOAuthAuthentication{ BaseUrl: "https://coinbase.com/", Client: http.Client{ Transport: &http.Transport{ Dial: dialTimeout, TLSClientConfig: mTLSConfig, }, }, } return &a, nil }
c173780
No additional headers needed for service OAuth requests }
c173781
ClientId: clientId, ClientSecret: clientSecret, RedirectUri: redirectUri, Rpc: rpc{ auth: serviceAuth, mock: false, }, } return &o, nil }
c173782
parameters.Add("response_type", "code") parameters.Add("client_id", o.ClientId) parameters.Add("redirect_uri", o.RedirectUri) parameters.Add("scope", strings.Join(scope, " ")) Url.RawQuery = parameters.Encode() return Url.String() }
c173783
:= oldTokens["refresh_token"].(string) return o.GetTokens(refresh_token, "refresh_token") }
c173784
o.GetTokens(code, "authorization_code") }
c173785
{ query := req.URL.Query() code := query.Get("code") return o.GetTokens(code, "authorization_code") }
c173786
data, err = r.simulateRequest(endpoint, method) } else { data, err = r.executeRequest(request) } if err != nil { return err } if err := json.Unmarshal(data, &holder); err != nil { return err } return nil }
c173787
Authenticate the request r.auth.authenticate(req, endpoint, params) req.Header.Set("User-Agent", "CoinbaseGo/v1") req.Header.Set("Content-Type", "application/json") return req, nil }
c173788
log.Printf("Response body:\n\t%s\n", bytes) } return nil, fmt.Errorf("%s %s failed. Response code was %s", req.Method, req.URL, resp.Status) } return bytes, nil }
c173789
basePath + "/test_data/" + method + "_" + fileName + ".json" data, err := ioutil.ReadFile(filePath) if err != nil { return nil, err } return data, nil }
c173790
apiKeyAuth(key, secret), mock: false, }, } return c }
c173791
rpc: rpc{ auth: clientOAuth(tokens), mock: false, }, } return c }
c173792
return c.rpc.Request("GET", path, params, &holder) }
c173793
err != nil { return 0.0, err } balanceFloat, err := strconv.ParseFloat(balance["amount"], 64) if err != nil { return 0, err } return balanceFloat, nil }
c173794
layer of nesting for _, addr := range holder.Addresses { addresses.Addresses = append(addresses.Addresses, addr.Address) } return &addresses, nil }
c173795
c.Post("account/generate_receive_address", params, &holder); err != nil { return "", err } return holder["address"].(string), nil }
c173796
c.transactionRequest("POST", "send_money", params) }
c173797
c.transactionRequest("POST", "request_money", params) }
c173798
false, err } if holder["success"].(bool) { return true, nil } return false, nil }
c173799
false, err } if holder["success"].(bool) { return true, nil } return false, nil }