text stringlengths 11 4.05M |
|---|
package base
// Pagination struct
type Pagination struct {
PageNo int `json:"pageNo"`
PageSize int `json:"pageSize"`
Total int `json:"total"`
}
|
package utils
import (
"crypto/md5"
"encoding/hex"
"os"
"strings"
)
func substr(s string, pos, length int) string {
runes := []rune(s)
l := pos + length
if l > len(runes) {
l = len(runes)
}
return string(runes[pos:l])
}
// GetParentFullPath ...
func GetParentFullPath(in string) (parentFullPath string) {
... |
package kvs
import (
"bytes"
"encoding/binary"
"encoding/json"
"fmt"
"sync"
abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/code"
"github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/... |
package event
type CustomerRegistered struct {
CustomerID string
FullName string
EmailAddress string
ConfirmationHash string
}
|
package main
import (
r "MetricsNew/redis"
"fmt"
)
func main() {
if r.ExistValue(123, []interface{}{23123, 121212}) {
fmt.Println("123123", " - old")
} else {
fmt.Println("123123", " - new")
}
if err := r.AddValue(123, []interface{}{23123, 121212}); err != nil {
fmt.Println(err)
}
if err := r.RenameKe... |
package enforcer
import (
"context"
"fmt"
"github.com/liatrio/rode/pkg/occurrence"
"github.com/liatrio/rode/pkg/attester"
"go.uber.org/zap"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
)
// Enforcer enforces attestations on a resource
type Enforcer interface {
Enforce(ctx con... |
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
//
package store
import (
"testing"
"github.com/mattermost/mattermost-cloud/internal/testlib"
"github.com/mattermost/mattermost-cloud/model"
"github.com/stretchr/testify/assert"
"github.com/stretchr/t... |
package main
import (
"bufio"
"fmt"
"log"
"os"
"strings"
)
func panacea(p, q string) bool {
var v, m int
l, r := strings.Fields(p), strings.Fields(q)
for _, i := range l {
fmt.Sscanf(i, "%x", &v)
m += v
}
for _, i := range r {
fmt.Sscanf(i, "%b", &v)
m -= v
}
return m <= 0
}
func main() {
data, ... |
package main
import (
"context"
"errors"
"net"
"net/http"
"os"
"os/signal"
"syscall"
)
func main() {
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
ctx := context.Background()
s := &http.Server{
Addr: net.JoinHostPort("", "9090"),
Handler: http.FileServer(http.D... |
package main
import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
"github.com/gorilla/mux"
"go.mongodb.org/mongo-driver/bson/primitive"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
var client *mongo.Client
type Person struct {
ID primitive.ObjectID `json:... |
package extra
import (
"time"
)
type ClientLog struct {
Id int
UserId int
Platform int
Version string
Content string
Extra string
Status int
CreatedAt time.Time
UpdatedAt time.Time
}
|
package sics
import (
"errors"
"fmt"
"github.com/moovweb/gokogiri"
"github.com/moovweb/gokogiri/xml"
"strings"
)
func Parse(input []byte) (m Match, err error) {
h, err := gokogiri.ParseHtml(input)
if err != nil {
return
}
// Find score tables and extract innings out of each
oversTables, err := h.Search("/... |
package magic
import (
"fmt"
"path/filepath"
"testing"
)
func TestMagic(t *testing.T) {
files, _ := filepath.Glob("/home/strings/via/cache/src/*")
if len(files) == 0 {
t.Errorf("expected files list greater the 0 to test")
t.FailNow()
}
for _, file := range files {
m, err := GetFileMagic(file)
if err !=... |
package controller
import (
"github.com/gorilla/websocket"
"github.com/labstack/echo/v4"
"log"
"net/http"
"time"
"websocket-example/controller/delivery"
)
var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {
return true
},
}
func Serve... |
package virtualmachineimage
import (
"context"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)
co... |
package main
import "fmt"
//程序定义一个int变量num的地址并打印
//将num的地址赋给指针ptr,并通过ptr去修改num的值
func main() {
var a int
fmt.Println(&a)
var p *int
p = &a
*p = 20
fmt.Println(a)
}
|
package postgres
import (
"github.com/google/uuid"
"github.com/orbis-challenge/src/models"
)
func (q DBQuery) SaveSectorWeight(sectorWeight *models.SectorWeight) (*models.SectorWeight, error) {
_, err := q.Model(sectorWeight).
Returning("*").
Insert()
return sectorWeight, err
}
func (q DBQuery) DeleteSector... |
package structs
import "fmt"
type Student struct{
id int
name string
age int
}
func Learn() {
james := Student {
id:2,
name:"James",
age: 15,
}
students := []Student{
{id:2, name:"John", age: 20},
{id:3, name:"Top", age: 21},
}
fmt.Println(james.name)
fmt.Println(students[1].name)
v := V... |
package cmd
import (
"bufio"
"fmt"
"os"
"strconv"
"strings"
snmpsimclient "github.com/inexio/snmpsim-restapi-go-client"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// eraseEnvCmd represents the eraseEnv command
var eraseEnvCmd = &cobra.Command{
Use: "erase-env <tag-id>... |
package ldap
import (
"bytes"
"crypto/tls"
"crypto/x509"
"fmt"
"reflect"
"strconv"
"strings"
"time"
log "github.com/Sirupsen/logrus"
"github.com/pkg/errors"
"github.com/rancher/go-rancher/v2"
"github.com/rancher/rancher-auth-service/model"
"gopkg.in/ldap.v2"
)
// LClient is the ldap client
type LClient ... |
/*
Package base provides base data structures and functions for gorse.
The base data structures and functions include:
* Parallel Scheduler
* Hyper-parameters Management
* Random Generator
* Similarity Metrics
* Sparse Data Structures
* Numeric Computing
* Options Management
*/
package base
|
package eth
import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/vitelabs/go-vite-gw/setting"
"os"
)
var Erc2ViteABI *abi.ABI
func init() {
contractAbi, e := GetContractAbi(setting.EthSetting.Erc2ViteABIPath)
if e != nil {
panic(e)
}
Erc2ViteABI = contractAbi
}
//read abi-json file
func GetC... |
package binary
import (
"encoding/binary"
"errors"
)
//ByteToIntByLittleEndian is a byte[] to int converter.
//c# BitConverter.GetBytes is LittleEndian
//LittleEndian 從最小開始 (最低位元組在前)
//BigEndian 從最大開始 (最高位元組在前)
//Ex: long 0x12345678
//littleEndian 0x78 0x56 0x34 0x12
//BigEndian 78 56 43 12
func ByteToIntByLittleE... |
package dependencies
import (
"bufio"
"encoding/json"
"fmt"
"regexp"
"strings"
)
func ParsePythonRequirements(reader *bufio.Reader) []string {
packageNamesSet := map[string]bool{}
for {
lineBytes, _, err := reader.ReadLine()
if err != nil {
break
}
line := string(lineBytes)
line = strings.TrimSp... |
// package config 支持字符串、整型、以及数组 布尔型
package snailframe
import (
"github.com/BurntSushi/toml"
"os"
"path/filepath"
)
/*
type configNormalType map[string]interface{}
type config struct {
data interface{}
}*/
//初始化Conf
func NewConf(configStrcut interface{},configName string) (redata toml.MetaData) {
dir, err := ... |
package urlshortener
import (
"log"
"net/http"
"gopkg.in/yaml.v2"
)
type pathUrl struct {
Path string `yaml:"title"`
URL string `yaml:"url"`
}
func MapHandler(pathToUrls map[string]string, fallback http.Handler) http.HandlerFunc {
return func(rw http.ResponseWriter, r *http.Request) {
path := r.URL.Path
... |
package data
type ItemCategories struct {
ItemCategories []struct {
Category string `json:"key"`
Value []struct {
SubCategory string `json:"key"`
Base []string `json:"value"`
} `json:"value"`
} `json:"itemCategories"`
Items []string `json:"items"`
}
|
// Copyright 2018 Sergey Novichkov. All rights reserved.
// For the full copyright and license information, please view the LICENSE
// file that was distributed with this source code.
package migrate
import (
"github.com/gozix/di"
"github.com/gozix/glue/v3"
gzSQL "github.com/gozix/sql/v3"
gzZap "github.com/gozix/... |
package galery
import (
"encoding/json"
"io/ioutil"
"net/http"
"regexp"
"strings"
"time"
"github.com/gorilla/mux"
"github.com/juliotorresmoreno/unravel-server/config"
"github.com/juliotorresmoreno/unravel-server/helper"
"github.com/juliotorresmoreno/unravel-server/middlewares"
"github.com/juliotorresmoreno... |
package main
import (
"fmt"
"message/src/cn/cncommdata/study/controller"
"message/src/cn/cncommdata/study/stack"
)
func main() {
//array()
//mySlice()
//helloWorld()
//originSlice()
//resetSlice()
//directStatementSlice()
//useMakeFunConstructSlice()
//utils.Send()
//实例化file
//file := model.FileConstr... |
package gofile
import "testing"
func TestNew(t *testing.T) {
Register("one", buildOne)
Register("two", buildTwo)
emptyConfig := map[string]string{}
one, err := New("one", emptyConfig)
if err != nil {
t.Errorf("Could not create driver 'one'")
}
switch v := one.(type) {
default:
t.Errorf("'one' not a '... |
// Copyright © 2019 NAME HERE <EMAIL ADDRESS>
//
// 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 ... |
package model
import (
"time"
"github.com/williammfu/vip-management-system/utils"
"gorm.io/gorm"
)
type Vip struct {
ID int `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
CountryOfOrigin string `json:"country_of_origin"`
ETA time.Time `json:"eta"`
Phot... |
package main
import (
"github.com/golang-collections/collections/stack"
)
var calc Calculator
func main() {}
// Operator is used to specify calculator operator.
type Operator int
const (
// UNKNOWN operator is used for unknown operators
UNKNOWN Operator = iota
// ADD operator is used to add two numbers
ADD
/... |
package config
import (
"github.com/bradfitz/gomemcache/memcache"
"github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin"
"os"
)
func InitializeSession() gin.HandlerFunc {
sessionDriver := os.Getenv("SESSION_STORE_DRIVER")
sessionName := os.Getenv("SESSION_STORE_NAME")
appKey := os.Getenv("APP_KEY")
swit... |
package cli
import (
"context"
"time"
"github.com/spf13/cobra"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/cli-runtime/pkg/genericclioptions"
"github.com/tilt-dev/tilt/internal/analytics"
engineanalytics "github.com/tilt-dev/tilt/internal/engine/analytics"
"github.com/tilt-dev/tilt/pkg/apis/core/v1... |
package main
import "fmt"
func main(){
a := test_defer()
fmt.Println("a:",a)
}
func test_defer() int {
defer func(){
fmt.Println("222")
}()
ret := 1
fmt.Println("ret:",ret)
return ret
} |
package database
import (
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func ConnectToDatabase() *gorm.DB {
dsn := "root:ngochd246@/tivis?charset=utf8&parseTime=True&loc=Local"
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
if err != nil {
panic("Connected fail")
}
return db
} |
package msgpack
import (
"encoding/hex"
"fmt"
"reflect"
"testing"
)
func TestPack(t *testing.T) {
t.Parallel()
packTests := map[string]struct {
// Expected value
v interface{}
// Hex encodings of typ, v
hs string
}{
"Bool/True": {
v: true,
hs: "c3",
},
"Bool/False": {
v: false,
hs:... |
package main
import (
"crypto/tls"
"encoding/base64"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"strings"
"time"
)
type Settings struct {
GitHubUserName string `yaml:"gitHubUserName"`
GitHubToken string `yaml:"gitHubToken"`
RestrictMergeRequester string `y... |
package login
import (
"encoding/json"
"github.com/llr104/LiFrame/core/liFace"
"github.com/llr104/LiFrame/core/liNet"
"github.com/llr104/LiFrame/dbobject"
"github.com/llr104/LiFrame/proto"
"github.com/llr104/LiFrame/server/app"
"github.com/llr104/LiFrame/utils"
"time"
)
var Enter EnterLogin
func init() {
En... |
package access
import (
"encoding/json"
"errors"
"net/http"
//"gopkg.in/mgo.v2"
//"gopkg.in/mgo.v2/bson"
//"github.com/mgalela/akses/appserver/db"
)
const (
graphPrefixURI = "https://graph.facebook.com"
)
var (
socialAccountMap = map[string]string{
"facebook": "Facebook",
"google": "Google",
"twitter... |
package gosqlite3-extension-functions
import (
"database/sql"
"testing"
)
func TestOpenReturnsWithoutError(t *testing.T) {
db, err := sql.Open("sqlite3-extension-functions", ":memory:")
if err != nil {
t.Fatalf(err.Error())
}
err = db.Ping()
if err != nil {
t.Fatalf(err.Error())
}
}
|
package level_ip
import (
"fmt"
)
const (
IPV4 uint8 = 0x04
IPV4_TCP = 0x06
)
type IPHdr struct {
version uint8
ihl uint8
tos uint8
len uint16
id uint16
flags uint16
frag_offet uint16
ttl uint8
proto uint8
csum uint16
saddr uint32
daddr ... |
package main
import "fmt"
var selectCaseSummary = `
每个case都必须是一个执行 <- 运算的channel通信
所有channel表达式都会被求值,所有被发送的表达式都会被求值
case和default的路径优先级:case优先级大于default。如果所有case都阻塞,且有default子句,则执行default。如果没有default字句,select将阻塞,直到某个通信可以运行;Go不会重新对channel或值进行求值。
case和case间的路径优先级: case之间优先级相同,如果有多个case都不阻塞,select会随机公平地选出一个执行,其他不会执行。
`
... |
package iafon
import (
"net/http"
"testing"
"time"
)
func TestNewServer(t *testing.T) {
if NewServer() == nil {
t.Fatal("NewServer() == nil")
}
}
func TestRunWithoutRoute(t *testing.T) {
s := NewServer("127.0.0.1:")
err := s.Run()
if err == nil {
t.Fatal("Run before add routes should return error")
}
}... |
package helper
import (
"encoding/json"
"log"
)
// PrettyPrintJSON : return a format JSON string representation
func PrettyPrintJSON(p interface{}) string {
b, err := json.MarshalIndent(p, "", " ")
if err != nil {
log.Println("error:", err)
return ""
}
return string(b)
}
|
package azure
import (
"errors"
"strings"
"testing"
"github.com/Azure/azure-sdk-for-go/arm/compute"
"github.com/NeowayLabs/klb/tests/lib/azure/fixture"
)
type VM struct {
client compute.VirtualMachinesClient
f fixture.F
}
func NewVM(f fixture.F) *VM {
as := &VM{
client: compute.NewVirtualMachinesClie... |
package thriftclient
import (
"errors"
)
const (
NO_NODE_SERVICE = 1
NO_AVAILABLE_NODE = 2
)
type NodeException interface {
CException
TypeID() int
Err() error
}
type cNodeException struct {
typeID int
err error
}
func (c *cNodeException) TypeID() int {
return c.typeID
}
func (c *cNodeException) Err(... |
package gdash
//Last return last slice element
func Last(slice []interface{}) interface{} {
if len(slice) > 0 {
return slice[len(slice)-1]
}
return nil
}
|
// Copyright 2019 Yunion
//
// 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... |
package awsfirehose
import (
"reflect"
"strings"
firehosePool "github.com/gabrielperezs/streamspooler/firehose"
)
type AWSFirehose struct {
s *firehosePool.Server
}
func NewOrGet(cfg map[string]interface{}) (*AWSFirehose, error) {
c := firehosePool.Config{}
v := reflect.ValueOf(&c)
ps := v.Elem()
typeOfS :... |
package main
import (
"github.com/G-Research/armada/cmd/armadactl/cmd"
"github.com/G-Research/armada/internal/common"
)
func main() {
common.ConfigureCommandLineLogging()
cmd.Execute()
}
|
package main
import "strings"
var DNSPOD_EMAIL = strings.Join([]string{"u", "s", "e", "r", "@", "e", "x", "a", "m", "p", "l", "e", ".", "c", "o", "m"}, "")
var DNSPOD_PASSWORD = strings.Join([]string{"e", "x", "a", "m", "p", "l", "e", "p", "a", "s", "s", "w", "o", "r", "d"}, "")
var GITHUB_TOKEN = strings.Join([]stri... |
package doublePointData
import (
"AlgorithmPractice/src/common/Constant"
)
var (
DemoArray01 = []int{1, 100, 22, 39, 43, 58, 64, 76, 79, 85, 96, 58}
Target01 = 99
Answer01 = []int{1, 22, 76}
Target011 = 101
Answer011 = []int{1, 22, 79}
Target012 = C.Max
Answer012 = []int{85, 96, 100}
Target013 ... |
package tests
import (
"sync"
"testing"
ravendb "github.com/ravendb/ravendb-go-client"
"github.com/stretchr/testify/assert"
)
func ravendb10566_shouldBeAvailable(t *testing.T, driver *RavenTestDriver) {
var err error
store := driver.getDocumentStoreMust(t)
defer store.Close()
var name string
var mu sync.Mu... |
package main
import (
"sync"
"time"
"github.com/go-redis/redis"
"github.com/mingjingc/redlock-go"
)
func main() {
dml := redlock.New(redis.NewClient(&redis.Options{
Addr: ":6379",
}), redis.NewClient(&redis.Options{
Addr: ":6380",
}), redis.NewClient(&redis.Options{
Addr: ":6381",
}))
var wg sync.Wai... |
package models
type BotUser struct {
UserName string
FirstName string
ChatID int64
} |
package main
import (
"fmt"
"time"
)
func main() {
now := time.Now()
/* You can convert a time to seconds since epoch using the Unix() func! */
secs := now.Unix()
nanos := now.UnixNano()
fmt.Println(now)
millis := nanos / 1000000
fmt.Println(secs)
fmt.Println(millis)
fmt.Println(nanos)
/* You can also ... |
package main
const Name string = "crondoc"
const Version string = "0.1.1"
|
package leetcode
func getRow1(rowIndex int) []int {
result := make([]int, 0, rowIndex+1)
for ; rowIndex >= 0; rowIndex-- {
result = append(result, 1)
for j := len(result) - 2; j > 0; j-- {
result[j] += result[j-1]
}
}
return result
}
|
package h2mux
import (
"bytes"
"io"
"sync"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func AssertIOReturnIsGood(t *testing.T, expected int) func(int, error) {
return func(actual int, err error) {
if expected != actual {
t.Fatalf("Expected %d bytes, got %d", expected, actual)
}
if err != ... |
package rpc
// RawTX represents a for creation using the RPC interface
// of the a Methuselah node.
type RawTX struct {
Data []byte `json:"data"`
Version uint8 `json:"version"`
}
|
package main
import (
"cuthkv/cache"
"os"
"os/signal"
"syscall"
)
func main() {
interrupt := make(chan os.Signal, 1)
signal.Notify(interrupt, os.Interrupt, os.Kill, syscall.SIGTERM)
go cache.InitCache()
<-interrupt
os.Exit(1)
}
|
package plugins
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/klog"
"strings"
)
const (
CustomConfigmapPluginName = "CustomConfigmap"
)
func init() {
register(CustomConfig... |
// Copyright 2017 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package security
import (
"context"
"io/ioutil"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"syscall"
"chromiumos/tast/testing"
)
func init() {
testing.Ad... |
package test
import (
"fmt"
"go_training/model"
"testing"
)
func TestPerhitunganMap(t *testing.T) {
t.Run("test untuk fungsi penjumlahan ", func(t *testing.T) {
var testPenjumlahan = []struct {
s string
P int
L int
T int
hasilMaunya interface{}
}{
{s: ... |
package models
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
// 销售订单实例表结构
// 销售子订单
type CustomerSubOrder struct {
SubOrderId int64 `json:"sub_order_id" bson:"sub_order_id"` // 子订单id
SubOrderSn string `json:"sub_order_sn" bson:"sub_order_sn"` // 子订单号
Com... |
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* ceftb xir
* ==================
* This file defines the network modeling intermediate representation (xir)
* data structures. xir is a simple network represenatation where
*
* The primary components are:
* - (sub)networks
... |
package responses
import (
"encoding/json"
"fmt"
"net/http"
)
func JSON(w http.ResponseWriter, statusCode int, data interface{}) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
w.Header().Set("Access-Control-Allow-Headers", "... |
package user
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
log "github.com/sirupsen/logrus"
"github.com/opsbot/cli-go/utils"
"github.com/opsbot/zerotier/api"
"github.com/spf13/cobra"
)
// UpdateCommand returns a cobra command
func UpdateCommand() *cobra.Command {
var fileName string
var fileData []byte... |
package main
import (
"fmt"
"github.com/gin-gonic/gin"
// "net/http"
)
type User struct{
FirstName string
LastName string
Email string
}
func listUsers(c *gin.Context){
var users = []User{
User{FirstName:"John",LastName:"Doe",Email:"john.doe@mail.com"},
User{FirstName:"Jane",LastName:"Doe",Email:"jane.doe... |
package main
/*
https://leetcode.com/problems/find-all-anagrams-in-a-string/discuss/92007/Sliding-Window-algorithm-template-to-solve-all-the-Leetcode-substring-search-problem.
Sliding Window algorithm template to solve all the Leetcode substring search problem.
*/
Among all leetcode questions, I find that there ar... |
package Week_01
import "fmt"
func getHint(secret string, guess string) string {
bulls, cows := 0, 0
bucket := map[byte]int {}
for k, v := range secret {
if byte(v) == guess[k] {
bulls++
}
bucket[byte(v)]++
}
for _,v := range guess {
if bucket[byte(v)] > 0 {
cows++
bucket[byte(v)]--
}
}
cows... |
package handler
import (
"github.com/GreenComb/margool-admin/usecases"
"github.com/GreenComb/margool-contrib/middleware"
"github.com/martini-contrib/render"
)
func DashboardCmsForm(ctx *middleware.Context, ren render.Render) {
ctx.Set("StaticAssets", usecases.GetConfStaticAssets())
ctx.Set("Sidebar", "dashboard"... |
package persistence
import (
"database/sql"
"errors"
"fmt"
structs3 "fp-dynamic-elements-manager-controller/internal/logging/structs"
"fp-dynamic-elements-manager-controller/internal/queue/structs"
structs2 "fp-dynamic-elements-manager-controller/internal/stats/structs"
"github.com/go-sql-driver/mysql"
"github... |
package bpi_test
import (
"testing"
"github.com/dasfoo/bright-pi"
"github.com/dasfoo/i2c"
)
type i2cDevice struct {
regs [256]byte
address byte
t *testing.T
}
func (d *i2cDevice) Close() error {
d.address = 0
return nil
}
func (d *i2cDevice) WriteByteToReg(addr, reg, value byte) error {
if addr =... |
package Split_Linked_List_in_Parts
type ListNode struct {
Val int
Next *ListNode
}
func splitListToParts(root *ListNode, k int) []*ListNode {
p := root
length := 0
for p != nil {
length++
p = p.Next
}
mod := length % k
size := length / k
c := root
result := make([]*ListNode, k)
for i := 0; c != nil &... |
package services
import (
"encoding/json"
"fmt"
"github.com/h2non/filetype"
"image"
"image/draw"
"image/jpeg"
"image/png"
"io/ioutil"
"os"
"strings"
"unicode/utf8"
)
func GenerateCard() {
source, err := os.Open("source.png")
if err != nil {
fmt.Println(err)
}
sourceImg, err := png.Decode(source)
//... |
package main
import (
"context"
"fmt"
pb "github.com/tony-yang/gcp-cloud-native-stack/frontend/genproto"
)
func (f *frontendServer) getProducts(ctx context.Context) ([]*pb.Product, error) {
resp, err := pb.NewProductCatalogServiceClient(f.catalogConn).ListProducts(ctx, &pb.Empty{})
return resp.GetProducts(), er... |
/*
* Npcf_SMPolicyControl API
*
* Session Management Policy Control Service © 2019, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
*
* API version: 1.0.4
* Generated by: OpenAPI Generator (https://openapi-generator.tech)
*/
package openapi
type QosNotificationCont... |
package controllers
import (
"github.com/revel/revel"
)
type Message struct {
*revel.Controller
}
func (c Message) Hello() revel.Result {
return c.RenderText("Hello, ReactGo!")
}
|
package operator
import (
"testing"
"github.com/blang/semver/v4"
"github.com/openshift/oc-mirror/pkg/api/v1alpha2"
"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/alpha/property"
"github.com/stretchr/testify/require"
)
func TestConvertDCToInclude... |
package main
import (
"bytes"
"context"
"encoding/json"
"errors"
"fmt"
"log"
"net/url"
"os"
"strings"
"time"
plugin_models "code.cloudfoundry.org/cli/plugin/models"
"code.cloudfoundry.org/cli/plugin"
"github.com/cloudfoundry/noaa/consumer"
"github.com/cloudfoundry/sonde-go/events"
)
type runAndWait st... |
package discern
import (
"fmt"
"github.com/hahnicity/go-discern/config"
"github.com/hahnicity/go-stringit"
)
func Requester(conf *config.Config, companies map[string]string, work chan <-WikiRequest) {
activeRequests := 0
c := make(chan *WikiResponse)
ar := make([]*WikiResponse, 0)
for sy... |
package main
import (
"fmt"
"io"
"os"
)
func isErr(e error) {
if e != nil {
fmt.Println("Error: ", e)
os.Exit(1)
}
}
func main() {
args := os.Args[1]
// file implements a Reader interface
file, err := os.Open(args)
isErr(err)
io.Copy(os.Stdout, file)
}
|
package main
import (
"flag"
"fmt"
)
func main() {
var port = flag.Int("port", 8000, "port number to start the server on")
flag.Parse()
// log.SetFlags(log.LstdFlags | log.Lshortfile)
fmt.Println("Starting server on port:", *port)
fmt.Printf("Option myFlag: %T, %d, %d\n", port, port, *port)
}
|
// Copyright 2021 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Package verifier is a framework for running verification function in parallel
// to the actual test with option to re-run verification function in a loop until
// the prim... |
// 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 ip
import (
"context"
"io"
"net"
"os"
"reflect"
"testing"
)
// stubCmdRunner is a simple stub of CmdRunner which always returns the given content
// as comman... |
package lang
import "fmt"
func Run(mod *ModuleVirtual) {
env := makeEnvironment(nil)
mod.environment = env
runBlob(mod, env, *mod.bytecode)
}
func loadModuleEnvironment(mod Module) {
// If the given module has already been evaluated, do nothing.
if mod, ok := mod.(*ModuleVirtual); ok && mod.environment == nil {... |
package main
import (
"bytes"
"encoding/csv"
"fmt"
"go/ast"
"go/format"
"go/token"
"io/ioutil"
"net/http"
"os"
"sort"
"strings"
)
func main() {
const sourceURL = "https://raw.githubusercontent.com/haliaeetus/iso-639/master/data/iso_639-2.csv"
inputData, err := httpGet(sourceURL)
if err != nil {
panic(... |
// Copyright 2021 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 cpu
func (cpu *CPU) clc() {
println("CLC")
cpu.waitTick()
cpu.C = false
}
func (cpu *CPU) cld() {
println("CLD")
cpu.waitTick()
cpu.D = false
}
func (cpu *CPU) cli() {
println("CLI")
cpu.waitTick()
cpu.I = false
}
func (cpu *CPU) clv() {
println("CLV")
cpu.waitTick()
cpu.V = false
}
func (cpu *... |
// Copyright 2022 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package video
import (
"context"
"fmt"
"time"
"chromiumos/tast/ctxutil"
"chromiumos/tast/errors"
"chromiumos/tast/local/chrome"
"chromiumos/tast/local/chrome/browser... |
package game
import (
"time"
"github.com/nsf/termbox-go"
)
// CSnake is color of the snake
const CSnake = termbox.ColorCyan
// PlayState is the game state where the player controls
type PlayState struct {
Width int
Height int
Snake *Snake
Food Food
SinceLastMove time.Duration
MoveThreshold time.Duration... |
package main
import (
"fmt"
"io/ioutil"
"strings"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx"
)
// Database connectivity variables
var db *pgx.ConnPool
var db_err error
//Initialise connection to the database
func init() {
db, db_err = pgx.NewConnPool(pgx.ConnPoolConfig{
ConnConfig: pgx.ConnConfig{
... |
package system
import (
"github.com/libp2p/go-libp2p-core/crypto"
"github.com/libp2p/go-libp2p-core/peer"
"testing"
. "github.com/smartystreets/goconvey/convey"
)
func TestCreateIdentity(t *testing.T) {
Convey("TestCreateIdentity", t, func() {
Convey("return a peerID and a privateKey which should be matched w... |
package kubernetes
import (
"testing"
"github.com/stretchr/testify/assert"
core_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestFilterPodsForEndpoints(t *testing.T) {
assert := assert.New(t)
endpoints := core_v1.Endpoints{
Subsets: []core_v1.EndpointSubset{
{
Address... |
// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package hmacsha512_test
import (
"crypto/hmac"
"crypto/rand"
"crypto/sha512"
"encoding/binary"
"testing"
"github.com/stretchr/testify/require"
"storj.io/common/internal/hmacsha512"
)
// NodeID is a duplicate of storj.NodeID to av... |
package main
import "os"
func main() {
// 我们将在这个网站中使用 panic 来检查预期外的错误。这个 是唯一一个为 panic 准备的例子。
panic("a problem")
// panic 的一个基本用法就是在一个函数返回了错误值但是我们并不知道(或 者不想)处理时终止运行。
// 这里是一个在创建一个新文件时返回异常错误时的 panic 用法。
_, err := os.Create("/tmp/file")
if err != nil {
panic(err)
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.