text stringlengths 11 4.05M |
|---|
package input
import (
"github.com/golangee/dom"
. "github.com/golangee/gotrino"
. "github.com/golangee/gotrino-html"
"github.com/golangee/property"
)
// TextField provides a material design style for text fields and related html5 variants. However, note
// that a native date picker is not available at least in S... |
/*
package messaging encapsulates sms messaging backend.
Twilio for SMS. Gmail for email.
*/
package messaging
type Messenger interface {
SendMessage(from, to, message string) error
// SendMessage(from, to, message string) (resp, error) What would (should) response be?
SetAuth(id, key string)
}
|
package main
import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
_ "github.com/go-sql-driver/mysql"
"github.com/julienschmidt/httprouter"
taxdb "github.com/syariatifaris/shopeetax/app/db/tax"
"github.com/syariatifaris/shopeetax/app/infra/config"
"github.com/syariatifaris/shopeetax/app/infra/db"
"github.co... |
// Copyright (c) 2019 Chair of Applied Cryptography, Technische Universität
// Darmstadt, Germany. All rights reserved. This file is part of go-perun. Use
// of this source code is governed by a MIT-style license that can be found in
// the LICENSE file.
package channel // import "perun.network/go-perun/channel"
impo... |
package nodes
import (
"fmt"
"reflect"
"github.com/ofavre/calcgraph/executor"
)
type TypeMismatchError struct {
expectedType reflect.Type
actualType reflect.Type
}
func typeMismatchErrorForTypeOf(expectedType reflect.Type, val interface{}) {
typeMismatchError(expectedType, reflect.TypeOf(val))
}
func typeM... |
package manifests
import (
"path/filepath"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
apicfgv1 "github.com/openshift/api/config/v1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
)
var imageDigestMirrorSetFilen... |
/*
Copyright (C) 2018 Intel Corporation.
SPDX-License-Identifier: Apache-2.0
*/
package oimcontroller_test
import (
"context"
"errors"
"fmt"
"os"
"time"
"google.golang.org/grpc/credentials"
"github.com/intel/oim/pkg/log"
"github.com/intel/oim/pkg/log/level"
"github.com/intel/oim/pkg/oim-common"
"github.c... |
package 获取
// ----------------------- 方法1: 求取最长直径 和 求取高度 分离 -----------------------
// 缺点: 存在重复求取相同节点高度的操作。
// 优点: 逻辑清晰。
func diameterOfBinaryTree(root *TreeNode) int {
return getMaxDiameter(root)
}
func getMaxDiameter(root *TreeNode) int {
if root == nil {
return 0
}
return max(
getHeight(root.Left)+getHeigh... |
package server
import (
"net/http"
"github.com/rs/zerolog"
)
type Healthcheck struct {
Base
}
func NewHealthcheck(log zerolog.Logger) Healthcheck {
return Healthcheck{Base: NewBase(log)}
}
func (h Healthcheck) GetHealthcheck(w http.ResponseWriter, r *http.Request) {
// h.ok(w)
w.WriteHeader(http.StatusOK)
}
|
package databases
import (
"fmt"
"github.com/jinzhu/gorm"
"../common"
"./models"
_ "github.com/lib/pq"
log "github.com/sirupsen/logrus"
)
// PostgresDB manages Postgres connection
type PostgresDB struct {
Connection *gorm.DB
Databasename string
}
func (pg *PostgresDB) Connect() {
pg.Databasename = commo... |
// Package vk implements a VK adapter for the joe bot library.
package vk
import (
"context"
"strconv"
"github.com/SevereCloud/vksdk/api"
"github.com/SevereCloud/vksdk/longpoll-bot"
"github.com/SevereCloud/vksdk/object"
"github.com/go-joe/joe"
"github.com/pkg/errors"
"go.uber.org/zap"
)
// BotAdapter impleme... |
package main
import "fmt"
import "github.com/golang-collections/go-datastructures/bitarray"
func main() {
fmt.Println("is palindrome permutation")
fmt.Println(tester("tacocat", true))
fmt.Println(tester("abcab", true))
fmt.Println(tester("abz", false))
}
func solution(input string) bool {
bitVector := bitarray.... |
// 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 wav
import (
"encoding/binary"
"encoding/hex"
"fmt"
"io"
"time"
"github.com/faiface/beep"
"github.com/pkg/errors"
)
// Decode takes a Reader containing audio data in WAVE format and returns a StreamSeekCloser,
// which streams that audio. The Seek method will panic if rc is not io.Seeker.
//
// Do not... |
package log
import (
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func init() {
lvl, err := logrus.ParseLevel(viper.GetString("log.level"))
if err == nil {
logrus.SetLevel(lvl)
}
}
|
package manifests
import (
"path/filepath"
"github.com/pkg/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/yaml"
operatorv1alpha1 "github.com/openshift/api/operator/v1alpha1"
"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/installconfig"
)
var imageCont... |
package model
import "time"
//User - a struct to rep User account
type User struct {
BaseModel
Lang string `json:"lang" gorm:"not null;type:varchar(5);default:'en'"`
FirstName string `json:"first_name" gorm:"not null;type:varchar(50);"`
LastName string `json:"last_name" gorm:"not ... |
package levenshtein
import "fmt"
// OutMatrix prints matrix to stdout
func OutMatrix(mtr [][]int) {
fmt.Println("Result matrix:")
for i := range mtr {
for j := range mtr[i] {
fmt.Printf("%3d ", mtr[i][j])
}
fmt.Printf("\n")
}
}
// createMatrix is used to create and fill matrix for levenstein
func createM... |
package spotify
import (
"fmt"
"net/http"
)
var NoMorePagesError = &Error{
Message: "spotify: no more pages",
Status: http.StatusBadRequest,
}
type Error struct {
Message string `json:"message"`
Status int `json:"status"`
}
func (e *Error) Error() string {
return fmt.Sprintf("Status code: %d. Message: %... |
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use ... |
package gosandpit
import "fmt"
func send() {
// messages <- "ping"
}
func receive() {
}
// ChannelAdv ...
func ChannelAdv() {
messages := make(chan string)
// go func() { messages <- "ping" }()
go send()
go receive()
msg := <-messages
fmt.Println(msg)
}
|
package main
import (
"fmt"
"github.com/liuzl/dl"
"io/ioutil"
"os"
"path/filepath"
)
// WriteFile writes data to file at filePath
func WriteFile(filePath, fileName string, data []byte) {
path := filepath.Join(filePath, fileName)
fmt.Println(path)
err := ioutil.WriteFile(path, data, os.FileMode(0664))
if err ... |
package services
import (
"github.com/MEIGUOSHU/meiguoshu_api_server/models"
"github.com/MEIGUOSHU/meiguoshu_api_server/utils"
"github.com/kataras/iris/core/errors"
)
var i int
func CreateCategory(cate *models.Category) (*models.Category, error) {
res, err := cate.Create(utils.DB)
return res, err
}
func Update... |
package actions
import (
"context"
"fmt"
"strings"
"github.com/chitoku-k/ejaculation-counter/reactor/infrastructure/client"
"github.com/chitoku-k/ejaculation-counter/reactor/service"
"github.com/mattn/go-mastodon"
"github.com/pkg/errors"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus... |
package main
import (
"00-newapp-template/internal"
)
func main() {
a := internal.NewApp()
a.Main()
return
}
|
// Intermediate library used in this test.
package parse
import "test/go_rules/test"
func GetAnswer() int {
return test.GetAnswer()
}
//go:generate stringer -type=Cat
type Cat int
const (
Ginger Cat = iota
Tortoiseshell
Bengal
Halp
)
|
package envdir
import (
"bytes"
"github.com/stretchr/testify/assert"
"os"
"os/exec"
"path/filepath"
"testing"
)
var workDirectoryPath, _ = os.Getwd()
// TestCase try to get environments from absent folder
func TestReadUnknownDir(t *testing.T) {
unknownPath := filepath.Join(workDirectoryPath, "unknown_folder/"... |
// 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... |
package command
import (
"flag"
"fmt"
"os"
"testing"
"time"
. "gopkg.in/check.v1"
)
var travis = flag.Bool("travis", false, "Enable it if the tests runs in TravisCI")
// Hook up gocheck into the "go test" runner.
func Test(t *testing.T) { TestingT(t) }
type CommandSuite struct{}
var _ = Suite(&CommandSuite{... |
/*
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 writing, softw... |
package main
import (
"log"
"os"
)
func readCurrentDir() {
file, err := os.Create("output.txt")
if err != nil {
log.Fatalf("failed opening directory")
}
defer file.Close()
}
func main() {
readCurrentDir()
}
|
package enum
type FinanceBillType int
const (
FinanceBillType_DEPOSIT FinanceBillType = 0
FianceBillType_EXPENSE FinanceBillType = 1
)
|
package mock
import (
"time"
)
// TestTime is used for testing time fields
func TestTime(year int) time.Time {
return time.Date(year, time.May, 19, 1, 2, 3, 4, time.UTC)
}
|
package approvalapi
import (
"context"
"net/http"
"strings"
remoteapprovalapi "github.com/lexis-project/lexis-backend-services-interface-approval-system.git/client"
remoteapprovalresources "github.com/lexis-project/lexis-backend-services-interface-approval-system.git/client/hpc_resource_management"
remoteapprov... |
package unionfind
import ()
type UnionFind interface {
Union(p, q int)
Connected(p, q int) bool
}
type quickFind struct {
id []int
}
func NewQuickFind(n int) *quickFind {
q := new(quickFind)
q.id = make([]int, n)
for i := 0; i < n; i++ {
q.id[i] = i
}
return q
}
func (qf quickFind) Union(p, q int) {
idp... |
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"path"
)
func mainHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "this is the mainHandler")
}
/*
IDSRequest is a struct representing a request
sent to the server asking for a single block (i.e. WorkItem)
*/
type IDSRequest st... |
package micropay
import (
"fmt"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/address"
"github.com/iotaledger/goshimmer/dapps/valuetransfers/packages/balance"
"github.com/iotaledger/hive.go/crypto/ed25519"
"github.com/iotaledger/wasp/packages/coretypes"
"github.com/iotaledger/wasp/packages/coret... |
/*
Create a function which takes in a date as a string, and returns the date a week after.
Examples
weekAfter("12/03/2020") ➞ "19/03/2020"
weekAfter("21/12/1989") ➞ "28/12/1989"
weekAfter("01/01/2000") ➞ "08/01/2000"
Notes
Note that dates will be given in day/month/year format.
Single digit numbers should be z... |
package Repository
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"log"
)
type RepositoryMysql struct {
db *sql.DB
}
var (
username string = "usnbuus7qz634mfn"
password string = "eGPmxLkhfNLevfwyn6hW"
host string = "bsifbrjg2n6llr3biozg-mysql.services.clever-cloud.com"
port int ... |
package converttyme
import (
"time"
"github.com/seiyab/tyme"
)
// ToTime is used to convert to time.Time
func (i IntermediateTime) ToTime() time.Time {
return time.Time(i)
}
// ToLocalYear is used to convert to LocalYear
func (i IntermediateTime) ToLocalYear() tyme.LocalYear {
return tyme.NewLocalYear(time.Time... |
package html
import (
"fmt"
"strings"
"github.com/sparkymat/webdsl/css"
)
type Node struct {
Name string
Attributes map[string]string
Classes map[css.Class]interface{}
Children []*Node
HtmlString *string
}
func (n Node) String() string {
if n.HtmlString != nil {
return *n.HtmlString
}
htmlS... |
package twitter
import (
"encoding/base64"
"fmt"
"net/http"
"github.com/dghubble/sling"
)
// The size of a chunk to upload. There isn't any set size, so we
// choose 1M for convenience.
const chunkSize = 1024 * 1024
// This should really be fetched from the status endpoint, but the
// docs say 15M so we'll go w... |
package controllers
import (
"github.com/astaxie/beego/logs"
"github.com/astaxie/beego/orm"
"github.com/web/questionnaire/models"
)
type Refirm struct {
BaseController
}
// @router /registered [get]
func (c *Refirm) Registered() {
o := orm.NewOrm()
firm := models.Firm{}
firm.Firmname = c.GetMustString("Firmna... |
// Copyright 2022 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 helpers
import (
"context"
"encoding/json"
"fmt"
"reflect"
"testing"
"time"
clusterfake "github.com/open-cluster-management/api/client/cluster/clientset/versioned/fake"
clusterv1 "github.com/open-cluster-management/api/cluster/v1"
testinghelpers "github.com/open-cluster-management/registration/pkg/he... |
package main
import (
"github.com/mndrix/tap-go"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
func main() {
var shares uint64 = 1024
var period uint64 = 100000
var quota int64 = 50000
var c... |
package utils
import (
"io/ioutil"
"gopkg.in/yaml.v2"
"os"
"strings"
"path"
)
type Config map[string]interface{}
var Configs = make(map[string]Config) //todo:是否把总配置放这里,应不应该放到业务中去
var AppConfig Config //app的配置
var Suffix = []string{".yml"} //只支持yaml配置格式
func (c Config) Resolve(filePath string) {
f, err :=... |
package main
import (
cli "github.com/rancher/wrangler-cli"
"github.com/rancher/wrangler-cli/example/pkg/app"
)
func main() {
cli.Main(app.New())
}
|
// Copyright 2017 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
// +build windows
package core
const (
defaultNumOpenFiles int = 10000
)
// GetFileLimit raises the number of open files limit to the current hard limit. The
// value... |
package models
import "github.com/google/uuid"
type User struct {
UID string
Name string
Age string
ChatRoomID string
}
func NewUser() *User {
return &User{
UID: uuid.New().String(),
}
}
func (user *User) SetName(name string) *User {
user.Name = name
return user
}
func (user *User) Se... |
// Copyright 2016 by caixw, All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
package syslocale
import (
"testing"
"github.com/issue9/assert"
)
func TestGetLocaleName(t *testing.T) {
a := assert.New(t)
name, err := getLocaleName()
a.NotError... |
package ringreader
import (
"testing"
)
func TestRingReader(t *testing.T) {
r, _ := NewReader(256)
t.Log("buffer:", r.Buf)
for i := 1; i < 1048576; i = i * 2 {
buf := make([]byte, i)
n, err := r.Read(buf)
if err != nil {
t.Error(err)
}
if n != len(buf) {
t.Error("did not read %d bytes", n)
}
... |
package tool
import (
"github.com/gin-contrib/sessions"
"github.com/gin-contrib/sessions/redis"
"github.com/gin-gonic/gin"
"log"
)
//初始化session操作
func InitSession(engine *gin.Engine){
config:=GetConfig().RedisConfig
store,err:=redis.NewStore(10,"tcp",config.Addr+":"+config.Port,config.Password,[]byte("secret"))... |
// Copyright 2019 The CVPM Authors. All rights reserved.
// Use of this source code is governed by a MIT
// license that can be found in the LICENSE file.
/*
* This file handles virtual environment for engine to use.
* It is designed to support different virtual environment frameworks, for now,
* it support:
* Venv, S... |
package main
import (
"os"
"os/signal"
"syscall"
"time"
_ "net/http/pprof"
"github.com/etf1/kafka-message-scheduler-admin/server/runner/mini"
log "github.com/sirupsen/logrus"
metrics "github.com/tevjef/go-runtime-metrics"
)
var (
version = "mini"
enableTevjefMetrics = false
)
func main() {
i... |
package mongodb
import (
"context"
"fmt"
"github.com/go-ocf/cloud/cloud2cloud-connector/store"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
const subscriptionCName = "Subscription"
const hrefKey = "resourcehref"
const linkedAccountIDKey = ... |
package main
import (
"bytes"
"encoding/binary"
"errors"
"fmt"
"io"
"net"
)
var TypeMapping = map[uint16]string{
1: "A",
2: "NS",
5: "CNAME",
6: "SOA",
11: "PTR",
15: "MX",
16: "TXT",
28: "AAAA",
252: "AXFR",
255: "ANY",
}
var ClassMapping = map[uint16]string{
1: "IN",
}
var OpcodeMappi... |
// Driver for cellular automata image output.
// Author: Matt Godshall
// Date : 08-31-2013
package main
import (
"encoding/hex"
"flag"
"fmt"
"image/color"
)
type colorError struct {
message string
}
func (c *colorError) Error() string {
return c.message
}
// Convert a color hex string (ex:... |
package klenv
import (
"os"
"testing"
"time"
"github.com/lalamove/konfig"
"github.com/lalamove/nui/nstrings"
"github.com/stretchr/testify/require"
)
func TestEnvLoader(t *testing.T) {
t.Run(
"load defined env vars",
func(t *testing.T) {
os.Setenv("FOO", "BAR")
os.Setenv("BAR", "FOO")
var l = New... |
package toecutter
import "github.com/BurntSushi/toml"
type Config struct {
Main MainConfig `toml:"main"`
}
// MainConfig ...
type MainConfig struct {
Curl string `toml:"curl"`
URL string `toml:"url"`
SiteKey string `toml:"site-key"`
APIPublic string `toml:"api-public"`
APIPrivate string `toml:... |
package main
import "fmt"
func main() {
a := 46
fmt.Printf("Decimal: %v\n", a)
fmt.Printf("Binary: %b\n", a)
fmt.Printf("Hex: 0x%X\n", a)
}
|
/* package justEmail provides basic functions to use SMTP in a way that most people would. As HTML, over TLS, and also retrying if it sends on a disconnected client */
package justEmail
import (
"crypto/tls"
"fmt"
"net/smtp"
"strings"
log "github.com/autopogo/justLogging"
"errors"
)
var (
ErrServerUnavailabl... |
package validator
import (
"regexp"
"strings"
"gopkg.in/go-playground/validator.v9"
"ImaginatoGolangTestTask/shared/common"
)
type IValidatorService interface {
ValidateStruct(req interface{}, name string) (string, bool)
}
type Validator struct{}
func NewValidatorService() IValidatorService {
return &Validat... |
/*
Given a number n, return True if n is in the range 1..10, inclusive. Unless outside_mode is True, in which case return True if the number is less or equal to 1, or greater or equal to 10.
*/
package main
import (
"fmt"
)
func in1to10(n int, outside_mode bool) bool {
if outside_mode {
return n <= 1 || n >= 10
... |
/*
Copyright 2023 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 writing, softw... |
package routes
import (
"Golang-Echo-MVC-Pattern/controller"
"Golang-Echo-MVC-Pattern/utils"
"github.com/labstack/echo"
)
type Routing struct {
example controller.ExampleController
}
func (Routing Routing) GetRoutes() *echo.Echo {
e := echo.New()
e.GET("/posts/", Routing.example.GetPostsController)
e.POST("/... |
package cloudflare
import (
"encoding/json"
"io/ioutil"
"net/http"
"github.com/nitschmann/scdns/pkg/util/rest"
)
func ExecRequestAndUnmarshalJson(r *rest.Request, v interface{}) (*http.Response, error) {
httpResponse, err := r.Exec()
if err != nil {
return httpResponse, err
}
values, err := ioutil.ReadAll... |
package domain
import (
"context"
"github.com/go-kit/log"
"github.com/google/uuid"
)
type ServiceInterface interface {
Matrix(ctx context.Context, id uuid.UUID) (Matrix, error)
Matrices(ctx context.Context) ([]Matrix, error)
CreateMatrix(ctx context.Context, matrix *Matrix) error
UpdateMatrix(ctx context.Cont... |
package main
import (
"fmt"
"strconv"
"strings"
)
func initializeGama(size int) []map[string]int {
gama := make([]map[string]int, 0)
for i := 0; i < 12; i++ {
gama = append(gama,
map[string]int{
"0": int(0),
"1": int(0),
})
}
return gama
}
type DiagnosticReport struct {
Gama []map[string]... |
package cleanup
// import (
// "strings"
// "testing"
// "github.com/devspace-cloud/devspace/cmd/flags"
// "gotest.tools/assert"
// )
// func TestNewCleanupCmd(t *testing.T) {
// cleanupCmd := NewCleanupCmd(&flags.GlobalFlags{})
// subcommands := cleanupCmd.Commands()
// expectedSubcommandNames := []string{"... |
// ˅
package main
// ˄
type ILink interface {
Item
// ˅
// ˄
}
// ˅
// ˄
|
// Copyright 2019 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 fitbit
import (
"context"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func setup_client() *Client {
return New(os.Getenv("TEST_TOKEN"))
}
func TestClientToken(t *testing.T) {
t.Run("success case", func(t *testing.T) {
token := &Token{
AccessToken: os.Getenv("TEST_TOKEN"),
}
c := New... |
package main
import (
"fmt"
"sync"
)
var a chan int
var wg sync.WaitGroup
func nobuf() {
wg.Add(1)
go func() {
defer wg.Done()
x := <-a
fmt.Printf("goroutine从通道a中取到了值:%v\n", x)
}()
a = make(chan int)
defer close(a) //关闭通道
a <- 10
wg.Wait()
}
func buf() {
a = make(chan int, 2)
defer close(a) //关闭通道
... |
package main
import (
"./network"
"fmt"
"runtime"
"strings"
"time"
)
func main() {
runtime.GOMAXPROCS(20)
incomingCh := make(chan interface{}, 1)
outgoingCh := make(chan interface{}, 1)
networkCh := make(chan string, 1)
var online bool = false
var localID string
var timestamp = time.Now()
activeElevs :=... |
package dushengchen
/**
Submission:
https://leetcode.com/submissions/detail/370577886/
*/
func canJump(nums []int) bool {
if len(nums) == 0 {
return true
}
reachable := make([]bool, len(nums))
reachable[0] = true
for i, v := range nums {
if !reachable[i] {
continue
}
for j := 1; j <= v; j++ {
if... |
package user
import (
pbUser "Open_IM/pkg/proto/user"
"Open_IM/pkg/common/config"
"Open_IM/pkg/common/log"
"Open_IM/pkg/grpc-etcdv3/getcdv3"
"context"
"github.com/gin-gonic/gin"
"net/http"
"strings"
)
type userInfo struct {
UID string `json:"uid"`
Name string `json:"name"`
Icon string `json:"icon"`
... |
package direct
import (
"encoding/json"
"github.com/trevor403/gostream/pkg/input"
)
func Handle(data []byte) {
raw := input.RawEvent{}
_ = json.Unmarshal(data, &raw)
switch raw.Type {
case input.KeyEventType:
ev := input.KeyEvent{}
json.Unmarshal(data, &ev)
HandleKey(ev)
case input.MouseEventType:
ev... |
package main
import (
_ "embed"
"os"
"text/template"
)
const templateText = `
{{- "" -}}
My context looks like this: {{ . }}
{{- /* You can use variables to store data before a context change */}}
{{- $data := . }}
{{- with .Company }}
"with .Company" the context is: {{ . }}
Root: {{ $data }}
Employees: {{ $da... |
/*
Package rtsp provides protocol definitions and parsers
*/
package rtsp
|
package main
/**
529. 扫雷游戏
让我们一起来玩扫雷游戏!
给定一个代表游戏板的二维字符矩阵。
'M' 代表一个未挖出的地雷,
'E' 代表一个未挖出的空方块,
'B' 代表没有相邻(上,下,左,右,和所有4个对角线)地雷的已挖出的空白方块,
数字('1' 到 '8')表示有多少地雷与这块已挖出的方块相邻,'X' 则表示一个已挖出的地雷。
现在给出在所有未挖出的方块中('M'或者'E')的下一个点击位置(行和列索引),根据以下规则,返回相应位置被点击后对应的面板:
如果一个地雷('M')被挖出,游戏就结束了- 把它改为 'X'。
如果一个没有相邻地雷的空方块('E')被挖出,修改它为('B'),并且所有和其... |
/*
hasaki-quant 数据中台连接交易所的网关
所有交易所的连接都通过gateway去调度
网关包括请求所有交易所的价格行情,所有接口的数据最后在gateway中进行抽象
网关还包含统一发单的功能,如果交易所被墙,那么在外网部署另一个hasaki-server,然后国内的服务中台的网关
连接墙外的数据中台进行数据订阅
所以hasaki-quant data server center做一个分支,若是在墙外启动,则在服务中台的配置文件中进行设置,只执行部分功能
网关接受下单需要的参数: market,symbol,price,volume 订阅行情需要的参数 : market,symbol,freque... |
package util
import (
"github.com/satori/go.uuid"
"strings"
)
//生成uuid
func GenerateUuid() string {
uid := uuid.NewV1()
uids := strings.Split(uid.String(), "-")
return uids[0] + uids[1] + uids[2] + uids[4] + uids[3]
}
|
package keycloak
import (
"fmt"
)
type Role struct {
Id string `json:"id,omitempty"`
RealmId string `json:"-"`
Name string `json:"name"`
}
func (keycloakClient *KeycloakClient) NewRole(role *Role) error {
var createRoleUrl string
createRoleUrl = fmt.Sprintf("/%s/clients/%s/roles", role.Name, role.Id)
... |
package middleware
import (
"time"
"github.com/jjeffcaii/mongo-proxy"
"github.com/jjeffcaii/mongo-proxy/protocol"
)
var instSkipIsMaster *skipIsMaster
func init() {
instSkipIsMaster = &skipIsMaster{}
}
type skipIsMaster struct {
}
func (p *skipIsMaster) Handle(ctx pxmgo.Context, req protocol.Message) error {
... |
// Copyright 2022 PingCAP, Inc. Licensed under Apache-2.0.
package daemon
import "context"
// Interface describes the lifetime hook of a daemon application.
type Interface interface {
// OnStart start the service whatever the tidb-server is owner or not.
OnStart(ctx context.Context)
// OnBecomeOwner would be call... |
package resolver
import (
"fmt"
"reflect"
"github.com/dalloriam/synthia/core"
"github.com/dalloriam/websynth/app/audio"
)
type SignalResolver struct {
sys *audio.System
sgn *core.Signal
}
func (s *SignalResolver) Attach(args struct {
ModuleIdx int32
ModuleField *string
}) (bool, error) {
i := int(args.M... |
package entities
const (
// AdministratorRole defines role of administrator
AdministratorRole = "administrator"
)
// User defines a user for our application
type User struct {
Username string `json:"username"`
Password string `json:"password"`
FirstName string `josn:"firstname"`
LastName string `json... |
// Licensed to Elasticsearch B.V. under one or more contributor
// license agreements. See the NOTICE file distributed with
// this work for additional information regarding copyright
// ownership. Elasticsearch B.V. licenses this file to you under
// the Apache License, Version 2.0 (the "License"); you may
// not use ... |
package charts
import (
"github.com/go-echarts/go-echarts/v2/opts"
"github.com/go-echarts/go-echarts/v2/render"
"github.com/go-echarts/go-echarts/v2/types"
)
// HeatMap represents a heatmap chart.
type HeatMap struct {
RectChart
}
// Type returns the chart type.
func (*HeatMap) Type() string { return types.Chart... |
package website
import (
"bytes"
"encoding/json"
"fmt"
"html/template"
"io"
"master/master"
"master/master/delegateRequestToSlave"
"net/http"
"network"
"path"
"website/session"
)
var (
IMAGES_PATH = network.PROJECT_ROOT + "/src/website/assets/images"
JAVASCRIPTS_PATH = network.PROJECT_ROOT + "/src/w... |
package problems
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func Test_moveZeroes(t *testing.T) {
type args struct {
nums []int
}
tests := []struct {
name string
args args
want []int
}{
{
name: "example 1",
args: args{
nums: []int{0, 1, 0, 3, 12},
},
want: []int{... |
package service
import (
"bufio"
"encoding/json"
"fmt"
"github.com/BurntSushi/toml"
"github.com/alecthomas/log4go"
"github.com/bitly/go-simplejson"
"github.com/robfig/cron"
log "github.com/sirupsen/logrus"
"os"
"strconv"
"zhiyuan/device_server/raying_api/internal/model"
)
func digital2String(digital string... |
package ch05
import "sort"
// Find min in the sorted rotated list.
func FindMin(in []int) int {
cpy := make([]int, len(in))
copy(cpy, in)
sort.Ints(cpy)
return cpy[0]
}
|
package tmpl3
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
)
func Test_findClosestElements(t *testing.T) {
tcs := []struct {
nums []int
k, x int
expect []int
}{
{[]int{1, 2, 3, 4, 5}, 4, 3, []int{1, 2, 3, 4}},
{[]int{1, 2, 3, 4, 5}, 4, -1, []int{1, 2, 3, 4}},
{[]int{1, 2, 3, 4,... |
package main
import (
_ "fmt"
"sort"
)
type HandData struct {
suitCount [LastSuit]int
rankCount [LastRank]int
}
func GenAllHands(deck *Deck) []Hand {
h := NewHand()
allHands := make([]Hand, 0, 2600000)
genHandsRecursive(deck.Cards, &h, &allHands)
return allHands
}
func genHandsRecursive(deck []Card, hand ... |
package env_test
import (
"testing"
"github.com/nasermirzaei89/env"
"github.com/stretchr/testify/assert"
)
func TestGetInt64Slice(t *testing.T) {
def := []int64{21, 22}
res := env.GetInt64Slice("V1", def)
assert.Equal(t, def, res)
expected := []int64{31, 32, 33}
t.Setenv("V1", "31,32,33")
res = env.GetI... |
package localcache_test
import (
"context"
"go.mercari.io/datastore/v2/clouddatastore"
"go.mercari.io/datastore/v2/dsmiddleware/localcache"
"go.mercari.io/datastore/v2/internal/testutils"
)
func Example_howToUse() {
ctx := context.Background()
client, err := clouddatastore.FromContext(ctx)
if err != nil {
p... |
package broadcaster
import (
"log"
"net/http"
"github.com/gin-gonic/gin"
"github.com/gorilla/websocket"
)
type Client struct {
hub *Hub
conn *websocket.Conn
message chan Message
}
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) boo... |
// Copyright 2022 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 in wr... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.