text stringlengths 11 4.05M |
|---|
package mychannel
import (
"fmt"
"testing"
"time"
)
func pass(left, right chan int){
left <- 1 + <- right
}
func TestMyChannel(t *testing.T) {
const n = 50
leftmost := make(chan int)
right := leftmost
left := leftmost
for i := 0; i< n; i++ {
right = make(chan int)
// the chain is constructed from the ... |
package main
import (
"fmt"
. "leetcode"
)
func main() {
fmt.Println(deleteNode(NewListNode(4, 5, 1, 9), 4))
fmt.Println(deleteNode(NewListNode(4, 5, 1, 9), 5))
fmt.Println(deleteNode(NewListNode(4, 5, 1, 9), 1))
// 4 -> 5 -> 1 -> 9
}
/**
* Definition for singly-linked list.
* type ListNode struct {
* ... |
// Package gitlab - user
package gitlab
import (
"context"
"encoding/json"
"fmt"
"sync"
)
// User entity
type User struct {
ID int `json:"id"`
Name string `json:"name"`
UserName string `json:"username"`
PublicEmail string `json:"public_email"`
}
func getUsersByIDs(parentCtx context.Cont... |
package mosquito
import (
"net/http"
)
type Request struct {
*http.Request
Params map[string]string
}
|
package historian
import (
"errors"
"github.com/fuserobotics/historian/dbproto"
"github.com/fuserobotics/reporter/remote"
"github.com/fuserobotics/statestream"
r "gopkg.in/dancannon/gorethink.v2"
)
const streamTableName string = "streams"
// Wrapper for response from RethinkDB with stream change
type streamChan... |
package memrepo
import (
"sort"
"github.com/scjalliance/drivestream"
"github.com/scjalliance/drivestream/resource"
)
var _ drivestream.DriveMap = (*Drives)(nil)
// Drives accesses a map of drives in an in-memory repository.
type Drives struct {
repo *Repository
}
// List returns the list of drives contained wi... |
package pair
import (
"github.com/hnnyzyf/go-stl/container/value"
)
type Pair interface {
value.Value
GetKey() interface{}
GetValue() interface{}
}
//The Pair could be string,interge,float,pointers and so on,we implement some Pair we always use
//String Pair
type StringPair struct {
Key string
Val interface{}... |
package main
import "fmt"
const idx_max = 500
type barang_mentah struct {
nama string
berat float64
harga int
barang_hasil string
}
type barang_jadi struct {
nama string
berat float64
harga int
asal_barang string
}
func main() {
var array_mentah [idx_max]barang_ment... |
// 24. Create the MT19937 stream cipher and break it
package main
import (
"bytes"
"crypto/cipher"
"errors"
"fmt"
"os"
"time"
)
const (
arraySize = 624
offset = 397
multiplier = 1812433253
upperMask = 0x80000000
lowerMask = 0x7fffffff
coefficient = 0x9908b0df
temperMask1 = 0x9d2c5680
temper... |
package pojo
import (
pojo2 "tesou.io/platform/brush-parent/brush-api/module/analy/pojo"
)
/**
发布记录
*/
type SuggStub struct {
pojo2.AnalyResult `xorm:"extends"`
}
|
package framework
import (
"time"
"github.com/gin-gonic/gin"
"github.com/appleboy/gin-jwt"
"strings"
userService "cms/service/user"
)
func getAuthMiddleware() *jwt.GinJWTMiddleware {
authMiddleware := &jwt.GinJWTMiddleware{
Realm: "UserRealm",
Key: []byte("hjTSdjskiTOWJWRsjfskfjlkowqj8j23LQj"),... |
package libraries
import (
"bufio"
"encoding/json"
"log"
"net/http"
"os"
"strings"
)
/*
Send the Vault Token and retrieve the secret from the specified path
Data can be pulled from data.file
*/
func GetSecret(x_vault_token string) map[string]interface{}{
path := GetData("secretpath")
env := GetConfig... |
/*
Copyright 2020 Humio https://humio.com
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, ... |
package main
import "fmt"
type Student struct {
name string
age int
}
func (s Student) changeName(newName string) {
s.name = newName
}
func (s *Student) changeAge(newAge int) {
s.age = newAge
}
func main() {
std1 := Student{"Bob", 21}
fmt.Println("New Student:", std1)
std1.changeName("Bobby")
std1.changeA... |
package handler
import (
"context"
api "github.com/aibotsoft/gen/pinapi"
"github.com/pkg/errors"
"time"
)
const CurrencyJobPeriod = time.Hour
func (h *Handler) CurrencyJob() {
for {
start := time.Now()
if !h.NetStatus {
h.log.Info("netStatus_not_ok")
time.Sleep(time.Minute)
continue
}
ctx, canc... |
// Package numeral provides the ability to create custom positional numeral
// systems in an efficient and performant way. You can create numerals based
// on custom numeral systems and use them at will.
//
//
// Each digit represented as a circular list that contains the all the possible numeral.
//
// Each number is ... |
package model_test
import (
"github.com/igogorek/http-rest-api-go/internal/app/model"
"github.com/stretchr/testify/assert"
"strings"
"testing"
)
func TestUser_Validate(t *testing.T) {
testCases := []struct {
name string
prepareUser func() *model.User
isValid bool
}{
{
name: "valid",
pre... |
/**
一定要记得在confin.json配置这个模块的参数,否则无法使用
*/
package login
import (
"fmt"
"github.com/dming/lodos/conf"
"github.com/dming/lodos/gate"
"github.com/dming/lodos/module"
"github.com/dming/lodos/module/base"
"github.com/dming/lodos/log"
"github.com/go-redis/redis"
"github.com/dming/lodos/utils/uuid"
)
var Module = fun... |
package main
import (
"fmt"
)
func fib(n uint) uint {
if n < 2 {
return n
}
return fib(n-2) + fib(n-1)
}
func main() {
for i := uint(1); i <= 10; i++ {
fmt.Printf("i=%d\t%d\n", i, fib(i))
}
// stack overflow
//fmt.Println(fib(10000000000000000))
}
|
// 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 main
import (
"fmt"
"os"
"testing"
"time"
)
// The benchmark function must run the target code b.N times.
// During benchmark execution, b.N is adjusted until the benchmark function lasts long enough to be timed reliably.
// allocs/op means how many distinct memory allocations occurred per op (single iter... |
// Copyright (C) 2019 Cisco Systems Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agr... |
package main
import "fmt"
func half(number int) (int, bool) {
return number / 2, number%2 == 0
}
func main() {
fmt.Print("half(1) returns ")
fmt.Println(half(1))
fmt.Print("half(2) returns ")
fmt.Println(half(2))
h, even := half(5)
fmt.Println(h, even)
}
|
/*
Run code from given body information such as
body.stdIn, body.code, body.language, etc.
*/
package main
import (
"fmt"
"io"
"io/ioutil"
"os/exec"
)
// path to /tmp/ folder and its files' names
const (
scripts = "scripts"
codeFile = "tmp/code"
)
// write body.code to /tmp/code.<<language extension>> ... |
package websock
import(
"fmt"
"net/http"
"github.com/henrylee2cn/pholcus/common/websocket"
)
type SockServer struct{
client *websocket.Conn
data chan([]byte)
}
var (
Server = NewServer()
)
func NewServer() *SockServer{
return &SockServer{
data :make(chan []byte),
}
}
func Start() {
http.Handle("/sock", ... |
package nkb
import (
"strconv"
"os/exec"
"fmt"
"strings"
)
func (a *app) enable() {
a.start("" +
"setkeycodes 3a " + strconv.Itoa(KEY_0) + " &" + // capslock
"wait")
}
func (a *app) disable() {
a.start("" +
"setkeycodes 3a 58 &" + // capslock
"wait")
}
func (a *app) capsModeOn() {
a.state.capsMode = ... |
/*
So, I wrote myself a one-liner which printed out a snake on the console. It's a bit of fun, and I wondered how I might condense my code...
Here's a (short) example output:
+
+
+
+
+
+
+
... |
package jsonapi
import (
"encoding/json"
)
type LinkDescriptor struct {
Href URLTemplate `json:"href"`
Type string `json:"type"`
}
func (ld *LinkDescriptor) UnmarshalJSON(data []byte) error {
// assume they gave us a full link descriptor object
var dst struct {
Href URLTemplate `json:"href"`
Type stri... |
package main
import (
"fmt"
"time"
)
// The function will return if a message arrival interval
// is larger than one minute.
func longRunning(messages <-chan string) {
for {
select {
// 会产生大量 chan 滞留在内存
case <-time.After(time.Minute):
return
case msg := <-messages:
fmt.Println(msg)
}
}
}
func mai... |
package main
import (
"encoding/json"
"fmt"
"github.com/codegangsta/negroni"
"html/template"
"io"
"net/http"
"net/url"
"nlc_dv/marc"
"nlc_dv/search"
"os"
"reflect"
"sort"
"strconv"
"flag"
)
var flagSkip int
var flagUtf8 bool
var ds *DataStore
type Doc struct {
Id int
Year int `json:"year"... |
package main
import (
"fmt"
"net/http"
)
func Handle_NAME(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "anu!!!!!!!!!")
}
func main() {
http.HandleFunc("/", Handle_NAME)
http.ListenAndServe(":80", nil)
}
|
package persist
type IQuery interface {
}
|
/*
* Tencent is pleased to support the open source community by making 蓝鲸 available.
* Copyright (C) 2017-2018 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 obtain a copy of the Li... |
package schema
import (
"time"
"github.com/graphql-go/graphql"
"github.com/mszsgo/hjson"
)
type EditMutation struct {
Name string `description:"配置名"`
UpdatedAt time.Time `description:"更新时间"`
}
func (*EditMutation) Description() string {
return "编辑"
}
type EditMutationArgs struct {
Name string `gra... |
package main
import (
"encoding/json"
"fmt"
"my9awsgo/my9sfn"
"time"
)
const GENERIC_STEP_PATH = "generic"
func (swlRun *SwlRun) RunStateMachine() (err error) {
var smInput StateMachineInput
smInput.Project = swlRun.SwlConf.Project
smInput.Env = swlRun.SwlConf.Env
smInput.Region = swlRun.SwlConf.Region
smIn... |
package reliable
import (
"errors"
"log"
"net"
"sync"
"time"
"github.com/seanpfeifer/hostrelay/scan"
)
var ErrServerClosed = errors.New("tcp: Server closed")
func ListenAndServeTCP(network, address string) error {
ln, err := net.Listen(network, address)
if err != nil {
return err
}
log.Printf(`Listenin... |
package repository
import (
"github.com/shharn/blog/db"
)
type dgraphRepositoryContext struct {
Client *db.Client
Err error
}
func (c *dgraphRepositoryContext) Commit() {
c.Client.Commit()
}
func (c *dgraphRepositoryContext) Rollback() {
c.Client.Rollback()
}
func (c *dgraphRepositoryContext) Dispose() {
def... |
package main
import (
"fmt"
"io/ioutil"
"log"
"net"
"net/http"
"net/url"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/zserge/lorca"
"gopkg.in/yaml.v2"
)
type cfg struct {
Debug bool
Title string
Width int
Height int
port int
CDN string
}
func main() {
dir, err := filepath.Abs(file... |
/*
* 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://... |
/*
Copyright 2018 The Kubernetes 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, ... |
package problems
func validMountainArray(A []int) bool {
if len(A) < 3 {
return false
}
var hasPeak bool
for i := 1; i < len(A); i++ {
if A[i] > A[i-1] {
if hasPeak {
return false
}
} else if A[i] < A[i-1] {
if i-1 == 0 {
return false
}
if !hasPeak {
hasPeak = true
}
} else ... |
package main
import (
"C"
"fmt"
"unsafe"
"github.com/axgle/mahonia"
)
//export MakeJWT
func MakeJWT(buffer *C.char)(*C.char) {
dec := mahonia.NewDecoder("gbk")
fmt.Println( dec.ConvertString( C.GoString(buffer) ) )
enc := mahonia.NewEncoder("gbk")
return C.CString( enc.ConvertString... |
package metadata
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/root-gg/plik/server/common"
)
func TestCreateSetting(t *testing.T) {
b := newTestMetadataBackend()
defer shutdownTestMetadataBackend(b)
err := b.CreateSetting(&common.Setting{Key: "foo", Value: "bar"})
require.NoErr... |
package gcp
import (
"fmt"
"sort"
"strconv"
"strings"
machineapi "github.com/openshift/api/machine/v1beta1"
"github.com/openshift/installer/pkg/quota"
"github.com/openshift/installer/pkg/types"
)
// Constraints returns a list of quota constraints based on the InstallConfig.
// These constraints can be used to... |
package mysqldb
import (
"context"
"time"
)
// PushNotification 通知
type PushNotification struct {
PnID int32 `gorm:"pn_id"`
PnDisplayTime string `gorm:"pn_display_time"`
PnTitle string `gorm:"pn_title"`
PnImageURL string `gorm:"pn_image_url"`
PnContentURL string `gorm:"p... |
package auth
import (
"errors"
"fmt"
"github.com/dgrijalva/jwt-go"
)
type JwtVerifier struct {
provider PublicKeyProvider
}
func NewJwtVerifier(provider PublicKeyProvider) (*JwtVerifier, error) {
result := &JwtVerifier{
provider: provider,
}
return result, nil
}
// Parse takes the token string and a functi... |
package config
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/instructure-bridge/muss/testutil"
)
// NOTE: For YAML:
// - don't let any tabs get in
// - file paths are relative to this test file's parent dir
func parseAndCompose(yaml string) (map[string]interfa... |
package tmpl1
import (
"strconv"
"testing"
"github.com/sko00o/leetcode-adventure/queue-stack/queue/bfs"
"github.com/sko00o/leetcode-adventure/queue-stack/queue/bfs/tmpl1"
"github.com/sko00o/leetcode-adventure/queue-stack/queue/bfs/tmpl2"
"github.com/stretchr/testify/require"
)
func TestBFS(t *testing.T) {
E :... |
package handlers
import (
"fmt"
"github.com/david-sorm/montesquieu/article"
"github.com/david-sorm/montesquieu/globals"
templates "github.com/david-sorm/montesquieu/template"
"net/http"
"strconv"
"strings"
)
type IndexView struct {
BlogName string
// a list of articles which should be displayed on the page
... |
package main
const (
xxqrTemplate = customHead + `
<body>
<img style="display: block;margin-left: auto;margin-right: auto;" src="data:image/png;base64,{{.QrBase}}" alt="QRCode" title="scan this picture to visit"/>
</body>`
// `
//<body>
//<div>
// <p>{{.QrBase}} was/were uploaded to</p>
//<img src="data:image/... |
package catrouter
import (
"github.com/julienschmidt/httprouter"
)
type Params struct {
params httprouter.Params
}
func (ps Params) ByName(name string) string {
return ps.params.ByName(name)
}
|
package controllers
import (
"github.com/astaxie/beego"
)
type IndexController struct {
beego.Controller
}
type AboutController struct {
beego.Controller
}
type CaseController struct {
beego.Controller
}
type NewsController struct {
beego.Controller
}
type NewsDeyailController struct {
beego.Controller
}
t... |
/*
* OpenAPI Petstore
*
* This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters.
*
* API version: 1.0.0
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package petstoreserver
import (
"net/http"
"github.com/gin... |
package client
import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
"time"
"github.com/magiconair/properties"
)
// BillingDetails customer address
type BillingDetails struct {
Zip string `json:"zip"`
}
// CardExpiry card expiry date
type CardExpiry struct {
Month string `json:"month"`
Year strin... |
package queries
// SQLResponse is a JSON response for an SQL query
type SQLResponse struct {
AffectedRows int64 `json:"affectedRows"`
Data string `json:"data"`
}
|
package main
import "sort"
var father []int
// 并查集初始化
func initUFS(size int) {
father = make([]int, size)
for i := 0; i < size; i++ {
father[i] = i
}
}
// 合并两个并查集
func mergeUFS(a, b int) {
// 注意a,b必须 < father数组的长度
father1, father2 := findFather(a), findFather(b)
father[father1] = father2 // 这样也可以
/*
fathe... |
package contract
import "github.com/bqxtt/book_online/api/model/entity"
type ListBooksRequest struct {
Page int32 `form:"page" json:"page" binding:"required"`
PageSize int32 `form:"page_size" json:"page_size" binding:"required"`
}
type ListBooksResponse struct {
BaseResponse *BaseResponse `json:"base_respo... |
package commands
import (
"context"
"log"
"os"
"strings"
"github.com/argoproj/pkg/errors"
argoJson "github.com/argoproj/pkg/json"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/argoproj/argo/cmd/argo/commands/clie... |
package erratum
// Use an input with a resource from the opener
func Use(o ResourceOpener, input string) (result error) {
resource, err := o()
for err != nil {
if _, ok := err.(TransientError); !ok {
return err
}
resource, err = o()
}
defer resource.Close()
defer func() {
if r := recover(); r != nil ... |
package excel
type ExcelTest struct {
}
|
package main
import (
"fmt"
"math"
"sort"
)
// https://leetcode-cn.com/problems/contains-duplicate-iii/
// 220. 存在重复元素 | Contains Duplicate III
// 其他:
// * 217: https://leetcode-cn.com/problems/contains-duplicate/
// * 219: https://leetcode-cn.com/problems/contains-duplicate-ii/
//-----------------------------... |
package informartionAllSum
import (
"fmt"
"time"
)
const (
//TimeFormart = "2006-01-02 15:04:05"
TimeFormart = "20060102"
)
func GetYesterDay() (yd string) {
t1 := time.Now()
diff, err := time.ParseDuration("-24h")
if err != nil {
fmt.Println(err)
}
yd = t1.Add(diff).Format(TimeFormart)
return yd
}
|
package main
import (
"os"
)
func main() {
day := os.Args[1]
switch day {
case "1":
data := loadFromTextFile("day1.txt")
dayOne(data)
case "2":
data := loadFromTextFile("day2.txt")
dayTwo(data)
case "3":
data := loadFromTextFile("day3.txt")
dayThree(data)
}
}
|
package sudoku
import (
"fmt"
"github.com/kr/pretty"
"log"
"reflect"
"testing"
)
func TestTechniquesSorted(t *testing.T) {
lastLikelihood := 0.0
for i, technique := range AllTechniques {
if technique.humanLikelihood(nil) < lastLikelihood {
t.Fatal("Technique named", technique.Name(), "with index", i, "has... |
/*
Copyright © 2022 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
dist... |
package main
import (
"github.com/aws/aws-sdk-go/aws/session"
"fmt"
"os"
"log"
"github.com/mitchellh/cli"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/iam"
"github.com/aws/aws-sdk-go/service/autoscaling"
"github.com/aws/aws-sdk-go/service/elb"
"github.com/aws/aws-sdk-go/service/... |
package schemes
import "image/color"
// PBJ is a gradient color scheme from orange to purple.
var PBJ []color.Color
func init() {
PBJ = []color.Color{
color.RGBA{R: 0x29, G: 0xa, B: 0x59, A: 0xff},
color.RGBA{R: 0x29, G: 0xa, B: 0x59, A: 0xff},
color.RGBA{R: 0x2a, G: 0xa, B: 0x59, A: 0xff},
color.RGBA{R: 0x... |
package gouldian_test
import (
"encoding/json"
"errors"
"net/http"
"testing"
µ "github.com/fogfish/gouldian/v2"
"github.com/fogfish/gouldian/v2/mock"
"github.com/fogfish/it/v2"
)
func TestHTTP(t *testing.T) {
foo := mock.Endpoint(
µ.HTTP(
http.MethodGet,
µ.URI(µ.Path("foo")),
),
)
req := mock.In... |
package functions
import (
"sort"
)
// Sort works similar to sort.SliceType(). However, unlike sort.SliceType the
// slice returned will be reallocated as to not modify the input slice.
//
// See Reverse() and AreSorted().
func (ss SliceType) Sort() SliceType {
// Avoid the allocation. If there is one element or le... |
/*
Task
The input consists of a JSON object, where every value is an object (eventually empty), representing a directory structure. The output must be a list of the corresponding root-to-leaf paths.
Inspired by this comment on StackOverflow.
Input specifications
You can assume that that the input always contains a ... |
package service
import (
"Seaman/model"
"github.com/go-xorm/xorm"
"github.com/kataras/iris/v12"
)
/**
* 管理员服务
* 标准的开发模式将每个实体的提供的功能以接口标准的形式定义,供控制层进行调用。
*
*/
type SecurityService interface {
//通过管理员用户名+密码 获取管理员实体 如果查询到,返回管理员实体,并返回true
//否则 返回 nil ,false
GetByAdminNameAndPassword(username, password string) (mo... |
package aggregation
import (
"github.com/emicklei/go-restful"
api "github.com/emicklei/go-restful-openapi"
. "grm-service/dbcentral/pg"
. "grm-service/util"
"titan-statistics/dbcentral/etcd"
"titan-statistics/dbcentral/pg"
. "titan-statistics/types"
)
type AggrSvc struct {
SysDB *pg.SystemDB
MetaDB *... |
package model
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type User struct {
ID string `json:"-" gorm:"primaryKey"`
Name string `json:"name,omitempty"`
Email string `json:"email,omitempty" gorm:"type:varchar(100);unique_index"`
Gender string `js... |
package main
import (
"bytes"
"context"
"crypto/sha256"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
)
func TestSuitePC(t *testing.T) {
var (
key = "fc58161e6b0da8e0cae8248f40141165"
adminUse... |
package main
import (
"container/heap"
"fmt"
)
// 1091. 二进制矩阵中的最短路径
// 在一个 N × N 的方形网格中,每个单元格有两种状态:空(0)或者阻塞(1)。
// 一条从左上角到右下角、长度为 k 的畅通路径,由满足下述条件的单元格 C_1, C_2, ..., C_k 组成:
// 相邻单元格 C_i 和 C_{i+1} 在八个方向之一上连通(此时,C_i 和 C_{i+1} 不同且共享边或角)
// C_1 位于 (0, 0)(即,值为 grid[0][0])
// C_k 位于 (N-1, N-1)(即,值为 grid[N-1][... |
package services
import (
Auth "LivingPointAPI/authorization/authorization"
"LivingPointAPI/clients"
DB "LivingPointAPI/database/database"
JWT "LivingPointAPI/utils/authentication"
"context"
"log"
"strconv"
"time"
jwtGo "github.com/dgrijalva/jwt-go"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)... |
package optionsgen_test
import (
"testing"
goplvalidator "github.com/go-playground/validator/v10"
testcase "github.com/kazhuravlev/options-gen/options-gen/testdata/case-10-global-override"
"github.com/kazhuravlev/options-gen/pkg/validator"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/requir... |
package resourcetypes
import (
"encoding/json"
"os"
"github.com/shwetha-pingala/HyperledgerProject/InvoiveProject/go-api/hyperledger"
"github.com/shwetha-pingala/HyperledgerProject/InvoiveProject/go-api/models"
)
func Index(clients *hyperledger.Clients) (resourcetypes *models.ResourceTypes, err error) {
resourc... |
package oop1
type Number1 interface{
Equal(i int) bool
LessThan(i int) bool
MoreThan(i int) bool
} |
// Copyright 2019-2023 The sakuracloud_exporter 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 appl... |
package main
import (
"os/signal"
"context"
"syscall"
"flag"
"log"
"os"
"github.com/GoogleCloudPlatform/cloud-builders-community/windows-builder/builder/builder"
)
var (
hostname = flag.String("hostname", "", "Hostname of remote Windows server")
username = flag.String("username", "", "Userna... |
// Copyright 2021 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 server
import (
"net/http"
"go.ua-ecm.com/chaki/tasks"
"github.com/labstack/echo"
)
func (s *Server) getTasks(c echo.Context) error {
sanitizedConfig := s.tasksConfig.Sanitize()
return c.JSON(http.StatusOK, sanitizedConfig)
}
type runTaskResponseStatement struct {
Data []map[string]interface{} `json... |
package Problem0506
import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
)
// tcs is testcase slice
var tcs = []struct {
nums []int
ans []string
}{
{
[]int{0, 4, 3, 2, 1},
[]string{"5", "Gold Medal", "Silver Medal", "Bronze Medal", "4"},
},
{
[]int{5, 4, 3, 2, 1},
[]string{"Gold Medal", "... |
package main
/*
Sorting slices using pkg sort
*/
import (
"fmt"
"sort"
)
func main() {
ss := []string {
"John", "Paul", "George", "Ringo",
}
si := []int {
3, 7, 2, 4, 1, 5, 8, 6,
}
fmt.Println("_________UNSORTED_________")
fmt.Println(ss)
fmt.Println(si)
fmt.Println("__________SORTED__________")
sor... |
package main
import "testing"
func TestBinarySearch(t *testing.T) {
assert([]int{}, 1, -1, t)
assert([]int{-1}, -1, 0, t)
assert([]int{-1, 1}, 1, 1, t)
assert([]int{-1, 1, 2, 3}, 3, 3, t)
assert([]int{-1, 1, 2, 3}, 4, -1, t)
assert([]int{-1, 1, 2, 3}, -4, -1, t)
assert([]int{-1, 1, 2, 3, 7}, -4, -1, t)
... |
package interactor
import (
"fmt"
"github.com/jinzhu/gorm"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"time"
)
// ReturnRes is a struct with returning message string and err.
type ReturnRes struct {
Msg string
Err error
// Code uint
}
// Reservation is a struct schema with details about the resevation.
type R... |
package controllers
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/GoPex/caretaker/bindings"
"github.com/GoPex/caretaker/helpers"
)
// GetPing is the handler for the GET /info/ping route.
// This will respond by a pong JSON message if the server is alive
func GetPing(c *gin.Context) {
c.JSON(http.S... |
// This file is subject to a 1-clause BSD license.
// Its contents can be found in the enclosed LICENSE file.
package evdev
import "unsafe"
// Absolute events describe absolute changes in a property.
// For example, a touchpad may emit coordinates for a touch location.
// A few codes have special meanings:
//
// Abs... |
package msgHandler
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/op/go-logging"
"sync"
)
type CheckFork struct {
sync.RWMutex
fork map[uint64]map[uint64][]*PeerHash
Logger *logging.Logger
}
type PeerHash struct {
peerid uint64
preHash []byte
}
func NewCheckFork() *CheckFork {
return &CheckFork{
... |
// +build spi,!i2c
package main
import (
// Modules
_ "github.com/djthorpe/gopi-hw/sys/spi"
)
const (
MODULE_NAME = "sensors/bme280/spi"
)
|
package main
import (
"fmt"
"math/rand"
"net/http"
"time"
)
type result int
func (r result) value() string {
var val = ""
switch r {
case 0:
val = "大吉"
case 1:
val = "中吉"
case 2:
val = "小吉"
case 3:
val = "吉"
case 4:
val = "凶"
case 5:
val = "大凶"
}
return val
}
// OmikujiServer is server
typ... |
package agent
import (
"net/http"
"github.com/Sirupsen/logrus"
"github.com/bryanl/dolb/service"
"github.com/gorilla/mux"
)
func UpstreamDeleteHandler(c interface{}, r *http.Request) service.Response {
config := c.(*Config)
vars := mux.Vars(r)
svcName := vars["service"]
uName := vars["upstream"]
sm := conf... |
package public
import (
"context"
"tpay_backend/merchantapi/internal/common"
"tpay_backend/model"
"tpay_backend/utils"
"tpay_backend/merchantapi/internal/svc"
"tpay_backend/merchantapi/internal/types"
"github.com/tal-tech/go-zero/core/logx"
)
type RechargeLogic struct {
logx.Logger
ctx context.Context
... |
package models
import (
"encoding/json"
"newproject/database"
"github.com/jinzhu/gorm"
)
// Product model
type Product struct {
gorm.Model
SKU string `json:"sku" gorm:"type:varchar(20);unique_index"`
CategoryID uint `json:"categoryID"`
Name string `json:"name"`
Description string... |
package skpsilk
// silk/src/SKP_Silk_scale_vector.c
// scale_vector32_Q26_lshift_18 Multiply a vector by a constant
func scale_vector32_Q26_lshift_18(data1 []int32, gain_Q26 int32, dataSize int) {
for i := 0; i < dataSize; i++ {
data1[i] = int32((int64(data1[i]) * int64(gain_Q26)) >> 8) // OUTPUT: Q18
}
}
|
package point2
import "testing"
func TestPoint2_String(t *testing.T) {
p := Point2{}
if p.String() != "(0.000000,0.000000)" {
t.Log(p)
t.Fail()
}
} |
package main
import (
"fmt"
"log"
"github.com/shanghuiyang/rpi-devices/dev"
"github.com/stianeikeland/go-rpio"
)
const (
p18 = 18
)
func main() {
if err := rpio.Open(); err != nil {
log.Fatalf("failed to open rpio, error: %v", err)
return
}
defer rpio.Close()
sg := dev.NewSG90(p18)
var angle int
for... |
package iirepo_stage
import (
"os"
"path/filepath"
)
// Walk will locate the ii repo stage for ‘path’ and call ‘fn’ for each staged file in deterministic order
// based on lexical ordering.
func Walk(path string, fn func(relstagedpath string)error) error {
stagepath, err := Locate(path)
if nil != err {
return ... |
package hat_test
import (
"bytes"
"io"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"go.coder.com/hat"
"go.coder.com/hat/asshat"
)
func TestT(tt *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
io.Copy(rw, req.Body)... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.