text stringlengths 11 4.05M |
|---|
package main
import (
"fmt"
"github.com/achakravarty/30daysofgo/day6"
)
func main() {
var count int
var str string
fmt.Scanf("%d\n", &count)
for i := 0; i < count; i++ {
fmt.Scanf("%s\n", &str)
even, odd := day6.SplitIntoEvenAndOdd(str)
fmt.Printf("%s %s\n", even, odd)
}
}
|
// Package gitlab is for return a payload parsed.
package gitlab
import (
"encoding/json"
"time"
)
// Payload struct
type Payload struct {
ObjectKind string `json:"object_kind"`
Before string `json:"before"`
After string `json:"after"`
Ref string `json... |
package hi
import (
"fmt"
"strings"
"time"
)
var printLn = fmt.Println
func main() {
a, b := "hello", "world"
_, _ = a, b
printLn(strings.HasPrefix(a, "h"))
array := strings.Fields("HELLO WORLD HELLO WORLD")
printLn(strings.ToLower("HELLO WORLD"))
for _, val := range array {
printLn(val)
}
newString := ... |
package main
import (
"fmt"
"net"
"sync"
"time"
)
type connections struct {
addrs map[string]*net.UDPAddr
// lock for modifying the map
mu sync.Mutex
}
func broadcast(conn *net.UDPConn, conns *connections) {
count := 0
for {
count++
conns.mu.Lock()
// loop over known addresses
for _, retAddr := rang... |
package dpos
import (
"context"
"runtime"
"sync"
"sync/atomic"
"time"
"github.com/bluele/gcache"
chainctx "github.com/qlcchain/go-qlc/chain/context"
"github.com/qlcchain/go-qlc/common"
"github.com/qlcchain/go-qlc/common/event"
"github.com/qlcchain/go-qlc/common/types"
"github.com/qlcchain/go-qlc/config"
"... |
package main
import (
"context"
"encoding/base64"
"encoding/pem"
"fmt"
"io/ioutil"
"os"
"strconv"
"strings"
"time"
"github.com/abiosoft/ishell"
"github.com/immesys/wave/eapi"
"github.com/immesys/wave/eapi/pb"
"github.com/olekukonko/tablewriter"
)
func parseFilterFromArgs(args []string) (*filter, error) ... |
package rand
import (
"math/rand"
"time"
)
func init() {
rand.Seed(time.Now().UnixNano())
}
const letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
func GenerateString(length int) string {
s := make([]byte, length)
for i := range s {
s[i] = letters[rand.Int63n(int64(length))]
}
return strin... |
package bootstrap
import (
"github.com/xeha-gmbh/homelab/shared"
"gopkg.in/yaml.v2"
"os"
)
func ParseConfig(path string) (Config, error) {
f, err := os.Open(path)
if err != nil {
output.Fatal(shared.ErrParse.ExitCode,
"Unable to open file {{index .file}}. Cause: {{index .cause}}",
map[string]interface{}{... |
/*
Copyright © 2021 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 to in writing, software
distrib... |
package main
import (
"fmt"
"time"
)
func main() {
n := time.Now()
fmt.Println(n)
fmt.Println("day:", n.Day(), "hour:", n.Hour(), "minute:", n.Minute(), "month:", n.Month(), "year:", n.Year(), "yearday:", n.YearDay())
fmt.Println(n.Date())
}
|
package persist_lib
import (
"database/sql"
)
type SqlClientGetter func() (*sql.DB, error)
func NewSqlClientGetter(cli **sql.DB) SqlClientGetter {
return func() (*sql.DB, error) {
return *cli, nil
}
}
type Scanable interface {
Scan(dest ...interface{}) error
}
type Runable interface {
Query(string, ...interf... |
package cryptutil
import (
"encoding/base64"
"testing"
)
func TestGenerateRandomString(t *testing.T) {
t.Parallel()
tests := []struct {
name string
c int
want int
}{
{"simple", 32, 32},
{"zero", 0, 0},
{"negative", -1, 32},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
o ... |
// This file was generated for SObject CollaborationGroup, API Version v43.0 at 2018-07-30 03:48:03.521256569 -0400 EDT m=+49.865734099
package sobjects
import (
"fmt"
"strings"
)
type CollaborationGroup struct {
BaseSObject
AnnouncementId string `force:",omitempty"`
BannerPhotoUrl string `force... |
package main
import (
"fmt"
"io/ioutil"
"os"
)
// START OMIT
func Generator() <-chan int {
out := make(chan int)
go func() {
defer close(out)
for i := 0; i < 10; i++ {
out <- i
}
}()
return out
}
func LargeFileReader(fname string) <-chan []byte {
out := make(chan []byte)
go func() {
f, _ := os.O... |
package main
import (
"os"
"github.com/elielodeveloper/examplebeat/cmd"
_ "github.com/elielodeveloper/examplebeat/include"
)
func main() {
if err := cmd.RootCmd.Execute(); err != nil {
os.Exit(1)
}
}
|
/*
* @lc app=leetcode.cn id=1356 lang=golang
*
* [1356] 根据数字二进制下 1 的数目排序
*/
package main
import (
"sort"
)
// @lc code=start
func sortByBits(arr []int) []int {
sort.Slice(arr, func(i, j int) bool {
counti := 0
countj := 0
tempi, tempj := arr[i], arr[j]
valueLess := tempi < tempj
for tempi > 0 {
cou... |
package keeper
import (
"encoding/hex"
"math/rand"
"time"
"github.com/tidwall/gjson"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
servicetypes "github.com/irisnet/irismod/modules/service/types"
"github... |
package mt
// A Vec is a 3D vector in units of 0.1 nodes.
type Vec [3]float32
// Add returns v+w.
func (v Vec) Add(w Vec) Vec {
for i := range v {
v[i] += w[i]
}
return v
}
// Sub returns v-w.
func (v Vec) Sub(w Vec) Vec {
for i := range v {
v[i] -= w[i]
}
return v
}
|
package chain
import "fmt"
/**
学生请假责任链 2天的老师可以批,超过两天的校长批
*/
type Handle interface {
HaveRight(days int) bool
Exec(days int)
}
type VocateChain struct {
Handle
Next *VocateChain
}
func (v *VocateChain) SetNext(next *VocateChain) {
v.Next = next
}
func (v *VocateChain) Exec(days int) {
if v.HaveRight(days) {... |
package main
import (
"context"
"fmt"
"time"
"github.com/brigadecore/brigade/sdk/v3"
"github.com/brigadecore/brigade/sdk/v3/meta"
myk8s "github.com/brigadecore/brigade/v2/internal/kubernetes"
"github.com/pkg/errors"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachine... |
package main
import (
"sync"
"time"
"fmt"
)
func TestTicker(wg sync.WaitGroup){
calDuration:= func(duration time.Duration)time.Duration {
now:=time.Now()
return now.Truncate(duration).Add(duration).Sub(now)
}
fmt.Println(calDuration(time.Second*5))
}
func main() {
TestTicker(sync.WaitGroup{})
}
|
package models
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/postgres" // using postgres sql
)
func SetupModels() *gorm.DB {
postgresConn := fmt.Sprintf("host=%v port=%v user=%v password=%v dbname=%v sslmode=disable",
"localhost", "5432", "", "", "golang-demo")
db, err := gorm.Op... |
package planets
import "context"
type Repository interface {
Add(ctx context.Context, planet Planet) error
GetAll(ctx context.Context) ([]Planet, error)
Get(ctx context.Context, id interface{}) (Planet, error)
GetByName(ctx context.Context, name string) (Planet, error)
Remove(ctx context.Context, id interface{})... |
package basic
import "fmt"
/*
go的闭包(Closure)定义: 引用了外部变量的匿名函数
*/
/*
函数胡返回值类型可以是函数
*/
func func1() func() int {
/*
因为没有引用外部变量, 所以返回的这个匿名函数还联不是闭包
*/
return func() int {
return 10
}
}
func closer1() {
str := "hello world"
/*
func()定义了一个匿名函数
*/
foo := func() {
/*
这个匿名函数引用了外部变量, 所以这个匿名函数就成为胃闭包
... |
package menu
import (
"FileSystem-LWH/analisis/lexico"
"FileSystem-LWH/analisis/sintactico"
"FileSystem-LWH/util"
"FileSystem-LWH/util/archivo"
"fmt"
"strings"
)
// Interfaz de línea de comandos
func Interfaz() {
fmt.Println("╔══════════════════════╗")
fmt.Println("║ Bienvenido ║")
fmt.Println("╚══... |
package leetcode
import "testing"
func TestIsLongPressedName(t *testing.T) {
if isLongPressedName("alex", "aaleex") != true {
t.Fatal()
}
if isLongPressedName("saeed", "ssaaedd") != false {
t.Fatal()
}
if isLongPressedName("leelee", "lleeelee") != true {
t.Fatal()
}
if isLongPressedName("laiden", "laiden... |
package main
import (
"flag"
"fmt"
"math/rand"
"net/http"
"strconv"
"sync/atomic"
"time"
)
var num int32
var laddr string
var sleepTime int
var debugLog bool
func init() {
flag.StringVar(&laddr, "a", "0.0.0.0:12345", "server listening address")
flag.IntVar(&sleepTime, "t", 0, "simulated sleep time for each... |
// select project doc.go
/*
select document
*/
package main
|
package table
import (
"fmt"
"strings"
)
func PrintResult(schema *Schema, records []*Record) {
sizes := make([]int, len(schema.Columns()))
for i := 0; i < len(schema.Columns()); i++ {
sizes[i] = -1
s := len(string(schema.Columns()[i].Name()))
if sizes[i] < s {
sizes[i] = s
}
for j := 0; j < len... |
package helm
import (
"context"
"github.com/werf/werf/pkg/deploy/secrets_manager"
"github.com/werf/werf/pkg/deploy/helm/chart_extender"
"github.com/spf13/cobra"
cmd_werf_common "github.com/werf/werf/cmd/werf/common"
)
func SetupRenderRelatedWerfChartParams(cmd *cobra.Command, commonCmdData *cmd_werf_common.Cm... |
package postgres
import (
"os"
"testing"
)
var testdb *TestDB
func TestMain(m *testing.M) {
var exitcode int
func() { // use a func wrapper so we can rely on defer
testdb = new(TestDB)
defer testdb.Close()
if err := testdb.Init(); err != nil {
panic(err)
}
exitcode = m.Run()
}()
//
os.Exit(exi... |
package show
import (
"fmt"
"io"
"math/rand"
"net/http"
"os"
"strings"
"github.com/gin-gonic/gin"
)
/**
* @desc 单文件上传 \ 多文件上传 图片
* @author Ipencil
* @create 2019/3/15
*/
func UploadOne(c *gin.Context) {
file, err := c.FormFile("files")
if err != nil {
fmt.Println("读取文件失败")
}
right := strings.Replac... |
package ledger
import (
"bytes"
"crypto/sha256"
"math/big"
"github.com/pkg/errors"
"github.com/btcsuite/btcutil/base58"
"golang.org/x/crypto/blake2b"
)
//
// Original Source: crypto.go
// https://github.com/goat-systems/go-tezos/blob/master/internal/crypto/crypto.go
//
type Prefix []byte
//B58cencode enco... |
package main
import (
"coconut/db"
_ "github.com/jinzhu/gorm/dialects/postgres"
)
func main() {
defer db.GetDB().Close()
router := drawRoutes()
router.Run(":9876")
}
|
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := 1.0
for i := 0; math.Abs(z*z-x) > 0.000005; i++ {
fmt.Printf("Step #%v:\t%v\t%v\n", i, z, math.Abs(z*z-x))
z -= (z*z - x) / (2 * x)
}
return z
}
func main() {
fmt.Println(Sqrt(2.0))
}
|
package eval714
import "fmt"
var index = 0
func (v Var) String(env Env) {
tab := ""
for i := 0; i < index; i++ {
tab += " "
}
fmt.Printf("%s", tab)
fmt.Println(v)
}
func (l literal) String(env Env) {
tab := ""
for i := 0; i < index; i++ {
tab += " "
}
fmt.Printf("%s", tab)
fmt.Println(l)
}
func (u un... |
package distributertest
import "github.com/Kareem-Emad/redis-grid/cache"
var fakeConnectionURLs = []string{
"http://redis_test1:4000",
"http://redis_test2:4000",
"http://redis_test3:4000",
"http://redis_test4:4000",
}
var globalExecutionCount = 0
var shardExecutionStack = map[string]string{
fakeConnectionURLs[... |
package notifications
import (
"context"
"encoding/json"
"errors"
"net/http"
"github.com/go-kit/kit/log"
kithttp "github.com/go-kit/kit/transport/http"
"github.com/gorilla/mux"
)
var (
errBadRoute = errors.New("Bad route")
errBadRequest = errors.New("Bad request")
errNotFound = errors.New("Not found")
err... |
package config
import (
"os"
)
type MiddlewareSpec struct {
MiddlewareName string `mapstructure:"middlewareName"`
RefName string `mapstructure:"refName"`
MiddlewarePath string `mapstructure:"middlewarePath"`
CustomMiddleware bool `map... |
package httpcanvas
import (
"fmt"
)
type Context struct {
Width float64
Height float64
command chan string
mouse chan mouseMovement
mouseX float64
mouseY float64
mouseClickedX float64
mouseClickedY float64
mouseClicked bool
}
func newContext(w, h float64, c chan string, m chan mouseMovement) *C... |
package app
import (
"fmt"
"net/http"
"os"
"github.com/EnMasseProject/maas-service-broker/pkg/broker"
"github.com/EnMasseProject/maas-service-broker/pkg/handler"
"github.com/EnMasseProject/maas-service-broker/pkg/maas"
)
type App struct {
broker *broker.MaasBroker
args Args
config Config
log *... |
package cmd
import (
"errors"
"fmt"
"strings"
"github.com/container-tools/spectrum/pkg/builder"
"github.com/container-tools/spectrum/pkg/util"
"github.com/spf13/cobra"
)
func Spectrum() *cobra.Command {
cmd := cobra.Command{
Use: "spectrum",
Short: "Spectrum can publish simple container images in a few ... |
// Copyright 2020 Torben Schinke
//
// 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
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to... |
package drums
import (
"time"
"github.com/siggy/bbox/bbox"
)
const (
TEMPO_TICK = 15
// test
// DECAY = 2 * time.Second
// KEEP_ALIVE = 5 * time.Second
// prod
DECAY = 3 * time.Minute
KEEP_ALIVE = 14 * time.Minute
// if 50% of beats are active, yield to the next program
YIELD_LIMIT = SOUNDS *... |
package hermes
import (
"errors"
"fmt"
"net/http"
"net/url"
"runtime"
"strings"
"sync"
"time"
"github.com/PuerkitoBio/fetchbot"
"github.com/PuerkitoBio/goquery"
)
const (
DefaultUserAgent = "Hermes Bot (github.com/jtaylor32/hermes"
)
// A Runner defines the parameters for running a single instance of Her... |
package main
import "fmt"
import "time"
import . "./worker_lib"
func main() {
worker_chan := make(chan Worker, 9)
generate_workers(worker_chan, 9)
data_chan := make(chan Data)
end := make(chan bool)
go func() { generate_data(data_chan); end <- true }()
go func() { DoWork(data_chan, worker_chan); end <- true }()... |
package runner
// This file contains the implementation for the storage sub system that will
// be used by the runner to retrieve storage from cloud providers or localized storage
import (
"archive/tar"
"bufio"
"compress/bzip2"
"compress/gzip"
"context"
"crypto/tls"
"crypto/x509"
"flag"
"fmt"
"io"
"io/iout... |
package command
import (
"fmt"
"io/ioutil"
"log"
"math/rand"
"net/http"
"net/url"
"regexp"
"strconv"
"strings"
"time"
"github.com/jixwanwang/jixbot/channel"
)
const defaultCooldown = 100 * time.Millisecond
type textCommand struct {
cp *CommandPool
clearance channel.Level
comm *subCommand
com... |
package fcm
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"time"
)
const (
// Methods
GET = "GET"
POST = "POST"
// Define Urls
defaultApiFCM = "https://fcm.googleapis.com/fcm/send"
defaultApiIID = "https://iid.googleapis.com/iid/info/%s?details=true"
// Set Max time to live for mes... |
package middleware
import (
"github.com/gobuffalo/buffalo"
)
// CacheControl takes a string and makes a header value to the key Cache-Control.
// This is so you can set some sane cache defaults to certain endpoints.
func CacheControl(cacheHeaderValue string) buffalo.MiddlewareFunc {
return func(next buffalo.Handler... |
package main
import "fmt"
func main() {
channels := []chan int{
make(chan int, 1),
make(chan int, 1),
make(chan int, 1), // 最后的","不能省略
}
//channels[0] <- 1
//channels[1] <- 1
//channels[2] <- 1
select {
case <-channels[0]:
fmt.Println("0")
case <-channels[1]:
fmt.Println("1")
case <-channels[2]:
... |
package regression
import (
"context"
"crypto/md5"
"errors"
"fmt"
"math"
"sync"
"time"
"go.skia.org/infra/go/skerr"
"go.skia.org/infra/go/sklog"
"go.skia.org/infra/go/vcsinfo"
"go.skia.org/infra/go/vec32"
"go.skia.org/infra/perf/go/alerts"
"go.skia.org/infra/perf/go/cid"
"go.skia.org/infra/perf/go/clust... |
package obs
import (
"io"
"net/http"
"github.com/pkg/errors"
"go.opencensus.io/exporter/prometheus"
"go.opencensus.io/stats/view"
)
func initMonitor(cfg MonitorConfig, namespace string, writerErr io.Writer) (string, http.HandlerFunc, func(), error) {
if !cfg.Enabled {
return "", nil, nil, nil
}
prometheus... |
package main
import "fmt"
func main() {
year := 2018
fmt.Printf("Type %T for %v\n", year, year)
days := 365.2425
fmt.Printf("Type %T for %[1]v\n", days)
a := "text"
fmt.Printf("Type %T for %[1]v\n", a)
b := 42
fmt.Printf("Type %T for %[1]v\n", b)
c := 3.14
fmt.Printf("Type %T for %[1]v\n", c)
d := tr... |
package cockroachdb
import (
"context"
"database/sql"
"errors"
"github.com/go-kit/kit/log/level"
"github.com/cockroachdb/cockroach-go/crdb"
"github.com/go-kit/kit/log"
"github.com/shijuvar/gokit-examples/services/order"
)
var (
ErrRepository = errors.New("unable to handle request")
)
type repository struct... |
package main
import (
"os"
"testing"
)
func TestNewDeck(t *testing.T) {
d := newDeck()
if len(d) != 52 {
t.Errorf("Expected deck length of 52, but got %v", len(d))
}
if d[0] != "Ace of Spades" {
t.Errorf("Expected first card to be Ace of Spades, but got %v", d[0])
}
if d[len(d)-1] != "King of Diamonds" {... |
package main
import (
"encoding/base64"
"encoding/binary"
"net"
"testing"
)
// TestChainIDSerializeDeserialize tests whether the serialization and deserialization of the chainid works.
func TestChainIDSerializeDeserialize(t *testing.T) {
protocol := ProtocolUDP
ip := net.IPv4(0xC0, 0xA8, 0x2A, 0x45)
port := ui... |
package flyweight
import "testing"
func TestChessBoard(t *testing.T) {
cf := GetChessFactory()
}
|
package boilingcore
import (
"bytes"
"fmt"
"io"
"os"
"strings"
"testing"
"github.com/google/go-cmp/cmp"
)
type NopWriteCloser struct {
io.Writer
}
func (NopWriteCloser) Close() error {
return nil
}
func nopCloser(w io.Writer) io.WriteCloser {
return NopWriteCloser{w}
}
func TestWriteFile(t *testing.T) {... |
package genstruct
import (
"fmt"
"strings"
)
func (m *Module) GenDataModel() (string, string) {
fmt.Println("Generate " + title(m.Name) + " DataModel.")
dataStruct := readTemplate("datamodels/datamodels.tmpt")
dataFeild := ""
dataForm := ""
hasTime := false
hasSql := false
hasNull := false
for _, col... |
package config
import (
"github.com/emicklei/go-restful"
api "github.com/emicklei/go-restful-openapi"
"grm-labelmgr/dbcentral/etcd"
. "grm-labelmgr/types"
. "grm-service/util"
)
type ConfigSvc struct {
DynamicDB *etcd.DynamicDB
DataDir string
ConfigDir string
}
// WebService creates a new service that ca... |
package crons
import (
"log"
"time"
"github.com/constant-money/constant-event/daos"
"github.com/constant-money/constant-event/services"
"github.com/constant-money/constant-web-api/models"
)
const (
DeltaTimeInSeconds = 60
)
// WalletCron : struct
type WalletCron struct {
ud *daos.UserDAO
walletSrv *s... |
package statsd
import (
"context"
"runtime"
"sync"
"testing"
"time"
"github.com/atlassian/gostatsd/pkg/fakesocket"
"github.com/magiconair/properties/assert"
"github.com/stretchr/testify/require"
)
func BenchmarkReceive(b *testing.B) {
// Small values result in the channel aggressively blocking and causing s... |
package foundation
import (
"testing"
"github.com/stretchr/testify/assert"
)
func init() {
SetMode(TestMode)
}
var ProdModeClosure = func(f func()) {
mode := Mode()
SetMode(ProdMode)
f()
SetMode(mode)
}
var DevModeClosure = func(f func()) {
mode := Mode()
SetMode(DevMode)
f()
SetMode(mode)
}
func TestM... |
package soduko_test
import (
"github.com/yehezkel/soduko"
"testing"
)
func TestSoduko1x1(t *testing.T) {
soduko := &soduko.Soduko{
Board: []int{
0,
},
Size: &soduko.SquareSize{X: 1, Y: 1},
}
solution := []int{
1,
}
err := soduko.Solve()
if err != nil {
t.Errorf("Unexpected error condition: %v,... |
package webauthnutil
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"github.com/pomerium/pomerium/pkg/grpc/databroker"
"github.com/pomerium/webauthn"
)
type mockDataBrokerServiceClient struct {
databr... |
package pin
import (
"crypto/rand"
"math/big"
"strconv"
)
func generateRandomDigit() uint64 {
i, err := rand.Int(rand.Reader, big.NewInt(10))
if err != nil {
panic(err)
}
return i.Uint64()
}
func Generate(length int) string {
var pin string
for i := 0; i < length; i++ {
rand := generateRandomDigit()
... |
package main
import (
"fmt"
"github.com/MrWebUzb/facade/singleton_pattern/db"
)
func main() {
conn := db.GetInstance()
query := "SELECT * FROM users WHERE username='john' AND password='doe';"
if err := conn.Query(query).Exec(); err != nil {
fmt.Printf("Error when execute query: %v", err)
}
}
|
package error
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"strconv"
"gopx.io/gopx-common/log"
"gopx.io/gopx-vcs-api/pkg/controller/helper"
)
type errorResponse struct {
Message string `json:"message"`
}
func setBasicHeaders(headers http.Header) {
headers.Set("Server", "GoPx.io")
headers.Set("Access-... |
package cache
import (
"encoding/json"
"fmt"
"regexp"
"sync"
apierr "k8s.io/apimachinery/pkg/api/errors"
log "github.com/sirupsen/logrus"
apiv1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)
var... |
/*
Copyright 2021 CodeNotary, 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 law or agreed to i... |
/*
Package plugins contains all plugins that interface with the chatbot.
Each plugin must implement the Plugin interface.
Here's an example of an implementation of the Plugin interface
package sample
import (
"regexp"
"github.com/handwritingio/deckard-bot/log"
"github.com/handwritingio/deckard-bot/message"
... |
package server
import (
"net/http"
"net/http/httputil"
"net/url"
"golang.org/x/net/context"
"github.com/coreos/tectonic-installer/installer/server/ctxh"
)
var proxyWhitelist = []string{
"https://stable.release.core-os.net/amd64-usr/current/coreos_production_ami_all.json",
}
// proxy allows the client to acce... |
/*
** description("").
** copyright('open-im,www.open-im.io').
** author("fg,Gordon@tuoyun.net").
** time(2021/9/8 14:35).
*/
package main
import (
"flag"
"fmt"
"open_im_sdk/open_im_sdk"
"open_im_sdk/open_im_sdk/ws_wrapper/utils"
"open_im_sdk/open_im_sdk/ws_wrapper/ws_local_server"
"runtime"
"sync"
)
func mai... |
package mobile
import (
"github.com/golang/protobuf/proto"
"github.com/textileio/go-textile/pb"
)
// SetLogLevel calls core SetLogLevel
func (m *Mobile) SetLogLevel(level []byte) error {
mlevel := new(pb.LogLevel)
if err := proto.Unmarshal(level, mlevel); err != nil {
return err
}
return m.node.SetLogLevel(m... |
package router
import (
"encoding/json"
"fmt"
"net/http"
"github.com/strava/go.strava"
"github.com/tedsuo/rata"
)
func NewRouter(authenticator *strava.OAuthAuthenticator) (http.Handler, error) {
handlers := rata.Handlers{
"root": newIndexHandler(authenticator),
"oauth": newoAuthHandler(authenticator),
}
... |
package dht
import (
"context"
"encoding/json"
"sync"
"github.com/google/uuid"
kbucket "github.com/libp2p/go-libp2p-kbucket"
"github.com/libp2p/go-libp2p/core/peer"
)
// KeyKadID contains the Kademlia key in string and binary form.
type KeyKadID struct {
Key string
Kad kbucket.ID
}
// NewKeyKadID creates a... |
// Copyright 2017 The LUCI 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... |
package tools
import "strconv"
// ReverseString reverses a string
func ReverseString(s string) string {
var r string
for _, v := range s {
r = string(v) + r
}
return r
}
// IsPalindromeString tells if a given string is a palindrome.
func IsPalindromeString(s string) bool {
return s == ReverseString(s)
}
// I... |
package datastore
import (
"entities"
)
type Dog struct Animal
func (d Dog) Speak() {
fmt.Println("Wan wan")
}
//Eat is a test func
func (d Dog) Eat() {
fmt.Println("Chewing bone")
} |
package lintcode
/**
* solution 1: recursion
* @param A: sorted integer array A
* @param B: sorted integer array B
* @return: A new sorted integer array
*/
func mergeSortedArray(A []int, B []int) []int {
if A == nil || len(A) == 0 {
return B
}
if B == nil || len(B) == 0 {
return A
}
if len... |
package main
import "fmt"
func rotl(x, y int64) int64
func main() {
fmt.Println(rotl(2, 3))
}
|
package buildPileOfCubes_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "./"
"math/rand"
"time"
)
func dotest(n int, exp int) {
var ans = FindNb(n)
Expect(ans).To(Equal(exp))
}
func findNbZFG(m int) int {
var cubeSize int = 0
n := 0
for ; cubeSize < m; n++ {
... |
package visible
var MyName = "Ankit"
var yourName = "Shikamaru"
/*
MyName is visible
yourName is not visible
*/
/*
MyName and yourName both can be accessed anywhere inside visible package
*/
|
package main
import (
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestParseSeatID(t *testing.T) {
testString := "FBFBBFFRLR"
result := getSeatID(strings.Split(testString, ""))
require.Equal(t, 357, result)
}
|
package dsn
import "github.com/exasol/exasol-driver-go/internal/config"
func ToInternalConfig(dsnConfig *DSNConfig) *config.Config {
apiVersion := 2
if dsnConfig.AccessToken != "" || dsnConfig.RefreshToken != "" {
apiVersion = 3
}
return &config.Config{
User: dsnConfig.User,
Password: ... |
package model
type Item struct {
ID string `json:"id"`
Url string `json:"url"`
Title string `json:"title"`
LikesCount int `json:"likes_count"`
UpdatedAt string `json:"updated_at"`
}
type ItemResponse struct {
ID string `json:"id"`
Url string `json:"url"`
Title string `json:"title"`
LikesCount int `json:"li... |
package main
//在二维网格 grid 上,有 4 种类型的方格:
//
//1 表示起始方格。且只有一个起始方格。
//2 表示结束方格,且只有一个结束方格。
//0 表示我们可以走过的空方格。
//-1 表示我们无法跨越的障碍。
//返回在四个方向(上、下、左、右)上行走时,从起始方格到结束方格的不同路径的数目。
//
//每一个无障碍方格都要通过一次,但是一条路径中不能重复通过同一个方格。
//
//
//
//示例 1:
//
//输入:[[1,0,0,0],[0,0,0,0],[0,0,2,-1]]
//输出:2
//解释:我们有以下两条路径:
//1. (0,0),(0,1),(0,2),(0,3),(1,... |
package coalbox
import (
"math"
"sort"
)
func ToSentences(bbs []BoundingBox) []BoundingBox {
return ToSentencesUsingRatios(bbs, 0.25, 0.5)
}
type taggedBoundingBox struct {
BoundingBox
tag int
}
func min(a, b int) int {
if a < b {
return a
}
return b
}
func max(a, b int) int {
if a < b {
return b
}
... |
package main
import "fmt"
// type Student struct {
// Name string
// Data []data
// }
type WhereList struct {
column string
operator string
value string
}
// data1 := data{
// study: "good",
// sports: "good",
// }
// 整形処理
func test(column, operator, value string) string {
return column + " " + opera... |
package main
import (
"fmt"
)
func bubbleSort(items []int) {
var (
n = len(items)
swapped = true
)
for swapped {
swapped = false
for i := 0; i < n-1; i++ {
if items[i] > items[i+1] {
items[i+1], items[i] = items[i], items[i+1]
swapped = true
}
}
n = n - 1
}
}
func main() {
items... |
package redis
import (
"culture/cloud/base/internal/config"
"fmt"
"github.com/go-redis/redis/v7"
"github.com/goava/di"
"sync"
)
// container Redis服务容器
var container *di.Container
var mutex sync.Mutex
func init() {
if config.Config.Env != config.Release {
di.SetTracer(&di.StdTracer{})
}
var err error
cont... |
package models
type LevelModel struct {
UserID string `json:"user_id" bson:"user_id"`
FbID string `json:"fb_id" bson:"fb_id"`
Name string `json:"name"`
Time int64 `json:"time"`
HighScore int64 `json:"high_score" bson:"high_score"`
Combo int `json:"combo"`
BestCombo int `json:"best_combo" bson:"be... |
package main
import "fmt"
func maxDistToClosest(seats []int) int {
N := len(seats)
if N == 0 {
return 0
}
max, pre := 0, 0
for i := 0; i < N; i++ {
if seats[i] == 0 {
continue
}
if seats[pre] == 0 {
max = i
}
if i-pre > 2*max {
max = (i - pre) / 2
}
pre = i
}
if pre != N-1 && N-pre-1 >... |
package sort
import "fmt"
func InsertionSort() {
s := []int{23, 42, 35, 10, 34}
for i := 1; i < len(s); i++ {
data := s[i]
j := i - 1
for j >= 0 && data < s[j] {
s[j+1] = s[j]
j--
}
s[j+1] = data
}
fmt.Println(s)
}
|
package basic
import "fmt"
type Person1 struct {
name string
age int
}
/*
函数定义中的前置的结构体变量就是receiver, 函数要改变作用调用者的结构体, receiver就用指针
*/
func (this *Person1) Growth() {
this.age++
}
func (this *Person1) ChangeName(newname string) {
this.name = newname
}
func receiver1() {
p := Person1{"wangzy", 30}
p.Growth()
... |
package tests
import (
"log"
"math/rand"
"testing"
"github.com/almerlucke/kallos"
"github.com/almerlucke/kallos/generators"
)
func TestChoice(t *testing.T) {
// seed := time.Now().UTC().UnixNano()
rand.Seed(12232)
c := generators.NewRandomChoice(kallos.ToValues(60, 61, 62, 63), false, false)
index := 0
... |
package problem0020
// isValid 判断字符串是否是有效的括号组成
func isValid(s string) bool {
stack := make([]byte, len(s))
top := 0
for i, _ := range s {
c := s[i]
switch c {
case '(':
stack[top] = c + 1
top++
case '[', '{':
stack[top] = c + 2
top++
case ')', ']', '}':
if top > 0 && stack[top-1] == c {
... |
package runner
// This file contains the implementation of storage that can use an internal cache along with the MD5
// hash of the files contents to avoid downloads that are not needed.
import (
"bufio"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"sync"
"time"
"github.com/go-stack/stack"
"github.com/... |
// Copyright 2023 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... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.