text stringlengths 11 4.05M |
|---|
package main
import (
"errors"
"net/http"
"github.com/SUSE/stratos-ui/components/app-core/backend/repository/interfaces"
"github.com/labstack/echo"
)
// Endpoint - This represents the CNSI endpoint
type Endpoint struct {
GUID string `json:"guid"`
Name string `json:... |
package azure
import (
"bufio"
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
)
// NewClient is the default constructor for creating a vision client using the api key.
func NewClient(emotionAPI, emotionKey string) (*Client, error) {
if emotionKey == "" {
return nil... |
//
// Copyright (c) SAS Institute Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agre... |
package raft
import "sync"
import "sync/atomic"
import "../labrpc"
import "time"
import "math/rand"
import "fmt"
import "bytes"
import "../labgob"
type ApplyMsg struct {
CommandValid bool
Command interface{}
CommandIndex int
}
type Entry struct {
Command interface{}
Term int
}
//
// A Go object implementi... |
package models
import (
"strings"
"time"
"gopkg.in/mgo.v2/bson"
"models/status"
"models/visibility"
)
type NewArticle struct {
Title string `bson:"title"`
Content string `bson:"content"`
Excerpt string
Categories []uint32 `bson:"categories"`
T... |
/*
Copyright 2021 The DbunderFS Contributors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or ... |
//go:build !darwin && !linux && (!windows || !cgo)
package ingress
import (
"context"
"fmt"
"net/netip"
"runtime"
"time"
"github.com/rs/zerolog"
"github.com/cloudflare/cloudflared/packet"
)
var errICMPProxyNotImplemented = fmt.Errorf("ICMP proxy is not implemented on %s %s", runtime.GOOS, runtime.GOARCH)
t... |
// Package bundledeployment deploys bundles, monitors them and cleans up.
package bundledeployment
import (
"context"
"errors"
"fmt"
"reflect"
"regexp"
"strings"
"sync"
"time"
"github.com/sirupsen/logrus"
"github.com/rancher/fleet/internal/cmd/agent/deployer"
"github.com/rancher/fleet/internal/cmd/agent/t... |
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package peertls
// Many cryptography standards use ASN.1 to define their data structures,
// and Distinguished Encoding Rules (DER) to serialize those structures.
// Because DER produces binary output, it can be challenging to transmit
// ... |
// Copyright 2018 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... |
package main
import (
"fmt"
"log"
"github.com/stephen-fox/radareutil"
)
func main() {
cliApi, err := radareutil.NewCliApi(&radareutil.Radare2Config{
// The executable path does not need to be fully qualified.
ExecutablePath: "radare2",
})
if err != nil {
log.Fatalf("failed to create a CLI API - %s", err.... |
package LeetCode
import (
"bytes"
"fmt"
)
func Code206() {
l1 := InitSingleList([]int{1, 2, 3, 4, 5})
fmt.Println(reverseList(l1))
}
/**
反转一个单链表。
示例:
输入: 1->2->3->4->5->NULL
输出: 5->4->3->2->1->NULL
*/
/**
* Definition for singly-linked list.
* type ListNode struct {
* Val int
* Next *ListNode
* ... |
package ThreadPool
import "fmt"
type Task struct {
taskId int
f func(id int) error
}
// NewTask Task的构造函数
func NewTask(id int, f1 func(id int) error) *Task {
return &Task{
taskId: id,
f: f1,
}
}
// 执行task
func (t *Task) execute() {
fmt.Println("taskId:", t.taskId, "is execute")
t.f(t.taskId)
}
|
package prop
import (
"fmt"
"github.com/LILILIhuahuahua/ustc_tencent_game/configs"
"testing"
)
func TestNewProps(t *testing.T) {
ids := make(map[int32]bool)
//coods := make(map[info.CoordinateXYInfo]bool)
m := New()
fmt.Println(m)
for k, v := range m.props {
fmt.Printf("index: %d, id: %d, status: %v, coords... |
package persistence
import (
"context"
"github.com/go-redis/redis/v8"
)
// NewRedisClient returns a redis client.
func NewRedisClient(url string) (*redis.Client, error) {
options, err := redis.ParseURL(url)
if err != nil {
return nil, err
}
client := redis.NewClient(options)
_, err = client.Ping(context.Bac... |
package models
type Error struct {
Message string
}
|
// Copyright 2020 Red Hat, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to i... |
package pkg
import (
"fmt"
"github.com/mrahbar/kubernetes-inspector/ssh"
"github.com/mrahbar/kubernetes-inspector/types"
"github.com/mrahbar/kubernetes-inspector/util"
"os"
"path"
"path/filepath"
"strings"
"time"
)
const (
netperfNamespace = "netperf"
orchestratorName = "netperf-orchestrator"
workerName ... |
package sequencing
type Sequence interface {
Val(int) interface{}
Len() int
}
|
// Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed t... |
package xhtml5_test
import (
. "github.com/bytesparadise/libasciidoc/testsupport"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("tables", func() {
It("1-line table with 2 cells", func() {
source := `|===
| *foo* foo | _bar_
|===`
expected := `<table class="tableblock frame-a... |
package cmd
import (
"github.com/spf13/cobra"
)
var testCmd = &cobra.Command{
Use: "test",
Short: "Test custom rules",
}
func init() {
rootCmd.AddCommand(testCmd)
}
|
/*
* Copyright 2018 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to i... |
package main
type Records struct {
Records *[]Record `json:"arrRecords"`
ReturnCode int `json:"intReturnCode,omitempty"`
Message string `json:"strMessage,omitempty"`
}
type Record struct {
Name string `json:"name,omitempty"`
RecordType string `json:"type,omitempty"`
Content string `json:... |
// Copyright 2017 The Aiicy Team.
//
// Licensed under the Apache License, Version 2.0 (the "License"): you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to... |
package main
import (
"fmt"
"io"
"net/http"
"os"
)
type logWritter struct{}
func main() {
resp, err := http.Get("https://vidhya03.labkit.in")
if err != nil {
fmt.Println("Error :", err)
os.Exit(-1)
}
if resp.Body != nil {
lw := logWritter{}
rd := textFileReader{}
wtn, err := io.Copy(lw, rd)
i... |
package common
import (
"strconv"
"time"
)
func TimeToString() string {
return strconv.FormatInt(Time(), 10)
}
func Time() (t int64) {
t = time.Now().UnixNano() / int64(time.Millisecond)
return
}
|
package main
import (
"reflect"
"testing"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/kubereboot/kured/pkg/alerts"
assert "gotest.tools/v3/assert"
papi "github.com/prometheus/client_golang/api"
)
type BlockingChecker struct {
blocking bool
}
func (fbc BlockingChecker) isBlocked() ... |
/*
Copyright 2021 The KodeRover Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, s... |
package errors
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func xx() error {
def := DefInternalError("code1", "err1")
return def.New()
}
func TestPrintDefError(t *testing.T) {
result := fmt.Sprintf("%+v\n", xx())
fmt.Println(result)
require.Contains(t, result, "c... |
package solutions
type WordTree struct {
Nodes [26]*WordTree
Word string
}
func findWords(board [][]byte, words []string) []string {
var result []string
root := buildTrie(words)
for i := 0; i < len(board); i++ {
for j := 0; j < len(board[0]); j++ {
findWord(board, root, i, j,... |
package blade
import (
"testing"
)
func Test_RadixTree(t *testing.T) {
testCases := []struct {
k string
v string
}{
{"", "empty"},
{"r", ":radix"},
{"radix", "radix"},
{"radixTree", "radixTree"},
{"radixTxn", "radixTxn"},
{"t", "test"},
{"this is a radix tree", "just a radix tree"},
{"yes, you ... |
package cmdgw
import (
"log"
apds "spca/apd/services"
gwif "spca/iif/cmdgw/if"
apdm "spca/apd/models"
// cmdh "spca/apd/cmdorchestrator"
)
// CmdGwHdl ...
var CmdGwHdl map[string]interface{}
var srvlist []string
// CmdGwInit initializes the datastructure and establishes the connection t... |
package parser_test
import (
"github.com/bytesparadise/libasciidoc/pkg/parser"
"github.com/bytesparadise/libasciidoc/pkg/types"
. "github.com/bytesparadise/libasciidoc/testsupport"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
var _ = Describe("collect footnotes", func() {
Context("in section tit... |
// Copyright © 2014-2015 Galvanized Logic Inc.
// Use is governed by a BSD-style license found in the LICENSE file.
package grid
// path is an A* implementation that works with 2D level layouts that conform
// to Plan. See:
// http://en.wikipedia.org/wiki/A*_search_algorithm
// https://www.redblobgames.com/pa... |
package virtual_services
import (
"reflect"
"strings"
"github.com/kiali/kiali/kubernetes"
"github.com/kiali/kiali/models"
)
type SingleHostChecker struct {
Namespace string
VirtualServices []kubernetes.IstioObject
}
type Host struct {
Service string
Namespace string
Cluster string
}
func (in Sin... |
package db
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
)
type EConfig struct {
UserName string `json:"userName"`
PassWord string `json:"passWord"`
Addr string `json:"addr"`
Port int `json:"port"`
DB string `json:"db"`
}
//初始化gorm
func InitOrm(cfg *EConfig) *go... |
package server
import (
"github.com/go-squads/comet-backend/domain"
"github.com/go-squads/comet-backend/repository"
"net/http"
"encoding/json"
)
func WithAuth(n http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
token := r.Header.Get("Authorization")
auth := reposit... |
package main
import (
"encoding/json"
"fmt"
"time"
"code-lib/notify/rabbitmq"
proto "subassembly/timer-controller/proto/notify"
)
func main() {
notify, err := rabbitmq.NewRabbitNotify(&rabbitmq.RabbitNotifyConf{
RabbitClientConf: &rabbitmq.RabbitClientConf{
Host: "localhost",
Port: 5672,
Use... |
package main
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
func toArray(tr *TreeNode, arr *[]int) {
if tr == nil {
return
}
toArray(tr.Left, arr)
*arr = append(*arr, tr.Val)
toArray(tr.Right, arr)
}
func findTarget(root *TreeNode, k int) bool {
arr := make([]int, 0)
... |
package types
import (
"fmt"
"math/big"
"github.com/zhaohaijun/matrixchain/vm/neovm/interfaces"
)
type Map struct {
_map map[StackItems]StackItems
}
func NewMap() *Map {
var mp Map
mp._map = make(map[StackItems]StackItems)
return &mp
}
func (this *Map) Add(key StackItems, value StackItems) {
for k := range... |
package main
// Leetcode 5786. (medium)
func maximumRemovals(s string, p string, removable []int) int {
left, right := 0, len(removable)-1
for left <= right {
mid := left + (right-left)/2
m := make(map[int]bool)
for i := 0; i <= mid; i++ {
m[removable[i]] = true
}
if existsOfMaximumRemovals(s, p, m) {
... |
package test
import (
"time"
)
// Unit 单元信息
type Unit struct {
ID int `orm:"id key auto"`
I8 int8 `orm:"i8"`
I16 int16 `orm:"i16"`
I32 int32 `orm:"i32"`
I64 uint64 `orm:"i64"`
Name string `orm:"name"`
Value float32 `orm:"value"`
F64 fl... |
package session
import (
"context"
"database/sql"
"sync"
"time"
"shared/protobuf/pb"
"shared/utility/errors"
"shared/utility/event"
"shared/utility/glog"
"shared/utility/param"
"shared/utility/servertime"
"shared/common"
"shared/utility/safe"
"shared/utility/session"
"gamesvr/manager"
"gamesvr/model"... |
package steam
import (
"net/url"
"github.com/Jleagle/valve-data-format-go/vdf"
"strconv"
)
// for now use keyvalues, eventually want to use something more
// encoding/json-like, with type assertions & all
type Depot struct {
kv vdf.KeyValue
}
func (d Depot) Name() string {
return d.kv.Key
}
func (d Depot) GetM... |
package mail
import (
"bytes"
"strconv"
"text/template"
"intra-hub/confperso"
"intra-hub/models"
"archive/zip"
"github.com/astaxie/beego"
"github.com/astaxie/beego/utils"
"io/ioutil"
"os"
"path"
"strings"
"time"
)
const (
activationURL = confperso.Protocol + "://" + confperso.Domain + "/users/activate... |
package nlputils
import (
"strings"
"golang.org/x/text/unicode/norm"
)
// ToWords will convert a string into a series of word values
func ToWords(str string) (words []string) {
var wordBuf []rune
// Normalize string before working with it
str = norm.NFC.String(str)
// Lowercase string before working with it
s... |
// Copyright 2018 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/cockroachdb/cockroach/blob/master/li... |
//Package etl the solution the etl exercism problem
package etl
import "strings"
//Transform implements takes the input map and transforms it to the correct format
func Transform(input map[int][]string) (output map[string]int) {
output = make(map[string]int)
for key, val := range input {
for _, letter := range va... |
package main
import (
"fmt"
)
import "net/http"
func main() {
fmt.Println("Hello World")
http.HandleFunc("/myroute", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("<h1>A simple web server</h1>"))
})
http.ListenAndServe(":8080", nil)
}
|
/*
Copyright 2021 The Tekton Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, softw... |
package configs
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadConfig(t *testing.T) {
cfg, err := LoadConfig("config.yaml")
assert.Equal(t, nil, err)
assert.Equal(t, "debug", cfg.Logger.Level)
assert.Equal(t, "127.0.0.1:8180", cfg.Application.Addr)
assert.Equal(t, []string{"stdou... |
package user
import (
. "github.com/jsl0820/wechat"
"testing"
)
func init() {
config := Config{
WxAppId: "wx582ef3694f7a7546",
WxAppSecret: "148ee9063222674ef03e4c21776e02cd",
}
WxConfig(config)
}
func TestCreate(t *testing.T) {
tag := new(UserTag)
id, err := tag.Create("dog122")
t.Log(id)
t.Log(er... |
// Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may not
// use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" fil... |
package main
import (
"database/sql"
"log"
"testing"
"github.com/olivere/elastic"
)
var recordCount = 10000
var searchCount = 1000
func BenchmarkInsertRandomRecordsToManticore(b *testing.B) {
var err error
var db *sql.DB
db, err = InitSphinxConnection("9306")
if err != nil {
log.Println(err)
return
}
... |
package main
import (
"fmt"
"github.com/bromaniac/advent_of_code/2021/util"
"strconv"
)
func main() {
data := input.Readln()
counter := 0
for i, j := range data {
if i == len(data)-1 {
break
}
c, _ := strconv.Atoi(j) // current
n, _ := strconv.Atoi(data[i+1]) //next
if c < n {
counter... |
package bit
import "testing"
//数字范围按位与
func rangeBitwiseAnd(m int, n int) int {
for m < n {
n &= n - 1
}
return n
}
func Test_201(t *testing.T) {
t.Log(rangeBitwiseAnd(5, 7)) // 101 111 101
t.Log(rangeBitwiseAnd(0, 1))
}
|
package service
import (
"context"
"fmt"
"testing"
"time"
)
func TestNewTCPService(t *testing.T) {
tcpService := NewTCPService(context.Background())
err := tcpService.StartListen(10000)
if err != nil {
t.Fatal(err)
}
err = tcpService.StartSend("127.0.0.1", 10000)
if err != nil {
t.Fatal(err)
}
time.S... |
package hook
import (
"github.com/utahta/momoclo-channel/validator"
)
type (
// PersistenceBeforeSaver hook
PersistenceBeforeSaver interface {
BeforeSave()
}
)
// BeforeSave hook
func BeforeSave(src interface{}) {
if p, ok := src.(PersistenceBeforeSaver); ok {
p.BeforeSave()
}
}
// Validate hook
func Vali... |
package enty
type Video struct {
ID uint64 `gorm:"primary_key;auto_increment" json:"id"`
Title string `json:"title" gorm:"type:varchar(100)"`
URL string `json:"url" gorm:"type:varchar(300);UNIQUE"`
Email string `json:"email" gorm:"type:varchar(300)"`
}
|
package main
import (
"syscall/js"
)
func main() {
registerCallbacks()
select {}
}
func registerCallbacks() {
js.Global().Set("hello", js.FuncOf(Hello))
}
func Hello(this js.Value, args []js.Value) interface{} {
return "Username"
}
|
package handlers
import (
"github.com/MetalRex101/auth-server/app/services"
"github.com/jinzhu/gorm"
)
type Handlers struct{
Oauth *Oauth
Api *Api
}
type Oauth struct {
AuthorizeClientHandler *AuthorizeClientHandler
AccessTokenHandler *AccessTokenHandler
ProfileHandler *ProfileHandler
}
type Api struct {
Ac... |
package version
var commit string
func Commit() string {
return commit
}
|
package main
import "fmt"
func main() {
s := "LVIII"
fmt.Println(romanToInt(s))
}
func romanToInt(s string) int {
m := map[string]int{}
m["I"] = 1
m["V"] = 5
m["X"] = 10
m["L"] = 50
m["C"] = 100
m["D"] = 500
m["M"] = 1000
// 从右到左遍历
sum := m[string(s[len(s)-1])]
for i := len(s) - 2; i >= 0; i-- {
// 左小右... |
package main
import (
"io/ioutil"
"net/url"
"strings"
"time"
h "github.com/xorpaul/gohelper"
yaml "gopkg.in/yaml.v2"
)
// configSettings contains the key value pairs from the config file
type configSettings struct {
Timeout time.Duration `yaml:"timeout"`
ServiceUrl ... |
package auth
import (
. "ftnox.com/common"
"ftnox.com/db"
"code.google.com/p/go.crypto/scrypt"
"database/sql"
"errors"
"bytes"
"strings"
"math"
)
var (
ERR_DUPLICATE_ADDRESS = errors.New("ERR_DUPLICATE_ADDRESS")
)
// USER
type User struct {
Id int64 `json:"id" ... |
//Copyright (C) 2020 Larry Rau. all rights reserved
package lex
import (
"fmt"
"net"
"strings"
"unicode"
)
// isEndOfLine reports whether r is an end-of-line character.
func isEndOfLine(r rune) bool {
return r == '\r' || r == '\n'
}
// isAlphaNumeric reports whether r is an alphabetic, digit, or underscore.
fun... |
package standalone
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestLoadConfig(t *testing.T) {
p := NewStandalone("./testconfig.yaml")
config, err := p.LoadConfig()
assert.True(t, len(config) == 1)
assert.Nil(t, err)
assert.NotNil(t, config)
assert.Equal(t, "eventstore", config[0].Kind)
... |
package scheduler
import (
"github.com/rebelit/gome/common"
"github.com/rebelit/gome/devices"
"log"
"strconv"
"time"
)
func GoGoScheduler() error {
log.Println("[INFO] schedule runner, starting")
for {
processSchedules := true
devs, err := devices.GetAllDevicesFromDb()
if err != nil{
log.Printf("[WAR... |
package dgoflake
import (
"testing"
"time"
)
func TestSnowflake_Increment(t *testing.T) {
var id uint64 = 577645285396840449
snowflake := ParseInt(id)
expected := id & 0xFFF
actual := snowflake.Increment()
if expected != actual {
t.Errorf("unexpected increment value for snowflake %d: expected %d, got %d", id... |
package memstorage
import (
"context"
"errors"
"github.com/SmitSheth/Mini-twitter/internal/user"
"github.com/SmitSheth/Mini-twitter/internal/user/userpb"
pb "github.com/SmitSheth/Mini-twitter/internal/user/userpb"
)
type userRepository struct {
storage *userStorage
}
// GetUserRepository returns a UserReposit... |
package server
import (
"fmt"
pb "github.com/1851616111/xchain/pkg/protos"
"github.com/golang/protobuf/proto"
"github.com/golang/protobuf/ptypes"
"time"
)
func makeKeepaliveMsg() *pb.Message {
timeStamp, _ := ptypes.TimestampProto(time.Now())
return &pb.Message{
Action: pb.Action_Request,
Type: pb... |
package main
import "fmt"
type IProject interface {
Add(name string, num, cost int)
GetProjectInfo()
Iterator() IProjectIterator
}
type IProjectIterator interface {
HasNext() bool
Next() IProject
}
///////////////////////////////////////////
type Project struct {
name string
num int
cost int
projectList [... |
package zapcloudwatch
import (
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
"go.uber.org/zap/zapcore"
)
// Interface defines CloudwatchHook interface
var _ Interface = (*CloudwatchHook)(nil)
// Interface of pgp
type Interface interface {
GetHook() (func(zapcore.Entry) error, error)
sendEvent(params *cloudw... |
package dynamicstruct
import (
"encoding/json"
"fmt"
"github.com/goldeneggg/structil"
)
func Example() {
type Hoge struct {
Key string
Value interface{}
}
hogePtr := &Hoge{
Key: "keystr",
Value: "valuestr",
}
// Add fields using Builder with AddXXX method chain
b := NewBuilder().
AddString("... |
// Copyright (c) 2018 The MATRIX Authors
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php
package blkgenorV2
import (
"github.com/MatrixAINetwork/go-matrix/consensus/blkmanage"
"github.com/MatrixAINetwork/go-matrix/ca"
"github... |
package wallet
import (
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
"log"
"github.com/FeiyangTan/golang-blockchain/util"
"golang.org/x/crypto/ripemd160"
)
const version = byte(0x00)
const addressChecksumLen = 4
// Wallet 公私钥对
type Wallet struct {
PrivateKey ecdsa.PrivateKey
PublicKey [... |
package main
import (
"fmt"
"math/big"
)
func main() {
i := big.NewInt(1)
j := big.NewInt(1)
temp := big.NewInt(0)
for c := 3; ; c++ {
temp.Add(i, j)
i.Set(j)
j.Set(temp)
if len(j.Text(10)) >= 1000 {
fmt.Println("c:", c)
break
}
}
}
|
package problem3
import (
"container/list"
"fmt"
"io/ioutil"
"math"
"strconv"
"strings"
)
type FuelSystemMatrix struct {
dim [][]int
}
type Wire struct {
xPos int
yPos int
startX int
startY int
}
func NewWire(initXpos int, initYpos int) *Wire {
w := Wire{
xPos: initXpos,
yPos: initYpos,
st... |
package command
import (
"errors"
"golang.org/x/net/context"
"github.com/xozrc/cqrs/types"
)
var (
commandFactoryMap map[string]CommandFactory
)
var (
CommandFactoryNoFound = errors.New("command factory no found")
)
func init() {
commandFactoryMap = make(map[string]CommandFactory)
}
/... |
package dockerconfig
import (
"github.com/Dynatrace/dynatrace-operator/src/logger"
)
var (
log = logger.Factory.GetLogger("docker-config")
)
|
// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
//go:build go1.18
// +build go1.18
package useragent_test
import (
"testing"
"storj.io/common/useragent"
)
func FuzzParseEntries(f *testing.F) {
f.Add([]byte(""))
f.Add([]byte("storj.io-common/v0.0.0-00010101000000-000000000000"))
... |
package weibo
type Comment struct {
ID int64 `json:"id" db:"id"`
UserID int64 `json:"user_id" db:"user_id"`
WeiboID int64 `json:"weibo_id" db:"weibo_id"`
Content string `json:"content" db:"content"`
CreatedAt int64 `json:"created_at" db:"created_at"`
}
|
package test
import (
"bytes"
"fmt"
"io/ioutil"
"net/http"
)
func post(url string, params []byte) (error, string, []byte) {
fmt.Println("URL:>", url)
req, err := http.NewRequest("POST", url, bytes.NewBuffer(params))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
client := &http.Client{}
... |
package transaction
import (
"fmt"
"testing"
)
func TestFromRaw(t *testing.T) {
tx1 := GetTestTransaction()
raw := ToRaw(tx1)
tx2 := FromRaw(raw)
if tx1 != tx2 {
fmt.Printf("Tx1: %x \n", tx1)
fmt.Printf("Tx2: %x \n", tx2)
t.Error("tx1 != tx2")
}
}
func TestFromJSON(t *testing.T) {
jsonStringA := To... |
package models
import (
db "go_cnode/database"
"gopkg.in/mgo.v2/bson"
"time"
"log"
)
//"log"
type Message struct {
Id bson.ObjectId `bson:"_id"`
Type string `json:"type"`
Master_id bson.ObjectId `json:"master_id" `
Author_id bson.ObjectId `bson:"author_id" `
Topic_id bson.ObjectId `json:... |
// Copyright 2018 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to i... |
package readwhilewrite
import (
"context"
"io"
"net/http"
"os"
)
// SendFileHTTP serves a file as a HTTP response while fw is writing to the same file.
//
// Once it gets an EOF, it waits more writes by the writer. If the ctx is done while
// waiting, SendFileHTTP returns. Typically you want to pass r.Context() a... |
package main
import "fmt"
func sqr(x *int) {
*x = *x * *x
}
func swap(x *int, y *int) {
a := *x
*x = *y
*y = a
}
func main() {
x := new(int)
*x = 5
sqr(x)
y := new(int)
*y = 10
fmt.Println(*x, *y)
swap(x, y)
fmt.Println(*x, *y)
v := 5
u := 10
fmt.Println(v, u)
swap(&u, &v)
fmt.Println(v, u)
}
|
package filepathfilter_test
import (
"os"
"path/filepath"
"sync"
"testing"
"github.com/git-lfs/git-lfs/filepathfilter"
"github.com/git-lfs/git-lfs/tools"
)
func BenchmarkFilterSimplePath(b *testing.B) {
files := benchmarkTree(b)
filter := filepathfilter.New([]string{"lfs"}, nil)
for i := 0; i < b.N; i++ {
... |
package main
type yplane struct {
Loc float64 `json:"loc"`
Reflectiveness float64 `json:"reflectiveness"`
Red float64 `json:"red"`
Green float64 `json:"green"`
Blue float64 `json:"blue"`
}
func (y *yplane) getReflectiveness() float64 {
return y.Reflectiveness
}
func (y ... |
// Code generated; DANGER ZONE FOR EDITS
package data
import (
"bytes"
"encoding/json"
"fmt"
"gopkg.in/yaml.v2"
)
const FactionDefinitionName = "faction"
type FactionDefinitions map[string]FactionDefinition
func (d FactionDefinitions) Keys() (out []string) {
for k := range d {
out = append(out, k)
}
retur... |
package zh
import (
"regexp"
"strconv"
"time"
"github.com/olebedev/when/rules"
)
/*
"上午 5点"
"上午 5 点"
"下午 3点"
"下午 3 点"
"下午 3点半"
"下午 3点30"
"下午 3:30"
"下午 3:30"
"下午 三点半"
*/
func HourMinute(s rules.Strategy) rules.Rule {
return &rules.F{
RegExp: regexp.MustCompile("(?i)" +
"(?:(凌\\s*晨|早\\s*晨|早\\s*上... |
package scene
import (
bsplib "github.com/galaco/bsp"
"github.com/galaco/bsp/lumps"
"github.com/galaco/lambda-client/internal/config"
"github.com/galaco/lambda-client/scene/visibility"
"github.com/galaco/lambda-client/scene/world"
"github.com/galaco/lambda-core/entity"
"github.com/galaco/lambda-core/lib/util"
... |
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package patchpanel interacts with the patchpanel system daemon.
package patchpanel
import (
"context"
"os"
"github.com/godbus/dbus/v5"
"github.com/golang/protobuf/pr... |
// Copyright 2019 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package security
import (
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strconv"
"strings"
"syscall"
"time"
"github.com/shirou/gopsutil/v3/process"
"c... |
package xin
import (
crand "crypto/rand"
"encoding/binary"
"math/rand"
)
func cryptoRandForm(fr *Frame, args []Value, node *astNode) (Value, InterpreterError) {
buf64 := make([]byte, 8)
_, err := crand.Read(buf64)
if err != nil {
return zeroValue, nil
}
n, readBytes := binary.Varint(buf64)
if readBytes <=... |
/*
Copyright 2014 Huawei Technologies Co., Ltd. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable la... |
package usecase
import (
"marketplace/ads/domain"
"github.com/go-pg/pg/v10"
)
type SearchAdsCmd func (db *pg.DB, user *domain.Account, keyword string) ([]domain.Ads, error)
func SearchAds() SearchAdsCmd {
return func (db *pg.DB, user *domain.Account, keyword string) ([]domain.Ads, error) {
var adsArray []domai... |
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package peer
import (
"bytes"
"container/list"
"fmt"
"math/rand"
"strings"
"sync"
"time"
"github.com/bitmark-inc/bitmarkd/block"
"github.... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.