text stringlengths 11 4.05M |
|---|
package main
import (
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"math/rand"
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"
mqtt "github.com/eclipse/paho.mqtt.golang"
"github.com/jakebailey/irc"
flags "github.com/jessevdk/go-flags"
"github.com/joho/godotenv"
yaml "gopkg.... |
package day3
import (
ds "aoc/datastructures"
"aoc/util"
)
type rucksack struct {
original string
}
func (r *rucksack) comp1() string {
mid := len(r.original) / 2
return r.original[:mid]
}
func (r *rucksack) comp2() string {
mid := len(r.original) / 2
return r.original[mid:]
}
func newRucksack(input string)... |
package database
import (
"FPproject/Backend/log"
"FPproject/Backend/models"
"time"
"github.com/google/uuid"
)
func (d *Database) InsertFood(f models.Food) (string, error) {
id := uuid.New().String()
res, err := d.db.Exec("INSERT INTO food(id, merchant_id, name, price, status, description, imglink, calories, c... |
package problem0215
import "testing"
func TestFindKthLargest(t *testing.T) {
t.Log(findKthLargest([]int{3, 2, 3, 1, 2, 4, 5, 5, 6}, 4))
}
|
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"testing"
log "github.com/Sirupsen/logrus"
"github.com/tzmartin/namedpiper"
)
func upload(t *testing.T) {
/* this is a comment style*/
w := client.Bucket("sai-corp-dev-session-ingest").Object("obj").NewWriter(ctx)
w.Resumable = true
_, err := w... |
package main
import (
"database/sql"
"log"
"fmt"
"github.com/yydzero/mnt/util/reflect"
_ "github.com/lib/pq"
"flag"
"sync"
)
var port int
var count int
func main() {
log.SetFlags(log.Ltime | log.Lshortfile)
flag.IntVar(&port, "p", 5432, "Default port to connect")
flag.IntVar(&count, "c", 10, "Default port... |
/*
The api package is a Go package designed to provider
tools to handle API requests. The primarily goal is to support HTTP API endpoints.
*/
package api
|
// Copyright (c) 2015 RightScale, Inc. - see LICENSE
package main
// Omega: Alt+937
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"regexp"
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/onsi/gomega/ghttp"
"github.com/rightscale/rsc/recording"
)
// Iterate thro... |
package main
import (
"fmt"
"log"
"os"
"github.com/Azure/azure-sdk-for-go/services/eventgrid/mgmt/2018-01-01/eventgrid"
"github.com/Azure/go-autorest/autorest"
"github.com/Azure/go-autorest/autorest/adal"
"github.com/Azure/go-autorest/autorest/azure"
)
var (
defaultLocation = "westeurope"
defaultActiveDire... |
package main
func shipWithinDays(weights []int, days int) int {
// 能否用weight装载力的船实现?
canShipWithin := func(weight int) bool {
// 临时累加值
sum := 0
// 趟数
count := 1
for _, w := range weights {
sum += w
if sum > weight {
sum = w
count++
if count > days {
return false
}
}
}
retu... |
// laser framework types
package types
//laser config struct
type LaserConfig struct {
Connection ConnectionInfo
}
//database connection struct
type ConnectionInfo struct {
Server string
Database string
User string
Password string
}
|
package main
import (
"context"
"database/sql"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
_ "github.com/go-sql-driver/mysql"
"gopkg.in/yaml.v3"
"git.scc.kit.edu/sdm/lsdf-checksum/scaleadpt"
)
func determineFSSubpath(filesystemName, rootDir string) (string, string, error) {
fs := scaleadpt.OpenFileSystem(... |
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"log"
"strings"
spew "github.com/davecgh/go-spew/spew"
)
type RssFeed struct {
XMLName xml.Name `xml:"rss"`
Channel RssChannel `xml:"channel"`
}
type RssChannel struct {
XMLName xml.Name `xml:"channel"`
Language string `... |
package main
import (
"fmt"
csv_conv "github.com/garupanojisan/csv-conv"
"log"
"os"
)
func main() {
f, err := os.Open("./example.csv")
if err != nil {
log.Fatal(err)
}
defer f.Close()
conv, err := csv_conv.NewConverter(f)
if err != nil {
log.Fatal(err)
}
// change column names
changed, err := conv.... |
// Exercise 10_distributed guides you through using the replay in a distributed system where
// creating runs, workflow consumers and activity consumers and event consumers are being
// processed/called from different processes. Each process directly communicates with the
// replay client (in this case the replay DBCli... |
package handlers
import (
. "github.com/paulbellamy/mango"
"github.com/sunfmin/mangotemplate"
"html/template"
)
type provider struct {
}
type Header struct {
}
func (p *provider) LayoutData(env Env) interface{} {
return &Header{}
}
func LayoutAndRenderer() (l Middleware, r Middleware) {
tpl, err := template.P... |
package p10
func numPairsDivisibleBy60(time []int) int {
if time == nil || len(time) == 0 {
return 0
}
h := map[int]int{}
t := 0
for i := 0; i < len(time); i++ {
time[i] = time[i] % 60
if time[i] == 0 {
if v, ok := h[time[i]]; ok {
t += v
}
} else {
if v, ok := h[60-time[i]]; ok {
t += v
... |
package main
import "fmt"
func main() {
DateCalculator()
firstDate, secondDate := inputDates()
message, _ := calculateDifference(firstDate, secondDate)
fmt.Println(display(message))
}
|
package usecase
import (
"fmt"
"net/http"
"regexp"
"strconv"
"strings"
"time"
entity "silverfish/silverfish/entity"
"github.com/PuerkitoBio/goquery"
"github.com/go-rod/rod"
"github.com/sirupsen/logrus"
)
// FetcherHappymh export
type FetcherHappymh struct {
Fetcher
}
// NewFetcherHappymh export
func New... |
package main
import (
"fmt"
"log"
"os/exec"
"strings"
"time"
"github.com/shanghuiyang/rpi-devices/iot"
)
const (
cpuInterval = 5 * time.Minute
)
func main() {
onenetCfg := &iot.OneNetConfig{
Token: iot.OneNetToken,
API: iot.OneNetAPI,
}
cloud := iot.NewCloud(onenetCfg)
if cloud == nil {
log.Print... |
package bitmap
import "testing"
func TestBitMap(t *testing.T) {
bitmap := NewBitMap(2 << 32)
bitmap.set(1023)
t.Log(bitmap.get(111024))
t.Log(bitmap.get(1023))
}
|
// Copyright 2020 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
// package coreutil provides functions to describe interface of the core contract
// in a compact way
package coreutil
import (
"fmt"
"github.com/iotaledger/wasp/packages/coretypes"
"github.com/iotaledger/wasp/packages/hashing"
"github.com/iot... |
package ipfs
import (
"context"
"fmt"
"time"
"github.com/ipfs/go-ipfs/core"
"github.com/ipfs/go-ipfs/core/coreapi"
iface "github.com/ipfs/interface-go-ipfs-core"
"github.com/ipfs/interface-go-ipfs-core/options"
nsopts "github.com/ipfs/interface-go-ipfs-core/options/namesys"
path "github.com/ipfs/interface-go... |
/*
Package dev ...
L298N is an motor driver
which can be used to control the direction and speed of DC motors.
Spec:
_________________________________________
| |
| |
OUT1 -| L298N ... |
package hpke
import (
"context"
)
type stubFetcher struct {
key *PublicKey
}
func (f stubFetcher) FetchPublicKey(_ context.Context) (*PublicKey, error) {
return f.key, nil
}
// NewStubKeyFetcher returns a new KeyFetcher which returns a fixed key.
func NewStubKeyFetcher(key *PublicKey) KeyFetcher {
return stubFe... |
/*
Copyright 2015 Crunchy Data Solutions, 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
import (
"fmt"
"os"
"os/signal"
"bazil.org/fuse"
"bazil.org/fuse/fs"
"main/passFS"
)
func main() {
sourceDir := os.Args[1]
mountDir := os.Args[2]
err := mount(sourceDir, mountDir)
if err != nil {
fmt.Println(err)
}
}
func mount(sourceDir, mountDir string) error {
c, err := fuse.Mount(mo... |
// Copyright 2020 The Operator-SDK 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 ... |
// Copyright 2019 The OpenSDS 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 agre... |
package main
import (
"log"
"github.com/langzhenjun/xiuhu/utils"
)
// const adminAddress = "0xf4cf445afe8945f76dea4cbcb80e82d18a4940ed"
// const adminKey = `{"address":"f4cf445afe8945f76dea4cbcb80e82d18a4940ed","crypto":{"cipher":"aes-128-ctr","ciphertext":"5ea7cc5184f29e108b9d8c59656479f5dd9430e372930e43795d6786d... |
package bootiso
import (
"context"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"hash"
"io"
"io/ioutil"
"log"
"os"
"os/exec"
"path"
"runtime/debug"
"strings"
"github.com/u-root/u-root/pkg/boot"
"github.com/u-root/u-root/pkg/boot/grub"
"github.com/u-root/u-root/pkg/boot/k... |
package main
import (
"fmt"
)
//Constants can only be declared outside the function
const Pi = 3.14
func main() {
//Type interface
i := 42 // int
f := 3.142 // float64
g := 0.867 + 0.5i // complex128
//Type Conversions
a := 42
b := float64(a)
c := uint(b)
fmt.Println("Value of Pi =", P... |
package main
import (
"fmt"
"github.com/garyburd/redigo/redis"
"log"
"math/rand"
"strconv"
"time"
)
/*
场景:排行榜应用,取TOP N操作
使用:Redis Sorted Set, 有序集合
最新N个数据是以某个条件为权重,比如按点赞的次数排序,这时候就需要sorted set
将你要排序的值设置成sorted set的score,将具体的数据设置成相应的value,每次只需要执行一条ZADD命令即可
重点:
1. 如何设计score值
*/
var pool *redis.Pool
func ini... |
package testproxy
import (
"crypto/tls"
"fmt"
"io"
"net"
)
type T struct {
FromAddr string
ToAddr string
Ln net.Listener
lastID uint
conns map[uint]net.Conn
closed bool
TLSConfig *tls.Config
}
func (p *T) GetNextID() uint {
if p.lastID >= ^uint(0) {
p.lastID = 0
}
p.lastID++
ret... |
package entity
import (
"time"
)
type UmsMember struct {
Id int64 `json:"id" xorm:"pk autoincr BIGINT(20) 'id'"`
MemberLevelId int64 `json:"member_level_id" xorm:"default NULL BIGINT(20) 'member_level_id'"`
Username string `json:"username" xorm:"default 'NULL' co... |
package core
import (
"context"
konsen "github.com/lizhaoliu/konsen/v2/proto_gen"
)
// RaftService defines methods exposed by a Raft service.
type RaftService interface {
// AppendEntries sends AppendEntries request to the remote server.
AppendEntries(ctx context.Context, in *konsen.AppendEntriesReq) (*konsen.Ap... |
package geebolt
import (
"fmt"
"reflect"
"unsafe"
)
const pageHeaderSize = unsafe.Sizeof(page{})
const branchPageElementSize = unsafe.Sizeof(branchPageElement{})
const leafPageElementSize = unsafe.Sizeof(leafPageElement{})
const maxKeysPerPage = 1024
const (
branchPageFlag uint16 = iota
leafPageFlag
metaPageFl... |
// Copyright (C) 2019 Cisco Systems 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 agr... |
package rawrecording
import (
"compress/gzip"
"encoding/binary"
"fmt"
"io"
"io/ioutil"
"sort"
)
type Reader struct {
currentPack *FramePack
currentFrameNdx int // index in currentPack
currentPackNdx int
packs *io.SectionReader
indexTimeOffsets []float64
indexFileOffsets []int64
Meta Met... |
package main
import "testing"
func TestSubjectAndMessage(t *testing.T) {
testCases := []struct {
name string
s string
wantSubject, wantMessage string
}{
{
"oneline",
"just one line",
"", "just one line",
},
{
"twoline",
"line1\nline2",
"", "li... |
package doublylinkedlist
import (
"fmt"
)
// Node doubly linked list node
type Node struct {
value interface{}
prev *Node
next *Node
}
// NewNode create new node with value, prev and next link
func NewNode(value interface{}, prev *Node, next *Node) *Node {
return &Node{value: value, prev: prev, next: next}
}
... |
package strings
import (
"strings"
"unicode"
)
// 1.1
// Implement an algorithm to determine if a string has all unique characters.
func allCharsUnique(str string) bool {
seen := make(map[rune]bool)
for _, c := range str {
if seen[c] {
return false
} else {
seen[c] = true
}
}
return true
}
// 1.1.b... |
package item
import "github.com/gofiber/fiber/v2"
type IHandler interface {
Create(c *fiber.Ctx) error
FindAllByOrderID(c *fiber.Ctx) error
}
type iHandler struct {
service IService
}
func NewIHandler(s IService) IHandler {
return &iHandler{s}
}
func (h *iHandler) Create(c *fiber.Ctx) error {
return c.JSON("Cr... |
package main
import "strconv"
func isPalindrome(x int) bool {
if x < 0 {
return false
}
str := strconv.Itoa(x)
i, j := 0, len(str)-1
for i < j {
if str[i] == str[j] {
i++
j--
continue
}
return false
}
return true
}
|
package amqp
import (
"context"
"github.com/Azure/go-amqp"
)
// Session is an interface for the subset of go-amqp *Session functions that we
// actually use, adapted slightly to also interact with our own custom Sender
// interface. Using these interfaces in our messaging abstraction, instead of
// using the go-am... |
package main
import (
"fmt"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/stretchr/gomniauth"
"github.com/stretchr/gomniauth/providers/google"
"github.com/stretchr/objx"
"net/http"
"os"
)
func main(){
_ = godotenv.Load()
gomniauth.SetSecurit... |
// SPDX-License-Identifier: Apache-2.0
// Copyright © 2020 Intel Corporation
package af
import (
"context"
"net/http"
)
func deletePfdAppTransaction(cliCtx context.Context, afCtx *Context,
pfdID string, appID string) (*http.Response, error) {
cliCfg := NewConfiguration(afCtx)
cli := NewClient(cliCfg)
resp, e... |
package main
func main() {
stringChan := make(chan<- string, 3)
intChan := make(<-chan int, 3)
stringChan <- "hello world"
<- intChan
// <- stringChan
// intChan <- 2
} |
package discovery
import (
"reflect"
"testing"
querypb "github.com/youtube/vitess/go/vt/proto/query"
"github.com/youtube/vitess/go/vt/topo"
)
func TestFilterByReplicationLag(t *testing.T) {
// 0 tablet
got := FilterByReplicationLag([]*TabletStats{})
if len(got) != 0 {
t.Errorf("FilterByReplicationLag([]) = ... |
package main
import (
"house365.com/studyGo/06day/mylogger"
"time"
)
/**需求
* 支持往不同的地方输出日志
* 日志分级别
* 1.debug
2.info
3.warning
4.error
5.fatal
日志要支持开关控制
日志要有时间,行号,文件名,日志级别,日志信息
日志文件要切割
*/
func main() {
//log :=mylogger.NewLog("debug")
log := mylogger.NewFileLogger("debug", "./"... |
package main
import (
"regexp"
"strconv"
)
type MetaData struct {
Title string
Author string
PubYear int
}
func GetMetaData(filename string) MetaData {
metaData := MetaData{}
re, err := regexp.Compile(`(.+) - (.+) \((\d{4})\)`)
if err == nil {
result := re.FindStringSubmatch(filename)
if len(result) ... |
package cmd
import (
"context"
"encoding/hex"
"fmt"
"os"
"regexp"
"sort"
"strings"
"sync"
"golang.org/x/sync/errgroup"
humanize "github.com/dustin/go-humanize"
"github.com/grrtrr/clcv2"
"github.com/olekukonko/tablewriter"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
// Flags
var showFlags struct... |
package connrt
import (
"errors"
"github.com/golang/mock/gomock"
"github.com/gookit/event"
"github.com/kbence/conndetect/internal/connlib"
"github.com/kbence/conndetect/internal/connlib_mock"
"github.com/kbence/conndetect/internal/ext_mock"
. "gopkg.in/check.v1"
)
var _ = Suite(&ConnectionReaderTestSuite{})
... |
package main
import (
inet "cm_liveme_im/libs/net"
"cm_liveme_im/libs/proto"
"net"
"net/rpc"
pb "github.com/golang/protobuf/proto"
log "github.com/thinkboy/log4go"
)
func InitRPC(auther Auther) (err error) {
var (
network, addr string
c = &RPC{auther: auther}
)
rpc.Register(c)
for i := 0; ... |
package handler
const (
group = 1
single =2
) |
package db
import (
"database/sql"
"sync"
"github.com/textileio/go-textile/pb"
"github.com/textileio/go-textile/repo"
)
type ThreadPeerDB struct {
modelStore
}
func NewThreadPeerStore(db *sql.DB, lock *sync.Mutex) repo.ThreadPeerStore {
return &ThreadPeerDB{modelStore{db, lock}}
}
func (c *ThreadPeerDB) Add(... |
package config
type DatabaseConfig struct {
User string `json:"user"`
Password string `json:"password"`
Host string `json:"host"`
Port string `json:"port"`
DbName string `json:"db_name"`
Charset string `json:"charset"`
}
var C = &DatabaseConfig{} |
package main
import "fmt"
type Builder interface {
BuildFoundation() string
BuildLevels() string
}
type FlatBuilder struct{}
type HouseBuilder struct{}
func (builder FlatBuilder) BuildFoundation() string {
return "small"
}
func (builder FlatBuilder) BuildLevels() string {
return "many"
}
f... |
// Copyright (c) 2019 bketelsen
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
package lxd
import "time"
type ConnectionCreated struct {
conn *Client
StartTime time.Time
}
func (e ConnectionCreated) Name() string {
return e.conn.URL
}
func (e ConnectionCreated)... |
package main
import (
_ "ml"
"ml/console"
. "fmt"
"goqml"
// _ "./resource"
)
func run() error {
engine := qml.NewEngine()
component, err := engine.LoadFile(`D:\Dev\Library\Qt\Examples\Qt-5.5\quick\demos\stocqt\stocqt.qml`)
if err != nil {
return err
}
... |
package other
import "fmt"
/**
@desc
KMP 字符串匹配算法
*/
/**
计算字符串 s 对应的前缀表
计算规则:
例: ababc
分解: a -> 前后无一致的为 0
a b -> 前后无一致的为 0
a b a -> 第一位和最后一位一致为 1
a b a b -> 前两位和最后两位一致为 2
a b a b c -> 前后无一致的为 0
答案:[0, 0, 1, 2, 0] 为了方便进行 KMP 计算,将数组往右移一位,最左位赋值为 -1 即变成 [-1, 0, 0, 1, 2]
提示:可以使用动态规划
... |
package solcast
import (
solcast "github.com/Siliconrob/solcast-go/solcast"
datatypes "github.com/Siliconrob/solcast-go/solcast/types"
"github.com/jimlawless/whereami"
"github.com/stretchr/testify/assert"
"log"
"testing"
"math"
)
var radiationLocation = datatypes.LatLng{Longitude: -97, Latitude: 32}
var powerL... |
package eventsourcing
import (
"fmt"
"log"
"reflect"
"strings"
"github.com/alexandervantrijffel/gonats/eventsourcing/contracts"
proto "github.com/golang/protobuf/proto"
)
type AggregateCommon interface {
ID() string
HandleStateChange(interface{})
}
type AggregateCommonImpl struct {
IdImpl string
Repos... |
package blocks
import (
"bytes"
"crypto/sha256"
"cryptom/internal"
"fmt"
"math"
"math/big"
)
const (
targetBits = 16 // arbitrary number, 24 will work for staging or prod (bigger is more difficult)
maxBits = 256
maxNonce = math.MaxInt64
)
type ProofOfWork struct {
Block *Block
target *big.Int
}
fun... |
package conversion
import (
"fmt"
"testing"
)
func TestIdUtils(t *testing.T) {
c := Color16BitToRGBA("#FF708AF0")
fmt.Println(c.R, c.G, c.B, c.A)
b := RGBAToColor16Bit(c)
fmt.Println(b)
}
|
package types
//
// Pagination is used when responding with
// a paginated list
//
type Pagination struct {
Next string `json:"next"`
Previous string `json:"previous"`
}
//
// PaginatedResponse is used when responding with
// a paginated list
//
type PaginatedResponse struct {
Data interface{} `json:"dat... |
package main
import "fmt"
func generateParenthesis(n int) []string {
res := []string{}
genParenthesis("", n, n, &res)
return res
}
//left right分别表示还可放置的左右括号的剩余数
func genParenthesis(item string, left int, right int, res *[]string) {
if left == 0 && right == 0 { //左右括号都放完
*res = append(*res, item)
return
}
/... |
/*
Copyright 2020 Humio https://humio.com
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, ... |
package command
import (
"flag"
)
type ServiceArgs struct {
ConfigFile string
}
func ParseArgs() ServiceArgs {
serviceArgs := ServiceArgs{}
flag.StringVar(&serviceArgs.ConfigFile, "c", "", "Path to service config file.")
flag.Parse()
return serviceArgs
}
|
package main
import (
"log"
"time"
"github.com/Shopify/sarama"
)
var localKafka = []string{"127.0.0.1:9093"}
func main() {
consume()
}
func consume() {
consumer, err := sarama.NewConsumer(localKafka, nil)
if err != nil {
log.Fatalf("error \n")
}
partitionList, err := consumer.Partitions("my-topic")
if e... |
package day3
import (
"aoc-2020/internal/utils"
"fmt"
"strings"
)
func Solution() {
lines := utils.ReadInput("internal/day3/input3")
var travelMap [][]string
for _, line := range lines {
travelMap = append(travelMap, strings.Split(line, ""))
}
fmt.Println(":: Part1 ::")
fmt.Printf("The sled will encount... |
package db
import (
"time"
"github.com/VolticFroogo/Animal-Pictures/helpers"
"github.com/VolticFroogo/Animal-Pictures/models"
)
// StoreRefreshToken generates, stores and then returns a JTI.
func StoreRefreshToken(uuid string) (jti models.JTI, err error) {
// No need to duplication check as the JTI's don't need ... |
/*
* Copyright (c) 2019 SUSE LLC.
*
* 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 smarttv
import (
"errors"
"github.com/Jeffail/gabs"
"os"
"strconv"
)
// TODO: Split Sequence Builder and Sequence into to types
type SequenceBuilder struct {
connector ConnectorDTO
sequence map[string]*gabs.Container
commands []TVCommand
}
type SequenceBuilderInterface interface {
Init()
Build()
... |
package converter
import (
"github.com/geoirb/rss-aggregator/pkg/models"
)
// Converter ...
type Converter struct {
}
// News convert news to slice of []string
func (c *Converter) News(src []models.News) (dst [][]string) {
dst = make([][]string, 0, len(src))
for _, news := range src {
data := make([]string, 2)
... |
package main
import (
"context"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"io"
"time"
"github.com/labstack/gommon/log"
"github.com/wexel-nath/grpc-go-course/greet/greetpb"
"google.golang.org/grpc"
)
func main() {
fmt.Println("Hello I'am a client")
cc, err := grpc.Dial("localhos... |
package main
const usage = `Usage: steg <command> [<args>]
-help
Print this help message.
Commands:
hide:
-f value
Path to file to hide (can specify flag multiple times.)
-input string
Path to file to hide files in.
-output string
Output path to new file, which cont... |
package observer
// Publisher interface
type Publisher interface {
Attach(observer Observer)
Unpin(observer Observer)
Notify()
Show()
}
|
package pc
import (
"errors"
"reflect"
"strconv"
"strings"
"unicode"
)
type State struct {
Value interface{}
Remains string
Err error
}
// FIXME: input is state???
type Parser func(state State) State
var (
ErrNoMatch = errors.New("no match")
ErrUnexpectedEnd = errors.New("unexpected end of lin... |
/*
# -*- coding: utf-8 -*-
# @Author : joker
# @Time : 2021/6/30 9:18 上午
# @File : jz_11_二进制中1的个数_test.go.go
# @Description :
# @Attention :
*/
package offer
import (
"fmt"
"testing"
)
func TestNumberOf1(t *testing.T) {
fmt.Println(NumberOf1(-1))
}
|
package util
import (
"fmt"
"math/rand"
"net/http"
"reflect"
"regexp"
"strings"
"grm-service/common"
"github.com/emicklei/go-restful"
"github.com/pborman/uuid"
errors "grm-service/errors"
log "grm-service/log"
)
type nullRet struct {
ret string `json:"ret,omitempty"`
}
func isNil(i interface{}) bool {... |
package policy
import (
"strings"
"github.com/rightscale/rsc/cmd"
"github.com/rightscale/rsc/rsapi"
)
// API 1.0 client
// Just a vanilla RightScale API client.
type API struct {
*rsapi.API
}
// New returns a API 1.0 client.
// It makes a test request to API 1.0 and returns an error if authentication fails.
// ... |
package main
import (
"fmt"
"os"
"sync"
"github.com/qiniu/api.v7/auth/qbox"
"github.com/qiniu/api.v7/storage"
"github.com/qiniu/x/rpc.v7"
)
var (
AK string
SK string
)
func init() {
AK = os.Getenv("Q_AK")
SK = os.Getenv("Q_SK")
}
func main() {
if AK == "" || SK =... |
// Copyright 2016 Google Inc. 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... |
/*
Copyright 2021. The KubeVela 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 writ... |
package contracts
import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"encoding/asn1"
"encoding/hex"
"fmt"
"math/big"
"reflect"
"testing"
"github.com/SIGBlockchain/project_aurum/internal/hashing"
"github.com/SIGBlockchain/project_aurum/internal/publickey"
)
func TestNew(t *testing.T) {
sende... |
package jobconfig
import (
"testing"
"k8s.io/apimachinery/pkg/api/equality"
"k8s.io/apimachinery/pkg/util/diff"
"k8s.io/apimachinery/pkg/util/sets"
prowconfig "k8s.io/test-infra/prow/config"
)
func TestMergeConfigs(t *testing.T) {
var testCases = []struct {
name string
dest *prowconfig.JobConfig
... |
// Copyright 2021 Google LLC. 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 applica... |
package fuzz
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"time"
)
// Instrument builds the instrumented binary and fuzz.zip if they do not already
// exist in the fzgo cache. If instead there is a cache hit, Instrument prints to stderr
// that the cached is being used.
// cacheDir is the location fo... |
package accounting
import (
"log"
"tddbudget/repository"
"testing"
"time"
"bou.ke/monkey"
"github.com/stretchr/testify/suite"
)
// AccountingSuite 計算測試組
type AccountingSuite struct {
suite.Suite
*Accounting
}
func TestSuiteInit(t *testing.T) {
suite.Run(t, new(AccountingSuite))
}
func (at *AccountingSuite... |
package ability
import (
"context"
"time"
"github.com/milobella/oratio/internal/config"
"github.com/milobella/oratio/internal/model"
"github.com/sirupsen/logrus"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
type DAO interface {
CreateOr... |
package main
import (
"bufio"
"fmt"
"os"
"sort"
)
const (
UP = iota
RIGHT = iota
DOWN = iota
LEFT = iota
STRAIGHT = iota
)
type Cart struct {
x, y int
dir int
nextTurn int
}
func (c Cart) String() string {
return fmt.Sprintf("%s@%d,%d", dirName(c.dir), c.x, c.y)
}
func (c *Ca... |
package ui
import (
"fmt"
"html/template"
"io/ioutil"
"net/http"
"time"
"github.com/dpordomingo/learning-exercises/ant/actors"
"github.com/dpordomingo/learning-exercises/ant/generators"
"github.com/dpordomingo/learning-exercises/ant/geo"
)
//RunServer starts a server that will report the world state
func Run... |
package main
import (
"encoding/json"
"io/ioutil"
"github.com/brigadecore/brigade/sdk/v3"
"github.com/pkg/errors"
)
// event is a git-initializer-specific representation of a Brigade Event.
type event struct {
Project struct {
Secrets map[string]string `json:"secrets"`
} `json:"project"`
Worker struct {
G... |
package router
import (
"project/app/admin/apis"
"github.com/gin-gonic/gin"
)
func init() {
routerNoCheckRole = append(routerNoCheckRole, getCaptchaRouter)
}
// 无需认证的路由代码
func getCaptchaRouter(v1 *gin.RouterGroup) {
r := v1.Group("/auth")
{
r.GET("code", apis.Captcha)
}
}
|
// Test that return values are processed
// Package pkg does something.
package pkg
import "errors"
type megaErr struct {
error
}
func (i megaErr) Error() string {
return "I am THE error"
}
func returnOne() int {
return 0
}
func returnTwo() (int, string) {
return 0, "something"
}
func returnErrOne() error {
... |
package test
import (
"github.com/anihouse/bot/app"
"github.com/sirupsen/logrus"
)
type module struct {
app *app.Module
enabled bool
}
func (module) ID() string {
return "test"
}
func (m module) IsEnabled() bool {
return m.enabled
}
func (module) LoadConfig(path string) error {
return nil
}
func (modul... |
package evo
import (
"sort"
)
type fitnessFunc func([]rune) float64
type newGenomeFunc func() []rune
type crossoverFunc func([]rune, []rune) []rune
type mutateFunc func([]rune) []rune
type GA struct {
popSize int
fitness fitnessFunc
newGenome newGenomeFunc
crossover crossoverFunc
mutate mutateFunc
eli... |
package fakeip
import (
"net"
"testing"
)
func TestPool_Basic(t *testing.T) {
_, ipnet, _ := net.ParseCIDR("192.168.0.1/30")
pool, _ := New(ipnet)
first := pool.Get()
last := pool.Get()
if !first.Equal(net.IP{192, 168, 0, 1}) {
t.Error("should get right first ip, instead of", first.String())
}
if !last.... |
// DRUNKWATER TEMPLATE(add description and prototypes)
// Question Title and Description on leetcode.com
// Function Declaration and Function Prototypes on leetcode.com
//728. Self Dividing Numbers
//A self-dividing number is a number that is divisible by every digit it contains.
//For example, 128 is a self-dividing n... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.