text stringlengths 11 4.05M |
|---|
package leetcode_go
import "math"
func judgeSquareSum(c int) bool {
l, r := 0, int(math.Sqrt(float64(c)))
var sum int
for l < r {
sum = l*l + r*r
if sum == c {
return true
} else if sum < c {
l++
} else {
r--
}
}
return false
}
|
/*
* Wire API
*
* Moov Wire implements an HTTP API for creating, parsing, and validating Fedwire messages.
*
* API version: v1
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package openapi
// ReceiptTimeStamp struct for ReceiptTimeStamp
type ReceiptTimeStamp struct {
// ReceiptDate is ... |
package main
import (
"fmt"
"strconv"
"strings"
)
func contains(slice []int64, n int64) bool {
for _, num := range slice {
if num == n {
return true
}
}
return false
}
func DuplicateFrequencyFinder() {
fmt.Println("-----------------------------")
inputs := strings.Split(GetFileAsString("input.txt"), "... |
package extractors
import (
"database/sql"
"log"
"github.com/bmeg/sifter/config"
"github.com/bmeg/sifter/evaluate"
"github.com/bmeg/sifter/task"
_ "github.com/mattn/go-sqlite3" // Adding sqlite3 to the SQL driver list
)
type SQLiteStep struct {
Input string `json:"input" jsonschema_description:"Path to the SQ... |
// Copyright (C) 2020 Storj Labs, Inc.
// See LICENSE for copying information.
// Package peertls manages TLS configuration for peers.
package peertls
|
// Package flag extends the basic flag behavior provided by Go.
package flag
|
package opt
import (
"cgon/master/app"
"cgon/master/common/status"
"github.com/gin-gonic/gin"
)
func Online(ctx *gin.Context) {
c := app.AppContext{Context: ctx}
c.Resp(status.SUCCESS, status.HEART_PACKAGE, nil)
}
|
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package storj
import (
"fmt"
"net/url"
"strconv"
"strings"
"github.com/zeebo/errs"
"storj.io/common/base58"
)
var (
// ErrNodeURL is used when something goes wrong with a node url.
ErrNodeURL = errs.Class("node URL")
)
// NodeU... |
package main
import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"net/http/httputil"
"os"
"regexp"
"strconv"
"time"
"github.com/gorilla/context"
"github.com/gorilla/handlers"
"github.com/gorilla/sessions"
"github.com/justinas/alice"
"github.com/valeriugold/vket/app/shared/databa... |
package main
import (
"context"
"fmt"
gd "github.com/brotherlogic/godiscogs"
pbrc "github.com/brotherlogic/recordcollection/proto"
)
func listUncategorized(ctx context.Context, client pbrc.RecordCollectionServiceClient) error {
releases, err := client.GetRecords(ctx, &pbrc.GetRecordsRequest{Filter: &pbrc.Recor... |
package controllers
import (
"github.com/astaxie/beego"
"fmt"
"opscenter/models"
)
type LoginController struct {
beego.Controller
}
func (index *LoginController) Get() {
index.TplName = "login.tpl"
}
func (index *LoginController) Post() {
var user models.Users
inputs := index.Input()
user.Username = inputs... |
package store
import (
"time"
"github.com/pkg/errors"
)
const (
JobQueued = "QUEUED"
JobRunning = "RUNNING"
JobFailure = "FAILURE"
JobSuccess = "SUCCESS"
TriggerManual = "MANUAL"
TriggerSchedule = "SCHEDULE"
)
type Job struct {
Id int `json:"id"`
SourceId int `json:"sourceId"`
Ini... |
// Copyright 2018 Erik Adelbert. All right reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ignore
package main
import "golang.org/x/tour/reader"
type MyReader struct{}
// MyReader.Read returns an infinite stream of 'A'.
// It does so len(b... |
package controllers
import (
"encoding/json"
"fmt"
"github.com/astaxie/beego"
"github.com/astaxie/beego/cache"
"github.com/astaxie/beego/logs"
"github.com/axgle/mahonia"
"github.com/hashicorp/consul/api"
"hello/common"
"net"
"os"
"strconv"
)
type TcpControllers struct {
beego.Controller
}
var Urlcache ca... |
// Copyright 2014 Dirk Jablonowski. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package device
import (
"fmt"
"github.com/dirkjabl/bricker/net/packet"
)
// Type for callback period.
type Period struct {
Value uint32
}
// FromPacket ... |
package civsession
import (
"strings"
"github.com/bwmarrin/discordgo"
"github.com/ecshreve/civ-bot-go/internal/util"
)
// CommandsHandler handles all civ-bot commands.
func (cs *CivSession) CommandsHandler(s *discordgo.Session, m *discordgo.MessageCreate) {
// Ignore all messages created by the bot itself.
if m... |
package cli
type OperatorSdkScorecardOptions struct {
LogLevel string
OutputFormat string
Selector []string
ResultFile string
Kubeconfig string
Namespace string
ServiceAccount string
}
type OperatorSdkScorecardReport struct {
Stdout string
Stderr string
Items []OperatorSdkScoreca... |
package problems
// https://leetcode.com/problems/apply-discount-every-n-orders/
type Cashier struct {
threshold int
ordersProcessed int
discount int
products []int
prices []int
}
func Constructor(n int, discount int, products []int, prices []int) Cashier {
return Cashier{
thresho... |
// Copyright 2019 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package cca provides utilities to interact with Chrome Camera App.
package cca
import (
"context"
"encoding/json"
"fmt"
"image/jpeg"
"io/ioutil"
"os"
"path/filepat... |
package controllers
import (
"fmt"
"io"
"os"
"path/filepath"
"github.com/dchest/captcha"
"github.com/itang/gotang"
gio "github.com/itang/gotang/io"
"github.com/itang/yunshang/main/app/models/entity"
"github.com/itang/yunshang/main/app/routes"
"github.com/itang/yunshang/main/app/utils"
"github.com/lunny/xor... |
package main
/*
Functions for reading the contents of the Git object database.
Git has three kinds of object: Commits, Blobs (files) and Trees (directories).
They are stored one-per-file under .git/objects, and each one is compressed
with zlib.
All Git objects have a header and a content section.... |
package code
import (
"encoding/binary"
"io"
"github.com/pgavlin/warp/wasm/leb128"
)
func encodeBlockType(w io.Writer, instr Instruction) error {
// Check for special block types.
if instr.Immediate&0x8000000000000000 != 0 {
_, err := w.Write([]byte{byte(instr.Immediate)})
return err
}
_, err := leb128.W... |
package main
import (
"fmt"
"os"
"os/signal"
"github.com/Sirupsen/logrus"
"github.com/braintree/manners"
"github.com/kardianos/osext"
"github.com/Hobsons/eremetic/database"
"github.com/Hobsons/eremetic/routes"
"github.com/Hobsons/eremetic/scheduler"
"github.com/prometheus/client_golang/prometheus"
"github.... |
package main
import "fmt"
func main() {
// numbers := []int{1, 2, 10, 3}
numbers := []int{1, 2, 3, 10, 54, 36, 8, 15, 7, 30, 5}
fmt.Println(maxNum(numbers))
}
func maxNum(numbers []int) int {
// base case
if len(numbers) == 2 {
if numbers[0] > numbers[1] {
return numbers[0]
}
return numbers[1]
}
// ... |
// Copyright 2014 Mark Wolfe. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package buildkite
import (
"encoding/base64"
"fmt"
"net/http"
"time"
)
// TokenAuthTransport manages injection of the API token for each request
type Token... |
package commands
import (
"flag"
"fmt"
"net/rpc"
)
// MemberDemoteCommand satisfies the Command interface for demoting a node
type MemberDemoteCommand struct{}
// Help prints detailed help text for the member demote command
func (c *MemberDemoteCommand) Help() {
fmt.Printf(`
Description:
Advises a node to 'dem... |
package main
import "rabbitmqdemoProject/model"
func main(){
model.QueryCap(2001,3002)
model.UpdateCap(2001,3002,5000)
} |
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//
package model_test
import (
"bytes"
"fmt"
"testing"
"time"
"github.com/mattermost/mattermost-operator/apis/mattermost/v1alpha1"
"github.com/mattermost/mattermost-cloud/model"
"github.com/stretch... |
package model
import (
"encoding/json"
"time"
"github.com/caos/logging"
"github.com/caos/zitadel/internal/crypto"
caos_errs "github.com/caos/zitadel/internal/errors"
es_models "github.com/caos/zitadel/internal/eventstore/models"
"github.com/caos/zitadel/internal/user/model"
)
const (
UserVersion = "v1"
)
ty... |
package main
func main() {
// base commands
// base()
// structures
// structures()
// interfaces
// interfaces()
// multithreading
// multithreading()
// multithreading select
// using_select()
// multithreading buffer
// using_buffer()
// packages
// fmt.Println(m.Stat([]float64{2, 5, 4}, []floa... |
package main
import (
// "bytes"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/czerwe/gobravia"
"github.com/gorilla/mux"
"github.com/jessevdk/go-flags"
"html/template"
"net/http"
"os"
// "strings"
)
type Options struct {
Listenport int `long:"listenport" env:"LISTENPORT" default:"4043" description... |
package leetcode_go
import (
"math"
)
func findCheapestPrice(n int, flights [][]int, src int, dst int, K int) int {
q := [][]int{[]int{src, 0}}
step := 0
m := make(map[int][][]int)
for _, flight := range flights {
m[flight[0]] = append(m[flight[0]], []int{flight[1], flight[2]})
}
res := math.MaxInt32
var cu... |
package File_IO
func Testwww() {
}
|
package utils
// 对 userAgent 的解析,解析出 浏览器-系统-版本号
func GetUserAgent(userAgentFromHeader string) string {
return "Ubuntu 18.04 上的 Chrome 71.0 浏览器"
}
|
/*
Copyright 2022 Gravitational, 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 writing, soft... |
package protocol
import (
"bufio"
"bytes"
"errors"
"github.com/zeebo/bencode"
"io"
"io/ioutil"
"log"
"net"
"sync"
"time"
"github.com/jech/storrent/config"
"github.com/jech/storrent/pex"
)
var ErrParse = errors.New("parse error")
var pool sync.Pool = sync.Pool{
New: func() interface{} {
return make([]... |
package model
import (
"gamesvr/manager"
"shared/utility/errors"
)
// 入参id为cons_action_id_type.go中各个模块对应的ActionIdType
func (u *User) CheckActionUnlock(id int32) error {
unlockConditions, err := manager.CSV.ActionUnlock.GetUnlockConditions(id)
if err != nil {
return errors.WrapTrace(err)
}
err = u.CheckUserCo... |
package main
import (
"bytes"
// "fmt"
"io"
"net"
"net/http"
"log"
"time"
)
func main() {
hostname := "vps.monkey.id.au"
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds)
request, err := http.NewRequest("GET", "http://"+hostname+"/info.php", nil)
request.Header.Set("C... |
package database
import (
"context"
"database/sql"
"errors"
"fmt"
"github.com/tahmooress/motor-shop/internal/entities/models"
)
func (m *Mysql) GetAdminByID(ctx context.Context, adminID models.ID) (*models.Admin, error) {
stmt, err := m.db.PrepareContext(ctx, "SELECT id,user_name,password,created_at,updated_at ... |
// Copyright 2020 Copyright (c) 2020 SAP SE or an SAP affiliate company. All rights reserved. This file is licensed under the Apache Software License, v. 2 except as noted otherwise in the LICENSE file.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in complian... |
package encryption
import (
"crypto/rand"
g "github.com/billy4479/file-encrypter/global"
"github.com/nicholastoddsmith/aesrw"
)
func makeAES(data *encryptionData) (err error) {
data.salt = make([]byte, g.SaltLength)
_, err = rand.Reader.Read(data.salt)
if err != nil {
return
}
data.hash = g.MakeHash([]byte... |
package server
import (
"errors"
"github.com/id_gen/config"
"sync"
"time"
)
//type Code int64
func getCurrenMills() int64 {
return time.Now().UnixNano() / 1000
}
var (
twepoch int64 = getCurrenMills()
)
const (
workerIdBits int64 = 5 /** machine id */
datacenterIdBits int64 = 5 /**datacenter id*/
m... |
package models
import "time"
type UserModel struct {
ID uint `gorm:"primaryKey" json:"id"`
WorkArea string `json:"work_area"`
UserName string `json:"user_name"`
UserDesignationID int `json:"user_designation_id"`
Team string `json:"team"`
PushKey ... |
// SPDX-License-Identifier: ISC
// Copyright (c) 2014-2020 Bitmark Inc.
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package rpccalls
import (
"golang.org/x/crypto/ed25519"
"github.com/bitmark-inc/bitmarkd/command/bitmark-cli/configuration"
"github.com/bitmark... |
package main
import (
"fmt"
)
func main() {
qashwaLoop: // Nama label dapat diganti dengan nama lain (contoh: outerLoop) dan harus diakhiri dengan tanda titik dua ( : )
for i := 0; i < 5; i++ {
for j := 0; j < 5; j++ {
if i == 3 {
break qashwaLoop
}
fmt.Print("matriks [", i, "][", j, "]", "\n")
}
... |
package osdconfig
import (
"context"
"encoding/json"
"errors"
"path/filepath"
"time"
"github.com/Sirupsen/logrus"
)
// watch starts a watch on kvdb.
// it listens on a channel forever as long as context is alive
func (manager *configManager) watch(c <-chan *DataWrite) {
// watch lock guarantees only one watch... |
package column
import (
"unsafe"
)
type tuple3Value[T1, T2, T3 any] struct {
Col1 T1
Col2 T2
Col3 T3
}
// Tuple3 is a column of Tuple(T1, T2, T3) ClickHouse data type
type Tuple3[T ~struct {
Col1 T1
Col2 T2
Col3 T3
}, T1, T2, T3 any] struct {
Tuple
col1 Column[T1]
col2 Column[T2]
col3 Column[T3]
}
// New... |
package main
import (
"net/http"
"github.com/G-Node/gin-repo/auth"
"github.com/G-Node/gin-repo/store"
)
func (s *Server) checkAccess(w http.ResponseWriter, r *http.Request, rid store.RepoId, want store.AccessLevel) (*store.User, bool) {
user, err := s.users.UserForRequest(r)
if err != nil && err != auth.ErrNo... |
package utils
import (
"fmt"
"os"
"reflect"
"regexp"
"strconv"
)
// Invoke (fn interface{}, args ...interface{}) interface{}
func Invoke(fn interface{}, args ...interface{}) interface{} {
v := reflect.ValueOf(fn)
rargs := make([]reflect.Value, len(args))
for i, a := range args {
rargs[i] = reflect.ValueOf(a... |
package model
type Library struct {
ID int64 `json:"id" db:"ID"`
Name string `json:"name" db:"NAME"`
Root string `json:"root" db:"ROOT"`
}
|
package functions
import (
"bufio"
"log"
"os"
"regexp"
"sort"
"strings"
)
/*
1) Функция ReadFromFile() – получая в качестве аргумента имя файла, читает текст из него текст,
переводя его в срез типа string и возвращает полученный результат.
*/
func ReadFromFile(fileName string) (stringMassive []string) {
file,... |
package awsutil
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/aws/credentials/stscreds"
"github.com/aws/aws-sdk-go/aws/defaults"
"github.com/aws/aws-sdk-go/aws/endpoints"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/pganalyze/collector/con... |
package main
import (
"fmt"
"reflect"
//↑reflect型の宣言
)
func main() {
num01 := 123
var num02 int = 1234567890
num03 := 1.23
var num04 float64 = 1.23456789
fmt.Println(reflect.TypeOf(num01))
fmt.Println(reflect.TypeOf(num02))
fmt.Println(reflect.TypeOf(num03))
fmt.Println(reflect.TypeOf(num04))
}
/... |
package main
import (
"fmt"
"gopkg.in/gin-gonic/gin.v1"
"gopkg.in/mgo.v2"
"log"
"net/http"
"time"
"sync"
)
type Rsvp struct {
Name string `json: "name"`
NumGuests int `json: "numGuests"`
IsAttending bool `json: "isAttending"`
WeddingCode string `json: "weddingCode"`
RequestedSongs string `json: "requested... |
package gaoxiaojob
import "time"
type Job struct {
URL string
Title string
Meta map[string]string
// 分类
Categories []string
// 需求学科
Subjects []string
// 所属省份
Provinces []string
// 工作地点
Locations []string
// 发布时间
PublishedAt *time.Time
// 截止日期
ExpireAt *time.Time
Body string
}
|
package handlers
import (
"github.com/labstack/echo"
"go-fitness/api"
"net/http"
)
func Category(service *api.Service) echo.HandlerFunc {
return func(c echo.Context) error {
schema, err := service.CategorySchema()
if err != nil {
return c.JSON(http.StatusInternalServerError, nil)
}
result := service.Ex... |
//
// Copyright (c) SAS Institute Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agre... |
// Copyright 2014 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, ... |
package httprequest
import (
"bytes"
"io/ioutil"
"net/http"
"syncAgent-go/syncAgent/params"
)
//Get GET syncthing srv获取随机folderID
/*
url 地址
*/
func Get(url string) ([]byte, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err //log
}
req.Header.Add("Content-Type", "applicati... |
// 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 contract
import "github.com/xuperchain/xupercore/kernel/contract/bridge/pb"
type KernRegistry interface {
RegisterKernMethod(contract, method string, handler KernMethod)
// RegisterShortcut 用于contractName缺失的时候选择哪个合约名字和合约方法来执行对应的kernel合约
RegisterShortcut(oldmethod, contract, method string)
GetKernM... |
package main
import (
"fmt"
"log"
"os"
"regexp"
"strconv"
)
var numberRegex = regexp.MustCompile(`^\d+$`)
func main() {
filename := os.Args[1]
parser, err := NewParser(filename)
if err != nil {
log.Fatal(err)
}
// Add label to symbolTable
symbolTable := NewSymbolTable()
romAddr := 0
for parser.HasMor... |
package mongodb
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"strconv"
"time"
"yes-blog/internal/model/post"
"yes-blog/internal/model/user"
"yes-blog/pkg/database/DBException"
)
type PostMongoDriver struct {
collection... |
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package firmware
import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
gossh "golang.org/x/crypto/ssh"
"google.g... |
package types
import (
"fmt"
"strconv"
"subc/ast"
"subc/constant"
"subc/scan"
)
// ident type checks an identifier.
func (c *checker) ident(x *operand, e *ast.Ident, silent bool) {
x.mode = invalid
x.expr = e
_, obj := c.scope.LookupParent(Ord, e.Name, scan.NoPos)
if obj == nil {
_, obj = c.scope.LookupP... |
package NodeList
type ListNode struct {
Val int
Next *ListNode
}
//循环
func reverseList(head *ListNode) *ListNode {
var pre *ListNode
next := new(ListNode)
for head != nil {
next = head.Next
head.Next = pre
pre = head
head = next
}
return pre
}
|
package abstractions
import (
"reflect"
"testing"
)
func TestSort(t *testing.T) {
tests := []struct {
in, o []int
f func(int, int) bool
}{
{nil, nil, nil},
{[]int{1, 2, 3}, []int{3, 2, 1}, func(a, b int) bool { return a < b }},
{[]int{3, 2, 1}, []int{1, 2, 3}, func(a, b int) bool { return a > b }},
... |
package e4
const (
flagStacktraceIncluded = 1 << iota
)
|
package msg
type MsgInfo struct {
From uint64
To uint64
Content string
}
|
package user
type ValidateUser struct {
ID int `json:"id" binding:"required"`
Name string `json:"name" binding:"required"`
Email string `json:"email" binding:"required"`
AvatarUrl string `json:"avatar_url" binding:"required"`
} |
// Copyright 2023 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... |
package psutil
import (
"syscall"
"unsafe"
)
const PROCESS_ALL_ACCESS = 0x1F0FFF
var (
kernel32 = syscall.NewLazyDLL("kernel32")
procGetProcessId = kernel32.NewProc("GetProcessId")
)
func killTree(ph syscall.Handle, code uint32) error {
var pe syscall.ProcessEntry32
pid, _, _ := procGetProcessId.Call(... |
// Copyright 2021 EricWinn
// Author: Eric Winn
// Email: eng.eric.winn@gmail.com
// Time: 2021/10/11 17:11
// File: modal.py
// Software: GoLand
package model
|
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"os"
)
type AutoGenerated struct {
Nodes []struct {
Node struct {
Name string `json:"name"`
INDICATION string `json:"INDICATION"`
TermDescription string `json:"Term description"`
Q01CAT string `json:"Q01_CAT... |
package oauth2
import (
"log"
"github.com/dgrijalva/jwt-go"
"github.com/uchupx/oauth2-mongo-learn/config"
// "gopkg.in/oauth2.v3"
"gopkg.in/oauth2.v3/errors"
"gopkg.in/oauth2.v3/generates"
"gopkg.in/oauth2.v3/manage"
"gopkg.in/oauth2.v3/server"
)
func CreateServe(conf *config.Config) *server.Server {
mong... |
package main
import (
"github.com/faiface/pixel"
"github.com/faiface/pixel/imdraw"
"github.com/faiface/pixel/pixelgl"
"golang.org/x/image/colornames"
)
type scene struct {
winW, winH int
quad *Quadtree
isMousePressed bool
}
func (s *scene) run() {
cfg := pixelgl.WindowConfig{
Title: "Pixel R... |
package main
import (
"fmt"
"math"
"sort"
)
func main() {
nums := []int{-1, 2, 1, -4}
target := 1
fmt.Println(threeSumClosest(nums, target))
}
func threeSumClosest(nums []int, target int) int {
// 升序
sort.Ints(nums)
result := math.MaxInt64
// 固定第一个数
for first := range nums {
// 跳过重复的数
if first > 0 && ... |
package prime
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestFactors1(t *testing.T) {
expected := []int(nil)
assert.Equal(t, expected, GetPrimeFactors(1))
}
func TestFactors2(t *testing.T) {
expected := []int{2}
assert.Equal(t, expected, GetPrimeFactors(2))
}
func TestFactors3(t *testing.... |
package main
func main() {
var x int
x = x >>= 3
}
|
package commands
import (
"os"
"strings"
"github.com/nlopes/slack"
)
var raspberryPIIP = os.Getenv("raspberryPIIP")
var rtm *slack.RTM
var piSDCardPath = "/home/pi/torrents/"
var piUSBMountPath = "/mnt/usb_1/DLNA/torrents/"
// SlackReportChannel default reporting channel for bot crons
var SlackReportChannel = os... |
package model
import (
"errors"
"fmt"
"log"
"sort"
"strconv"
)
var (
InvalidCard = Card{}
)
func NewCardFromString(card string) Card {
c, err := NewCardFromExternalString(card)
if err != nil {
log.Printf(`dev error: NewCardFromString invalid card (%q): %s`, card, err.Error())
}
return c
}
// NewCardFrom... |
package admin
import (
"coinford_admin_api/admin_models"
"coinford_admin_api/admin_configs"
"fmt"
"github.com/dgrijalva/jwt-go"
"time"
"errors"
)
func apiAuthenticateAdmin(tokenString string) (CommonResponse, *admin_models.Admin, *admin_models.AdminGroup, bool, error) {
err := parseAdminToken(tokenString)
if ... |
package curl
import (
"errors"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"
)
type (
Request struct {
URL string
URI string
Method string
Headers map[string]string
Params url.Values
Json interface{}
IsJson bool
Byte []byte `json:"-"`
ByteStr string
IsByte bo... |
package validate
type Validator struct {
e Errors
}
func (v *Validator) Add(err Error) {
if v.e == nil {
v.e = make(Errors)
}
v.e.Add(err)
}
func (v *Validator) Presence(attr string, value string) *PresenceError {
verr := Presence(attr, value)
if verr != nil {
v.Add(verr)
}
return verr
}
func (v *Vali... |
package main
// Implements a server that tails Graphite's logs
// finds out when new data sources become available
// and serves out a UI that lets you see/render those
// continuously.
// Written by J.A. Oldenbeuving / ojilles@gmail.com
import (
"encoding/json"
"flag"
"fmt"
"github.com/ActiveState/tail"
"githu... |
package git
import (
"fmt"
"github.com/bmsandoval/kubester/bash"
kube_svc "github.com/bmsandoval/kubester/services/input_svc"
"github.com/bmsandoval/kubester/utils"
"github.com/spf13/cobra"
"log"
"os/exec"
)
var ResetAllCmd = &cobra.Command{
Use: "reset_all",
Aliases: []string{"ra"},
Short: "reset cur... |
package main
//134. 加油站
//在一条环路上有N个加油站,其中第i个加油站有汽油gas[i]升。
//
//你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1个加油站需要消耗汽油cost[i]升。你从其中的一个加油站出发,开始时油箱为空。
//
//如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。
//
//说明:
//
//如果题目有解,该答案即为唯一答案。
//输入数组均为非空数组,且长度相同。
//输入数组中的元素均为非负数。
func canCompleteCircuit(gas []int, cost []int) int {
n := len(gas)
resu... |
// Copyright 2017 The Cockroach Authors.
//
// Licensed as a CockroachDB Enterprise file under the Cockroach Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/cockroachdb/cockroach/blob/master/li... |
package ga
import "testing"
func TestExtractElite(t *testing.T) {
tests := []struct {
in *Generation
n int
perf Performance
outElite *Generation
outRem *Generation
}{
{
&Generation{generation{
&TestCM{0x1, 0x1, 0x1, 0x0},
&TestCM{0x1, 0x0, 0x0, 0x0},
&TestCM{0x1, 0x1, 0... |
// Copyright 2019 The gVisor Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agree... |
package main
import (
"encoding/json"
"flag"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"runtime"
"time"
"github.com/boltdb/bolt"
"github.com/golang/glog"
"github.com/gorilla/mux"
"github.com/spf13/pflag"
"github.com/urfave/negroni"
gitapi "kolihub.io/koli/pkg/git/api"
"kolihub.io/koli/pkg/git/conf"
... |
package main
import (
"fmt"
"time"
)
func sample1(message chan string) {
message <- "Hello world.1"
message <- "Hello world.2"
message <- "Hello world.3"
message <- "Hello world.4"
}
func sample2(message chan string) {
//time.Sleep(2*time.Second)
str := <-message
str = str + "I'm go routine"
message <- st... |
// Copyright 2020 The Cockroach Authors.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt.
//
// As of the Change Date specified in that file, in accordance with
// the Business Source License, use of this software will be governed
// by the Apache License, ... |
package server
import (
"sync"
)
// Cable - TODO
type Cable struct {
Scope string
Owner string `default:"test"`
Connected bool
Authorized bool
Stats Stats
spaceSignal SpaceSignal
ufoSignal UfoSignal
sync.Mutex
pool ProxyPackMap
}
|
package utils
import (
"log"
"net"
"github.com/Iteam1337/go-protobuf-wejay/types"
"github.com/golang/protobuf/proto"
)
func send(msg []byte, conn *net.UDPConn, addr *net.UDPAddr) (err error) {
if _, err = conn.WriteToUDP([]byte(msg), addr); err != nil {
log.Println(err)
}
return
}
func Send(m types.Messag... |
package main
import (
"errors"
"fmt"
)
//Set is struct of implements sets in go.
type Set struct {
Elements map[string]struct{}
}
//NewSet return isntance of Set.
func NewSet() *Set {
var set Set
set.Elements = make(map[string]struct{})
return &set
}
//Add is responsable by add elements.
func (s *Set) Add(ele... |
package webgl3d
type Lighting struct {
}
func NewLighting() *Lighting {
var lighting Lighting
return &lighting
}
|
package myreplication
//http://dev.mysql.com/doc/internals/en/capability-flags.html
const (
_CLIENT_LONG_PASSWORD uint32 = 0x00000001
_CLIENT_FOUND_ROWS uint32 = 0x00000002
_CLIENT_LONG_FLAG uint32 = 0x00000004
_CLIENT_CONNECT_WITH_DB uint32 ... |
package checkclient
import (
"os"
"testing"
"time"
"github.com/kuberhealthy/kuberhealthy/v2/pkg/checks/external"
)
// TestGetKuberhealthyURL ensures that KH_REPORTING_URL env var can be fetched
func TestGetKuberhealthyURL(t *testing.T) {
var testCases = []struct {
input string
err string
}{
{"http://k... |
package Tools
import (
"fmt"
"net/url"
"testing"
)
var v = url.Values{"a": []string{"a1", "a2"}, "b": []string{"b1", "b2"}}
func TestMakeStr(t *testing.T) {
fmt.Println(MakeStr(v))
//a=a1&a=a2&b=b1&b=b2
}
func TestMakeStr2(t *testing.T) {
fmt.Println(MakeStr2(v))
//a=a1a=a2b=b1b=b2
}
func TestMakeStr3(t *te... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.