text stringlengths 11 4.05M |
|---|
package model
import (
"fmt"
"glog/utils"
"log"
"time"
_ "github.com/jinzhu/gorm/dialects/mysql"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"gorm.io/gorm/logger"
"gorm.io/gorm/schema"
)
var (
db *gorm.DB
err error
)
func InitDb() {
dns := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=True&loc=L... |
// Copyright 2017 Mirantis
//
// 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 writi... |
/*
The MIT License (MIT)
Copyright (c) 2014 Chris Grieger
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge,... |
/*
* Copyright © 2018-2022 Software AG, Darmstadt, Germany and/or its licensors
*
* SPDX-License-Identifier: Apache-2.0
*
* 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://... |
// Lock is an implementation of the github.com/kaepora/miniLock encrypted container.
// This is a simple CLI interface to decrypt minilock container.
package main
import (
"flag"
"fmt"
"os"
"github.com/sycamoreone/lock/minilock"
"golang.org/x/crypto/ssh/terminal"
)
var (
ourPublic, ourSecret *[32]byte // Our o... |
package main
import (
"net/http"
"strings"
"text/template"
"encoding/json"
"io/ioutil"
"path"
"path/filepath"
"os"
"fmt"
"github.com/spf13/hugo/parser"
//"github.com/op/go-logging"
)
var (
//log = logging.MustGetLogger("main")
)
func isEditable(value interface{}) bool {
t := value.(string)
return ... |
package invoker
import (
"context"
"github.com/pkg/errors"
"google.golang.org/grpc"
v1 "github.com/mee6aas/zeep/pkg/api/invoker/v1"
)
// Connect connects to the agent with the specified address.
func Connect(ctx context.Context, addr string) (e error) {
if conn, e = grpc.Dial(addr, grpc.WithInsecure(), grpc.Wi... |
package main
import (
"github.com/docker/docker-credential-helpers/credentials"
"github.com/rancher-sandbox/rancher-desktop/src/go/docker-credential-none/dcnone"
)
func main() {
credentials.Serve(dcnone.DCNone{})
}
|
package message
import "fmt"
// Message ...
type Message string
// String ...
func (m Message) String() string {
return string(m)
}
// Format ...
func (m Message) Format(args ...interface{}) string {
return fmt.Sprintf(string(m), args...)
}
// Equal ...
func (m Message) Equal(src string) bool {
return string(m)... |
package main
import (
"flag"
"mqtt-adapter/src/adapter"
"mqtt-adapter/src/config"
"mqtt-adapter/src/logger"
)
var (
configFlag = flag.String("conf", "./package.json", "Path to package.json file")
subsFlag = flag.String("subs", "./service-processor/subscriptions.txt", "Path to subscriptions.txt file")
listFl... |
package task
import (
"fmt"
"strings"
"tcc_transaction/constant"
"tcc_transaction/global/config"
"tcc_transaction/global/various"
"tcc_transaction/send"
"tcc_transaction/send/email"
"tcc_transaction/store/data"
)
func taskToSend(needRollbackData []*data.RequestInfo, subject string) {
var s send.Send = email.... |
package deezer
import (
"fmt"
"log"
"net/http"
"github.com/doctori/music-migrator/utils"
"github.com/go-resty/resty/v2"
)
const baseAddress = "https://api.deezer.com"
const tokenPath = ".deez"
// Client is a client for working with the Deezer Web API.
// To create an authenticated client, use the `Authenticato... |
package handlers
import (
"github.com/button-tech/BNBTextWallet/UI"
"github.com/bwmarrin/discordgo"
"strings"
)
func MainBotHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself
if m.Author.ID == s.State.User.ID {
return
}
ctx := UI.Pages{
Update: m,
... |
package admin
import (
"context"
"tpay_backend/adminapi/internal/common"
"tpay_backend/model"
"tpay_backend/adminapi/internal/svc"
"tpay_backend/adminapi/internal/types"
"github.com/tal-tech/go-zero/core/logx"
)
type GetPlatformBankCardListLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.Servi... |
package find
import (
"testing"
)
func TestFind(t *testing.T) {
a := "orlorlworlworl"
b := "worl"
t.Log(Find(a, b))
}
func TestGenerateBC(t *testing.T) {
b := "orlorlworlworl"
t.Log(generateBC(b))
}
func TestGenerateGS(t *testing.T) {
b := "orlorlworlworl"
t.Log(generateGS(b))
}
func BenchmarkFind(b *testi... |
package main
import "math"
func main() {
}
func minPathSum(grid [][]int) int {
res := 0
up := 0
left := 0
for i := 0; i < len(grid); i++ {
for j := 0; j < len(grid[0]); j++ {
if i == 0 {
up = math.MaxInt64
} else {
up = grid[i-1][j]
}
if j == 0 {
left = math.MaxInt64
} else {
le... |
// Copyright (c) 2023 Zededa, Inc.
// SPDX-License-Identifier: Apache-2.0
package zedrouter
import (
"bytes"
"context"
"fmt"
"math"
"net"
"os"
"os/exec"
"path/filepath"
"regexp"
"sync"
"sync/atomic"
"testing"
"time"
"github.com/insomniacslk/dhcp/dhcpv4/nclient4"
"github.com/lf-edge/eve/pkg/pillar/base... |
package main
import (
"crypto/rand"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
"path"
"text/template"
)
// Login request JSON
type User struct {
UserName string `json:"username"`
Password string `json:"password"`
}
// Users a struct of user
type Users struct {
Users []User `json:"users"`
}
... |
package mt
import "image/color"
type Param1Type uint8
const (
P1Nothing Param1Type = iota
P1Light
)
//go:generate stringer -trimprefix P1 -type Param1Type
type Param2Type uint8
const (
P2Nibble Param2Type = iota
P2Byte
P2Flowing
P2FaceDir
P2Mounted
P2Leveled
P2Rotation
P2Mesh
P2Color
P2ColorFaceDir
P... |
package main
import (
"strconv"
"strings"
)
type TreeNode struct {
Val int
Left *TreeNode
Right *TreeNode
}
type Codec struct {
}
func Constructor() Codec {
return Codec{}
}
// Serializes a tree to a single string.
func (this *Codec) serialize(root *TreeNode) string {
res := ""
if root == nil {
return... |
/*
* Tencent is pleased to support the open source community by making Blueking Container Service available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
* Licensed under the MIT License (the "License"); you may not use this file except
* in compliance with the License. You may obta... |
package ginplugin
import (
"github.com/gin-gonic/gin"
)
const defaultSessionManagerKey = "github.com/goodplayer/Princess"
func SessionHandler(sessionDomainService *SessionDomainService) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
sessionDomainService.initSessionManager(ctx)
ctx.Next()
}
}
func S... |
package solver
import (
"context"
"github.com/go-air/gini/inter"
"github.com/go-air/gini/z"
)
type choice struct {
prev, next *choice
index int // index of next unguessed literal
candidates []z.Lit
}
type guess struct {
m z.Lit // if z.LitNull, this choice was satisfied by a previous assumption... |
package log
import (
"fmt"
"math"
"gopkg.in/cheggaaa/pb.v1"
)
const (
NOCOLOR = 0
RED = 31
GREEN = 32
YELLOW = 33
BLUE = 36
GRAY = 37
UNICODE_FULL_BLOCK = "█"
UNICODE_HALF_BLOCK = "▌"
)
type Report struct {
O float64
Chunk float64
ProgressBar *pb.ProgressBar
}
func NewReport()... |
/*
* Copyright (c) 2020. Denis Rendler <connect@rendler.me>
*
* 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... |
/*
* @lc app=leetcode.cn id=70 lang=golang
*
* [70] 爬楼梯
*/
// @lc code=start
package main
import "fmt"
func climbStairs(n int) int {
p, q := 0, 0
r := 1
for i := 1; i <= n; i++ {
p = q
q = r
r = p + q
}
return r
}
func climbStairs2(n int) int {
if n == 2 {
return 2
}
if n == 1 {
return 1
}
r... |
package anansi
import (
"errors"
"fmt"
"image"
"os"
"syscall"
)
var errAttrNoFile = errors.New("anansi.Attr.ioctl: no File set")
// Attr implements Context-ual manipulation and interrogation of terminal
// state, using the termios IOCTLs and ANSI control sequences where possible.
type Attr struct {
file *os.Fi... |
package handlers
import (
"log"
"net/http"
"github.com/danielhood/quest.server.api/services"
)
// Ping holds handler structure
type Ping struct {
svc services.Ping
}
// NewPing creates an instance of Ping
func NewPing() *Ping {
return &Ping{services.NewPing()}
}
func (h *Ping) ServeHTTP(w http.ResponseWriter,... |
package leetcode
type ListNode struct {
Val int
Next *ListNode
}
type List struct {
Head *ListNode
Tail *ListNode
}
func (l *List) AddNode(n *ListNode) {
if l.Head == nil {
l.Head = n
}
if l.Tail != nil {
l.Tail.Next = n
}
l.Tail = n
}
func addTwoNumbers(l1 *ListNode, l2 *ListNode) *ListNode {
var li... |
package model
import (
_ "fmt"
)
type Choice struct {
comment string
condition string
code Code
}
func NewChoice() *Choice {
return &Choice{}
}
func (this *Choice) AcceptAsFirst(visitor CodeVisitor) {
visitor.VisitChoiceFirstBegin(this)
this.code.Accept(visitor)
visitor.VisitChoiceFirstEnd(this)
}
f... |
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
// Data struct
type Data struct {
Coords Coord `json:"coord"`
Weathers map[Weather]interface{} `json:"weather"`
Base string
Mains MainData `json:"main"`
Visibility int
}
// Coord struct
type Coord struc... |
package api
import (
"testing"
"unsafe"
"github.com/stretchr/testify/require"
)
func TestMakeView(t *testing.T) {
data := []byte{0xaa, 0xbb, 0x64}
dataView := makeView(data)
require.Equal(t, cbool(false), dataView.is_nil)
require.Equal(t, cusize(3), dataView.len)
empty := []byte{}
emptyView := makeView(emp... |
package spec
import (
"github.com/agiledragon/trans-dsl"
"github.com/agiledragon/trans-dsl/test/context"
)
type IsAbcExist struct {
}
func (this *IsAbcExist) Ok(transInfo *transdsl.TransInfo) bool {
stubInfo := transInfo.AppInfo.(*context.StubInfo)
return stubInfo.Abc == "abc"
}
|
package secrets
import (
"context"
"github.com/pkg/errors"
core_ca "github.com/kumahq/kuma/pkg/core/ca"
core_mesh "github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
core_xds "github.com/kumahq/kuma/pkg/core/xds"
)
type CaProvider interface {
// Get returns all PEM encoded CAs, a list of CAs that were used ... |
package endpoint
import (
"context"
"fmt"
// "github.com/feng/future/go-kit/agfun/agfun-server/entity"
"github.com/feng/future/go-kit/agfun/agfun-server/protocol"
"github.com/feng/future/go-kit/agfun/agfun-server/service"
// "github.com/go-kit/kit/endpoint"
)
//MakeAccountEndpoint 生成Account断点
func MakeAccountE... |
/**
* @file
* @copyright defined in aergo/LICENSE.txt
*/
package p2p
import (
"context"
"fmt"
"github.com/aergoio/aergo/config"
"github.com/aergoio/aergo/p2p/p2pkey"
"reflect"
"strings"
"testing"
"time"
"github.com/aergoio/aergo/p2p/p2pcommon"
"github.com/aergoio/aergo/p2p/p2pmock"
"github.com/golang... |
package cmd
import (
"bytes"
"fmt"
"os"
"os/exec"
"github.com/spf13/cobra"
)
var (
pipelinesGHOAuthKey string
pipelinesGHOAuthSecret string
pipelinesGHOAuthTeam string
pipelinesUsername string
pipelinesPassword string
pipelinesDev bool
)
// initPipelinesCmd represents the initpip... |
package main
import (
"html/template"
"net/http"
"regexp"
"fmt"
"runtime"
"strconv"
"radio"
"flag"
"encoding/json"
"log"
)
var templates = template.Must(template.ParseFiles("index.html"))
var playValidPath = regexp.MustCompile("^/(play)/(\\d)/*(.*)$")
func indexHandler(entryPoint string) func(w ... |
package main
import (
"github.com/javinc/go-space-shooter"
"github.com/javinc/go-space-shooter/system"
)
const (
title = "Shoot-em-Up"
screenWidth = 450
screenHeight = 600
)
var engine *ecs.Engine
func init() {
engine = ecs.New(title, screenWidth, screenHeight)
}
func main() {
engine.Start()
// Re... |
package chapter14
import (
"fmt"
"testing"
)
func inOrderTraversal(root *TreeNode) {
if root == nil {
return
} else {
inOrderTraversal(root.Left)
fmt.Println(root.Value)
inOrderTraversal(root.Right)
}
}
func TestRebuildBSTPreorder(t *testing.T) {
root := RebuildBSTPreorder([]int{19, 7, 3, 2, 5, 11, 17,... |
package main
import "fmt"
func main() {
type NoKtp string
type Married bool
var noKtp NoKtp = "3212902929221"
var status Married = true
fmt.Println(noKtp)
fmt.Println(status)
} |
package guest
import (
"context"
"github.com/angryronald/guestlist/internal/guest/domain"
"github.com/angryronald/guestlist/internal/guest/public"
)
func (s *Service) ListGuests(ctx context.Context, isArrivedOnly bool) ([]*public.Guest, error) {
guestsRepo, err := s.repository.FindAll(ctx, isArrivedOnly)
if err... |
package api
import (
"fmt"
"octlink/mirage/src/modules/usergroup"
"octlink/mirage/src/utils"
"octlink/mirage/src/utils/merrors"
"octlink/mirage/src/utils/octlog"
"octlink/mirage/src/utils/uuid"
)
func APIAddUserGroup(paras *ApiParas) *ApiResponse {
resp := new(ApiResponse)
newGroup := usergroup.FindGroupByNa... |
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package transform
import (
"os"
"testing"
"github.com/Jeffail/gabs"
. "github.com/onsi/gomega"
)
func TestAPIModelMergerMapValues(t *testing.T) {
RegisterTestingT(t)
m := make(map[string]APIModelValue)
values := ... |
package sqlconnector
import (
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
"log"
"os"
)
func connectCloudSql() (*gorm.DB, error) {
connectionName := os.Getenv("CLOUDSQL_CONNECTION_NAME")
if len(connectionName) == 0 {
return nil, ... |
package main
import "fmt"
func main() {
fmt.Println(equalFrequency("abcc"))
fmt.Println(equalFrequency("bac"))
fmt.Println(equalFrequency("ddaccb"))
fmt.Println(equalFrequency("aca"))
}
func equalFrequency(word string) bool {
bs := []byte(word)
var dfs func(idx int) bool
dfs = func(idx int) bool {
m := mak... |
package main
import (
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/mysql"
"github.com/strava/go.strava"
"gopkg.in/natefinch/lumberjack.v2"
"log"
"os"
"path/filepath"
)
// Main function.
func main() {
appDir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
log.SetOutput(&lumberjack.Logger{
Filen... |
package promise
import (
"encoding/json"
"errors"
"fmt"
"log"
"gopkg.in/confluentinc/confluent-kafka-go.v1/kafka"
)
// KafkaConfig is a config for using kafka
type KafkaConfig struct {
BoostrapServers string
}
// KafkaClient is a client that can consumes and produces messages
type KafkaClient struct {
produc... |
package arangodb
import (
"fmt"
"github.com/apex/log"
"github.com/thedanielforum/arangodb/errc"
)
func (c *Connection) Delete(collectionName string ,docHandle string) error {
endPoint := fmt.Sprintf("_db/%s/_api/document/%s/%s", c.db, collectionName,docHandle)
_,err := c.del(endPoint, nil)
if err != nil {
/... |
// Copyright (C) 2015 Scaleway. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE.md file.
package commands
import (
"strings"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func ExampleRunImages() {
ctx := testCommandContext()
args... |
package sdk
import (
"context"
"encoding/json"
"net/http"
rm "github.com/brigadecore/brigade/sdk/v3/internal/restmachinery"
"github.com/brigadecore/brigade/sdk/v3/meta"
"github.com/brigadecore/brigade/sdk/v3/restmachinery"
)
const (
// RoleAssignmentKind represents the canonical RoleAssignment kind string
Ro... |
package sys
import "easyctl/util"
// 查询端口监听
func SearchPortStatus(port string) (result string, err error) {
cmd := "ss -alnpt|grep " + port
return util.ExecuteCmdAcceptResult(cmd)
}
|
package models
import (
"github.com/jinzhu/gorm"
// psql driver only w/Initializers
_ "github.com/jinzhu/gorm/dialects/postgres"
// sqlite driver only w/Initializers
_ "github.com/jinzhu/gorm/dialects/sqlite"
)
// Database - namespace
type Database struct {
*gorm.DB
}
// NewPostgresDatabase - postgres database... |
package app
import (
"github.com/gin-gonic/gin"
"github.com/mvrsss/go-todo-api/app/controllers"
)
func SetRouters() *gin.Engine {
r := gin.Default()
v1 := r.Group("/v1")
{
v1.GET("todo", controllers.GetAllTasks)
v1.POST("todo", controllers.AddTask)
v1.GET("todo/:id", controllers.GetATask)
v1.PUT("todo/:... |
package quicksort
import (
"log"
"math/rand"
)
// Basic quicksort algorithm (Hoore circa 1961)
// Sort the array in-place
func Sort(a []int, strategy PivotChoice) (count int) {
if len(a) <= 1 {
return
}
// Swap pivot to the first position in a[left]
strategy.Pivot(a)
index := Par... |
/*
* @lc app=leetcode.cn id=12 lang=golang
*
* [12] 整数转罗马数字
*/
// @lc code=start
package main
import (
"fmt"
"math"
"strconv"
)
func main() {
var a int
a = 90
fmt.Printf("%d, %s\n", a, intToRoman(a))
a = 1049
fmt.Printf("%d, %s\n", a, intToRoman(a))
a = 100049
fmt.Printf("%d, %s\n", a, intToRoman(a))... |
// Copyright © 2018 Sunface <CTO@188.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 ... |
package main
import "fmt"
func searchMatrix(matrix [][]int, target int) bool {
return searchMatrix3(matrix, target)
}
// https://leetcode-cn.com/problems/search-a-2d-matrix/
func searchMatrix1(matrix [][]int, target int) bool {
n := len(matrix)
if n == 0 {
return false
}
m := len(matrix[0])
if m == 0 {
re... |
package main
import (
"bufio"
"fmt"
"log"
"net"
)
func main() {
conn, err := net.Dial("tcp", "127.0.0.1:8080")
if err != nil {
log.Fatal(err)
}
/*
fmt.Fprintf(conn, "GET /HTTP/1.0\r\n\n")
status, err := bufio.NewReader(conn).ReadString('\n')
if err != nil {
log.Fatal(err)
}
fmt.Println(status)*... |
package erroneous
import (
"time"
"github.com/twinj/uuid"
)
// Guid is an alias for uuid.UUID. Indluded to reduce repetition of external package
type Guid uuid.UUID
// Store is an interface to abstract storage of error data.
type Store interface {
ProtectError(Guid) error
DeleteError(Guid) error
DeleteAllError... |
package leetcode
import "testing"
func TestHashMap(t *testing.T) {
hm := Constructor()
hm.Put(1, 1)
hm.Put(2, 2)
if hm.Get(1) != 1 {
t.Fatal()
}
if hm.Get(3) != -1 {
t.Fatal()
}
hm.Put(2, 1)
if hm.Get(2) != 1 {
t.Fatal()
}
hm.Remove(2)
if hm.Get(2) != -1 {
t.Fatal()
}
}
|
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
fmt.Println(compareVersion("1.01", "1.001"))
fmt.Println(compareVersion("1.0", "1.0.0"))
fmt.Println(compareVersion("0.1", "1.1"))
}
// leetcode submit region begin(Prohibit modification and deletion)
func compareVersion(version1 string, version2... |
package main
import (
"fmt"
)
func main() {
var1 := 10
var2 := 10.5
// illegal
// var3 := var1 + var2
// legal
var3 := var1 + int(var2)
var4 := float64(var1) + var2
fmt.Println("int: ", var1, "+", var2, "=", var3)
fmt.Println("float64: ", var1, "+", var2, "=", var4)
}
|
package engine
import (
"github.com/d5/tengo/v2"
"github.com/pkg/errors"
)
/*
factorValue := factor(domain_id, "bridgeCode name")
*/
func factorGetInTengo(runtimeCtx domainStatus) func(args ...tengo.Object) (ret tengo.Object, err error) {
return func(args ...tengo.Object) (ret tengo.Object, err error) {
if len(a... |
package discovery
import (
"strings"
"sync"
"time"
"github.com/appootb/grc"
"github.com/appootb/substratum/discovery"
)
func Init() {
if discovery.Implementor() == nil {
debug, _ := grc.New(grc.WithDebugProvider())
Register(debug)
}
}
func Register(rc *grc.RemoteConfig) {
discovery.RegisterImplementor(&... |
package main
// "fmt"
// User sds
type User struct {
ID int64
Name string
Avatar string
}
// GetUserInfo dsd
func GetUserInfo() *User {
return &User{ID: 13746731, Name: "EDDYCJY", Avatar: "https://avatars0.githubusercontent.com/u/13746731"}
}
// GetUserInfos dsa
func GetUserInfos(u *User) *User {
return ... |
package models
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/config"
"github.com/astaxie/beego/orm"
_ "github.com/go-sql-driver/mysql"
"strconv"
"time"
)
type Admin struct {
Id int64
Username string
Password string
Time time.Time
}
type Web struct {
Id int64
Url string
Ico... |
package stop
//go:generate stringer -type=EvalType eval_type.go
// EvalType represents the type of the output returned from a STOP
// evaluation.
type EvalType uint32
const (
TUnsupported EvalType = 0
TString EvalType = 1 << iota
TList
TMap
TBool
)
|
// +build !race
package consul
import (
"context"
"testing"
"time"
"github.com/square/p2/pkg/store/consul/transaction"
"github.com/square/p2/pkg/util"
)
const (
lockMessage = "Locked by lock_test.go"
)
func TestSession(t *testing.T) {
fixture := NewConsulTestFixture(t)
defer fixture.Close()
sessionRenewa... |
package whatlanggo
import (
"unicode"
)
type trigram struct {
trigram string
count int
}
//convert punctuations and digits to space.
func toTrigramChar(ch rune) rune {
if isStopChar(ch) {
return ' '
}
return ch
}
func count(text string) map[string]int {
var r1, r2, r3 rune
trigrams := map[string]int{}
... |
package true_git
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/go-git/go-git/v5"
"github.com/werf/werf/pkg/util"
)
func UpwardLookupAndVerifyWorkTree(lookupPath string) (bool, string, error) {
lookupPath = util.GetAbsoluteFilepath(lookupPath)
for {
dotGitPath := filepath.Join(lookup... |
package api
import (
"context"
"encoding/json"
"fmt"
"io/ioutil"
stdlog "log"
"net/http"
"os"
"strconv"
"strings"
"time"
"github.com/dollarshaveclub/acyl/pkg/ghapp"
"github.com/dollarshaveclub/acyl/pkg/ghclient"
nitroerrors "github.com/dollarshaveclub/acyl/pkg/nitro/errors"
"github.com/google/uuid"
"gi... |
package api
import (
"context"
"github.com/gremlinsapps/avocado_server/api/model"
"github.com/gremlinsapps/avocado_server/dal/model"
"github.com/gremlinsapps/avocado_server/dal/sql"
)
func (r *queryResolver) Ingredients(ctx context.Context, filter *apimodel.ResultsFilter) ([]apimodel.Ingredient, error) {
repo, e... |
/*
* @lc app=leetcode.cn id=1929 lang=golang
*
* [1929] 数组串联
*/
package main
// @lc code=start
func getConcatenation(nums []int) []int {
ret := make([]int, len(nums)*2)
for i := 0; i < len(nums); i++ {
ret[i] = nums[i]
ret[i+len(nums)] = ret[i]
}
return ret
}
// @lc code=end
|
// +build dcap
package main
/*
#cgo CFLAGS: -DRATLS_ECDSA=1
#cgo LDFLAGS: -L../build/lib -Llib -lra-tls-server -l:libcurl-wolfssl.a -l:libwolfssl.a -lsgx_uae_service -lsgx_urts -lz -lm
#cgo LDFLAGS: -lsgx_dcap_ql
extern int ra_tls_server_startup(int sockfd);
*/
import "C"
func ratlsServerStartup(fd uintptr) {
C.ra... |
package main
import (
"fmt"
"time"
)
func sendChan(ch chan<- int) {
count := 0
for count < 10 {
ch <- count
count++
}
}
func receiveChan(ch <-chan int) {
for {
fmt.Println(<-ch)
}
}
func main() {
ch := make(chan int, 1)
go sendChan(ch)
go receiveChan(ch)
time.Sleep(1e9)
}
|
package serializer
func EncodeWithZlib(v interface{}) ([]byte, error) {
data, err := json.Marshal(v)
if err != nil {
return nil, err
}
return Compress(data)
}
func DecodeWithZlib(data []byte, v interface{}) error {
decodedData, err := Decompress(data)
if err != nil {
return err
}
return json.Unmarshal(dec... |
package testrunner
import (
tmv1beta1 "github.com/gardener/test-infra/pkg/apis/testmachinery/v1beta1"
)
const (
AnnotationLandscape = "testrunner.testmachinery.sapcloud.io/landscape"
AnnotationK8sVersion = "testrunner.testmachinery.sapcloud.io/k8sVersion"
AnnotationCloudProvider = "testrunner.testmachinery... |
package main
import (
"image"
"math"
)
type scene struct {
objects []object
lights []light
fov float64
camera ray
}
func (s *scene) calculateCameraToWorld() {
}
// intersec returns object, point of intersection and its normale if ray intersects something
// if there is no intersection, then obj == nil
func (s... |
// Hot Data Status
package consts
|
package storage
import (
"fmt"
"strconv"
"sync"
"github.com/mauleyzaola/challenge/domain"
)
type Memory struct {
sync.Mutex
nextId int64
items map[string]interface{}
}
func (this *Memory) Init() {
this.nextId = 0
this.items = make(map[string]interface{})
}
func (this *Memory) List() []string {
this.Lock... |
package main
import "fmt"
func main() {
// n = 0
TestRoutine(0)
// สร้างการทำงานซ้อน ฟังก์ชัน TestRoutine(n int)
// สร้างตัวแปร input เก็บค่า string
var input string
fmt.Scanln(&input)
}
// Routine คือ ฟังก์ชันที่สามารถเรียกใช้งาน ฟังก์ชันอื่นได้ในขณะที่มีการทำงานอยู่
func TestRoutine(n int) {
// n คือ พารามิ... |
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
package helpers
import (
"encoding/json"
"strings"
"testing"
)
func TestKubernetesAllowedSizes(t *testing.T) {
sizes := GetKubernetesAllowedVMSKUs()
if len(sizes) == 0 {
t.Errorf("expected GetKubernetesAllowedVMSKU... |
package main
import "fmt"
func main() {
sum, n := 0, 0
for {
var idade int
fmt.Scanf("%d", &idade)
if idade < 0 {
break
}
sum += idade
n++
}
fmt.Printf("%.2f\n", float32(sum)/float32(n))
}
|
// Copyright 2018 Simon Pasquier
// 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 main
import (
"bufio"
b64 "encoding/base64"
"encoding/json"
"flag"
"fmt"
"log"
_ "net/http/pprof"
"os"
"strings"
"time"
"github.com/ckin-it/minedive/minedive"
)
var lineChan chan string
var bootstrap string
var mineClient *minedive.Client
var avoid []string
func init() {
lineChan = make(chan str... |
package cmd
import (
"fmt"
"github.com/juliabiro/expander/pkg/abbreviator"
"github.com/juliabiro/expander/pkg/utils"
"github.com/spf13/cobra"
)
var dryRun bool
var clear bool
func printOutput(data *utils.ExpanderData, configfile string) {
// format output
out := utils.MakeSortedString(data.GeneratedConfig)
... |
package main
import (
"context"
"flag"
"fmt"
pb "ziyun/auth-service/pb"
r "ziyun/auth-service/svc/client/http"
)
func main() {
flag.Parse()
ctx := context.Background()
authCli, _ := r.New("192.168.73.3:5150")
AToke := "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDEzODc0OTIsImlzcyI6IlN5c3RlbSIsIkNsaWVu... |
package main
import (
"encoding/base64"
"encoding/binary"
"fmt"
)
func main() {
var num int64 = 6285777273663
// convert int64 to []byte
buf := make([]byte, binary.MaxVarintLen64)
_ = binary.PutVarint(buf, num)
// convert []byte to int64
x, n := binary.Varint(buf)
fmt.Printf("x is: %v, %s, n is: %v\n", x, ... |
package main
import (
"math/rand"
"time"
)
type point struct {
x float64
y float64
bias float64
label int
}
func f(x float64) float64 {
return 3*x + 2
}
func newPoint() point {
src := rand.NewSource(time.Now().UnixNano())
r := rand.New(src)
p := point{
x: (r.Float64() * 20) - 10,
y: (r.Float6... |
package queue
import (
"github.com/carney520/go-algorithm/data-structure/list"
)
// Queue 表示队列类型
type Queue struct {
list *list.List
}
// Enqueue 插入队列
func (q *Queue) Enqueue(data interface{}) {
q.list.Append(data)
}
// Dequeue 出队列
func (q *Queue) Dequeue() interface{} {
head := q.list.Head()
if head != nil {
... |
package brawlstars
import (
"compress/gzip"
"encoding/json"
"errors"
"fmt"
"net/http"
"strconv"
"sync/atomic"
"time"
)
// BaseURL is the base API URL all requests go to
const BaseURL = "https://api.brawlapi.cf/v1/"
// New creates a new instance of a Brawl Stars client with an empty http.Client{}
func New(tok... |
package red_black_tree
import (
"fmt"
"math"
)
// 1. 每个节点都是红色或黑色
// 2. 根节点必须为黑色
// 3. 叶子节点必须为黑色
// 4. 双亲节点为红色时, 叶子节点必须为黑色
// 5. 任意根所有路径的黑色节点数量相同
type Node struct {
k int
v interface{}
color Color
parent, left, right *Node
}
type Color string
const Red Color = ... |
package apps
import (
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"testing"
)
type User struct {
ID uint `gorm:"primarykey"`
Email string `gorm:"uniqueIndex"`
FirstName string
}
// An app to manage users
type UserApp struct{}
func (a *UserApp) Name() string {
return "users"
}
func (a *UserApp) Migra... |
package accesscontrol
import (
"net/http"
"github.com/danielsomerfield/authful/server/service/oauth"
"github.com/danielsomerfield/authful/server/wire/authentication"
)
type ClientAccessControlFn func(request http.Request) (bool, error)
func NewClientAccessControlFn(clientLookup oauth.ClientLookupFn) ClientAccessC... |
package main
import (
"log"
"math/rand"
"os"
"strconv"
"time"
)
func SayGreetings(greeting string, times int) {
for i := 0; i < times; i++ {
log.Println(greeting + " " + strconv.Itoa(i))
dur := time.Second * time.Duration(rand.Intn(5)) / 2
time.Sleep(dur) // 睡眠片刻
}
}
func main() {
rand.Seed(time.Now().... |
package main
// Testing the new GitHub Desktop application
// Testing two
// Git Branch test
// Testing four five six
import "fmt"
var (
sum int = 0
)
func main() {
for i := 0; i < 1000; i++ {
if i%3 == 0 || i%5 == 0 {
sum = sum + i
}
}
fmt.Println(sum)
} |
package personages
import (
"core/positions"
)
type Personage struct {
Id int64
AccountId int64
Name string
PositionId int64
}
type PersonageResponse struct {
Id int64 `json:"id"`
Name string `json:"name"`
Position positions.Position `json:"position"`
}
type... |
package dcp
import (
"reflect"
"testing"
)
func Test_maxValueSubArray(t *testing.T) {
type args struct {
arr []int
k int
}
tests := []struct {
name string
args args
want []int
}{
{"1", args{arr: []int{10, 5, 2, 7, 8, 7}, k: 3}, []int{10, 7, 8, 8}},
{"2", args{arr: []int{1, 2, 3, 1, 4, 5, 2, 3, 6... |
package data
import (
"encoding/json"
"fmt"
"log"
"strconv"
"strings"
"time"
)
//关注专题
func SubjectFocus_(grbfs, ckege, uiksh string) string {
Mutex.Lock()
conn, err := Db.Begin()
if err != nil {
log.Println("事物开启失败")
Mutex.Unlock()
return SuccessFail_("0", "事物开启失败")
}
_, err = Db.Exec("insert into ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.