text stringlengths 11 4.05M |
|---|
package main
import (
"crypto/sha256"
"log"
"os"
"fmt"
)
// Automate the creation of multiple directories
func createDirs(dirNum int, uDir string) {
// Change into a directory, specified by the user
os.Chdir(uDir)
for i := 1; i < dirNum + 1; i++ {
fmt.Print("Enter a directory name: ")
... |
package fs_test
import (
"testing"
"gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs/fstestutil"
"gx/ipfs/QmVGjyM9i2msKvLXwh9VosCTgP4mL91kC7hDmqnwTTx6Hu/sys/unix"
)
type exchangeData struct {
fstestutil.File
// this struct cannot be zero size or multiple instances may look identical
_ int
}
func... |
package 排序
import (
"bytes"
"fmt"
"sort"
)
func minNumber(nums []int) string {
sort.Slice(nums, func(i, t int) bool {
return splice(nums[i], nums[t]) < splice(nums[t], nums[i])
})
return stringfy(nums)
}
func splice(A, B int) string {
return fmt.Sprintf("%d%d", A, B)
}
func stringfy(nums []int) string {
b... |
package sysinfo
import (
"fmt"
"syscall"
)
func init() {
diskUsageImpl = darwinDiskUsage
memInfoImpl = darwinMemInfo
}
func darwinDiskUsage(path string) (*DiskStats, error) {
var stfst syscall.Statfs_t
err := syscall.Statfs(path, &stfst)
if err != nil {
return nil, err
}
free := stfst.Bfree * uint64(stfs... |
package main
import (
"flag"
"fmt"
"log"
"regexp"
"sync"
"time"
irc "github.com/thoj/go-ircevent"
)
var useDebug bool
var app = struct {
cfg *Config
irc *irc.Connection
conversations map[string]*Conversation
mutex sync.Mutex
}{
conversations: map[string]*Conversation{},
}
fun... |
package main
import (
"fmt"
"sort"
)
func solve() {
var n int
fmt.Scanf("%d\n", &n)
nums := []int{}
total := 0
var temp int
for i:=0; i<n; i++ {
fmt.Scanf("%d", &temp)
nums = append(nums, temp)
total += temp
}
// Not really necessary, I could have used sort.Ints, but I wanted to
// le... |
package requests
func (*BaseRequest) EmailRules() []string {
return []string{"required", "min:4", "max:30", "email"}
}
func (*BaseRequest) NameRules() []string {
return []string{"required", "alpha_num", "between:3,20"}
}
func (*BaseRequest) PasswordRules() []string {
return []string{"required", "min:6"}
}
|
package main
// Thanks to the folks behind
// http://www.zytrax.com/tech/survival/ssl.html which helped me make
// sense of x509 certs!
import (
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/asn1"
"encoding/base64"
"encoding/pem"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"log"
"math/big"
"net/htt... |
package service
import (
"consumer-importer/model"
"consumer-importer/service/util"
)
// FileService service responsible for managing File data to the postgres database
type FileService struct {
Props *util.DbProperties
}
//Save store a File object into File database table
func (f *FileService) Save(dto *model.Fi... |
package main
const Version = "0.0.20220316"
|
// SPDX-FileCopyrightText: (c) 2018 Daniel Czerwonk
//
// SPDX-License-Identifier: MIT
package server
import (
"testing"
"time"
bgp "github.com/bio-routing/bio-rd/protocols/bgp/server"
"github.com/bio-routing/bio-rd/routingtable/vrf"
"github.com/bio-routing/bio-rd/routingtable"
bnet "github.com/bio-routing/b... |
package handler_test
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/rafael84/shortener/handler"
"github.com/rafael84/shortener/persistence"
"github.com/rafael84/shortener/service"
)
func TestRecover(t *testing.T) {
service.Storage = persistence.NewMemory()
// a b c ba bb bc ca... |
package schema
import (
"net/url"
"time"
)
// NTP represents the configuration related to ntp server.
type NTP struct {
Address *AddressUDP `koanf:"address" json:"address"`
Version int `koanf:"version" json:"version" jsonschema:"enum=3,enum=4,title=NTP Version" jsonschema_descr... |
package main
import (
"fmt"
"github.com/nak3/go-lvm"
)
func main() {
// List volume group
vglist := lvm.ListVgNames()
availableVG := ""
// Create a VG object
vgo := &lvm.VgObject{}
for i := 0; i < len(vglist); i++ {
vgo.Vgt = lvm.VgOpen(vglist[i], "r")
if vgo.GetFreeSize() > 0 {
availableVG = vglist[i]... |
package handlers
import (
"errors"
"testing"
"github.com/go-webauthn/webauthn/protocol"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/valyala/fasthttp"
"github.com/authelia/authelia/v4/internal/mocks"
"github.... |
package containersnapshot
import (
"context"
stderr "errors"
"os"
"path/filepath"
"strings"
"time"
atomv1alpha1 "github.com/supremind/container-snapshot/pkg/apis/atom/v1alpha1"
"github.com/supremind/container-snapshot/pkg/constants"
"github.com/go-logr/logr"
"github.com/operator-framework/operator-sdk/pkg/... |
package daemon
import (
"fmt"
"log"
"time"
"github.com/reef-pi/rpi/i2c"
"github.com/reef-pi/reef-pi/controller"
"github.com/reef-pi/reef-pi/controller/connectors"
"github.com/reef-pi/reef-pi/controller/drivers"
"github.com/reef-pi/reef-pi/controller/settings"
"github.com/reef-pi/reef-pi/controller/storage"
... |
package nameshake
import (
"encoding/json"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
sdk "github.com/cosmos/cosmos-sdk/types"
abci "github.com/tendermint/tendermint/abci/types"
)
var (
ModuleName = "nameshake"
RouterKey = "nameshake"
)
func NewAppModule(k Keeper) AppModule {
... |
package main
import (
routes "alta/delivery/routes/external"
"alta/pkg/db"
_ "github.com/go-sql-driver/mysql"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
)
type Stock struct {
CompanyCode string
CompanyName string
LastPrice int
}
func main() {
// Initiate echo framework
e := echo.New... |
package service
import (
"context"
"fmt"
"net/http"
"github.com/go-ocf/cloud/cloud2cloud-gateway/store"
"github.com/gorilla/mux"
)
type retrieveDevicesSubscriptionHandler struct {
s store.DevicesSubscription
}
func (c *retrieveDevicesSubscriptionHandler) Handle(ctx context.Context, iter store.DevicesSubscrip... |
package main
import "net/http"
var chttp = http.NewServeMux()
func serveIt(w http.ResponseWriter, r *http.Request) {
chttp.ServeHTTP(w, r)
}
func main() {
chttp.Handle("/", http.FileServer(http.Dir("./")))
http.HandleFunc("/", serveIt)
http.ListenAndServe(":8000", nil)
}
|
package convert
import (
"github.com/ChowRobin/fantim/model/po"
"github.com/ChowRobin/fantim/model/vo"
)
func UserPoToVo(userPo *po.User) *vo.User {
if userPo == nil {
return nil
}
return &vo.User{
UserId: userPo.UserId,
Nickname: userPo.Nickname,
Avatar: userPo.Avatar,
}
}
|
package main
import (
"fmt"
"net/http"
"github.com/labstack/echo/v4"
"go.elastic.co/apm/module/apmechov4"
)
func main() {
e := echo.New()
e.Use(apmechov4.Middleware())
e.GET("/*", func(c echo.Context) error {
route := c.Param("*")
msg := fmt.Sprintf("Hello Kubernetes and Elasticsearch!\nYou've hitted /%... |
package imagekit
import (
"bytes"
"context"
"errors"
"mime/multipart"
"net/url"
"strconv"
"strings"
)
//
// METHODS
//
// ServerUpload uploads file to ImageKit.io.
func (s *UploadService) ServerUpload(ctx context.Context, r *UploadRequest) (*UploadResponse, error) {
if r == nil {
return nil, errors.New("re... |
package main
import (
"github.com/atang152/go_webapp/product"
"github.com/atang152/go_webapp/user"
"net/http"
)
func main() {
// Add route to serve css files
http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir("./static"))))
http.Handle("/favicon.ico", http.NotFoundHandler())
http.Han... |
package resolver
import (
"github.com/taktakty/netlabi/testdata"
"github.com/stretchr/testify/require"
"strconv"
"strings"
"testing"
)
func TestDeviceModelMutations(t *testing.T) {
testData := deviceModelTestData
t.Run("Create", func(t *testing.T) {
p := testdata.DeviceModelParamStruct{
Name: "new test... |
package _020_10_18
func isValid(s string) bool {
if len(s) < 2 {
return false
}
pairs := map[byte]byte{
')': '(',
']': '[',
'}': '{',
}
stack := make([]byte, 0)
for _, b := range []byte(s) {
if len(stack) == 0 || stack[len(stack)-1] != pairs[b] {
stack = append(stack, b)
} else {
stack = stack[... |
package main
import (
"flag"
"fmt"
"net/http"
"net/http/httputil"
"os"
"strings"
"time"
"github.com/TV4/graceful"
"github.com/go-chi/chi"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
const serviceName = "http-proxy"
var (
buildTag = "dev"
httpPort = flag.Int("port", 8080, "HTTP port to lis... |
package datahub
import (
"context"
"errors"
Entities "github.com/containers-ai/alameda/datahub/pkg/entities"
"github.com/containers-ai/alameda/pkg/utils/log"
"github.com/containers-ai/api/alameda_api/v1alpha1/datahub"
"github.com/grpc-ecosystem/go-grpc-middleware/retry"
"google.golang.org/grpc"
"reflect"
"tim... |
package gcs
import (
"bitbucket.org/inehealth/idonia-pacs/service/idonia/idonia-core"
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"mime/multipart"
"net/http"
"strconv"
"strings"
)
func UploadFile(file []byte, name string, policy *idonia_core.GetPolicyRes) (err error) {
body := new(bytes.Buffer)
writer := mult... |
package util
import (
"bufio"
"errors"
"fmt"
"net"
"os"
)
const procNetRoute = "/proc/net/route"
func getDefaultRoute() (*DefaultRouteInfo, error) {
if routeTable, err := GetRouteTable(); err != nil {
return nil, err
} else if routeTable.DefaultRoute == nil {
return nil, errors.New("could not find default... |
package logging
// Log Format values.
const (
FormatText = "text"
FormatJSON = "json"
)
// Log Level values.
const (
LevelTrace = "trace"
LevelDebug = "debug"
LevelInfo = "info"
LevelWarn = "warn"
LevelError = "error"
)
// Field names.
const (
FieldRemoteIP = "remote_ip"
FieldMethod = "method"
Fiel... |
/*
Copyright 2019 The MayaData 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
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, s... |
// Copyright © 2022 IN2P3 Computing Centre, IN2P3, CNRS
// Copyright © 2018 Philippe Voinov
//
// Contributor(s): Remi Ferrand <remi.ferrand_at_cc.in2p3.fr>, 2021
//
// This software is governed by the CeCILL license under French law and
// abiding by the rules of distribution of free software. You can use,
// modify... |
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package templates
const GenerateEndpoint = `
{{- /* . (dot) refers to a string which is the endpoint's name */ -}}
{{- define "GenerateEndpoint" -}}
{{- ... |
package nes
import "encoding/gob"
type Cartridge struct {
PRG []byte // PRG-ROM banks
CHR []byte // CHR-ROM banks
SRAM []byte // Save RAM
Mapper byte // mapper type
Mirror byte // mirroring mode
Battery byte // battery present
}
func NewCartridge(prg, chr []byte, mapper, mirror, battery byte... |
package day6
import (
"testing"
)
const part1Answer = 251208
const part2Answer = 397
func TestPart1(t *testing.T) {
tree, err := readTree("../../input/6.txt")
if err != nil {
t.Fatal("Could not open tree", err)
}
answer := part1(&tree)
if part1Answer != answer {
t.Errorf("part1(input) == %d, want %d", ans... |
package main
import (
"flag"
)
// ServerParams represents required for launch params
type ServerParams struct {
Port int
Domain string
Debug bool
Verbose bool
}
// ParseFlags parse commandline params
func ParseFlags() *ServerParams {
// Parse command line arguments
var (
domain string
port int
... |
package main
import "fmt"
func test() {
ages := map[string]int{
"alice": 31,
"charlie": 34,
}
ages["alice"] = 31
ages["charlie"] = 34
// 创建一个空map
ages = map[string]int{}
//使用delete函数从字典中删除一个元素
delete(ages, "alice")
// 即使键不存在 删除操作也是安全的
// map使用给定的键来查找元素
// 如果对应的元素不存在 则返回类型的零值
//map不是一个变量 因此不能获取他的地址... |
package gitConnector
import (
"bytes"
"encoding/json"
"fmt"
"github.com/sixleaveakkm/AWSGitHook/src/hookEvent"
"io/ioutil"
"net/http"
"net/url"
"os"
"strings"
)
type TokenResponse struct {
AccessToken string `json:"access_token"`
Scopes string `json:"scopes"`
ExpiresIn int `json:"expires_in"`... |
package usecase
import (
"fmt"
"chatserver/pkg/domain"
"chatserver/pkg/lib/config"
)
type Order struct {
UserID int `json:"user_id"`
Quantity int `json:"quantity"`
ProductID int `json:"product_id"`
}
type OrderUsecase struct {
cfg config.Config
od domain.OrderDomain
ud domain.UserDomain
}
func InitO... |
package 待分类
import (
"fmt"
"os"
)
var path string
func main() {
f := DirInput()
if f != nil {
fInfo, err := f.Stat() //获取FileInfo
if err != nil {
fmt.Printf("main-001\t%v\n", err)
} else if fInfo.IsDir() {
fun1(f)
}
f.Close()
}
}
func DirInput() *os.File {
//用户交互,获取目录路径
fmt.Print("请输入要遍历目录... |
package accmanager_test
import(
"testing"
"manager/accmanager"
//"fmt"
)
func Test_FiManager_Process(t *testing.T){
m := accmanager.NewFiManager()
m.ClearDB()
m.Process()
}
|
package sortByBits
import "sort"
type slice []int
func (s slice) Len() int { return len(s) }
func (s slice) Swap(i, j int) { s[i], s[j] = s[j], s[i] }
func (s slice) Less(i, j int) bool {
bitsI := getBits(s[i])
bitsJ := getBits(s[j])
if bitsI < bitsJ {
return true
} else if bitsI == bitsJ {
return s[i] ... |
package main
import (
"io"
"log"
"net/http"
"os"
)
func main() {
http.HandleFunc("/", serveIndexHTML)
http.HandleFunc("/tody.jpg", serveTodyPicture)
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatalln(err)
}
}
func serveIndexHTML(res http.ResponseWriter, req *http.Request) {
res.Header(... |
/*
An undulant number is a number where its digits alternate between up and down like the following number: 461902 or 708143, or even 1010101, but not 123, because 2 < 3.
Write a program or function which returns a truthy value if a number is undulant, and a falsy value otherwise. The shortest code wins.
Note: Singl... |
package controllers
import (
"github.com/astaxie/beego"
"github.com/yydzero/surf/weichat"
"github.com/yydzero/surf/weichat/api"
"sync"
"time"
"github.com/yydzero/cherry/models"
"github.com/astaxie/beego/orm"
"log"
)
type CrawlController struct {
CherryController
}
// Signup will register new user
// TODO: p... |
// Copyright 2020-present Kuei-chun Chen. All rights reserved.
package keyhole
import (
"go.mongodb.org/mongo-driver/bson"
)
const (
kb = 1024
mb = kb * kb
gb = kb * mb
tb = kb * gb
)
// Stringify returns JSON string
func Stringify(doc interface{}) string {
data, err := bson.MarshalExtJSON(doc, false, false)
... |
package matcher
import (
"fmt"
"log"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMatcherError(t *testing.T) {
_, err := New(&Options{
RoutesFile: "",
})
assert.Error(t, err)
}
func TestMacherTestSetHeaders(t *testing.T) {
routesFile, err := filepath.Abs("./testdata/routes.es... |
package common_test
import (
"encoding/json"
"fmt"
"github.com/APTrust/exchange/constants"
"github.com/APTrust/exchange/network"
"github.com/APTrust/exchange/partner_apps/common"
"github.com/APTrust/exchange/util/fileutil"
"github.com/aws/aws-sdk-go/service/s3"
"github.com/stretchr/testify/assert"
"github.com... |
package main
import "os"
// TODO: 動的に関数名を生成してチェックできるようにする
func add2() int
func main() {
i := add2()
os.Exit(i)
} |
// 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 movie
import (
"log"
)
const (
REGULAR = iota //0
NEW_RELEASE //1
CHILDREN // 2
)
type Movie struct {
title string //片名
//priceCode int //价格代号
price Pricer
}
func (m *Movie) Init(title string, priceCode int) {
m.title = title
m.SetPriceCode(priceCode)
}
func ... |
package testsuite
import (
"context"
"testing"
"time"
"go.mercari.io/datastore/v2"
)
var _ datastore.PropertyLoadSaver = &dataPLS{}
var _ datastore.KeyLoader = &dataKL{}
type dataPLS struct {
Name string
LoadCount int
CreatedAt time.Time
}
func (d *dataPLS) Load(ctx context.Context, ps []datastore.Prop... |
package main
import (
"html/template"
"log"
"net/http"
"os"
"path/filepath"
)
var templates map[string]*template.Template
func init() {
if templates == nil {
templates = make(map[string]*template.Template)
}
basePath, _ := os.Getwd()
templatesDir := basePath + "/tmpl/"
layouts, err := filepath.Glob(templ... |
package leetcode
func fib(N int) int {
a, b := 0, 1
fib_ary := make([]int, 31)
for i := 0; i <= 30; i++ {
fib_ary[i] = a
a, b = b, a+b
}
return fib_ary[N]
}
|
package flow
import (
"context"
"errors"
"github.com/direktiv/direktiv/pkg/refactor/core"
"github.com/direktiv/direktiv/pkg/refactor/filestore"
"github.com/google/uuid"
)
func (flow *flow) placeholdSecrets(ctx context.Context, tx *sqlTx, nsID uuid.UUID, file *filestore.File) error {
rev, err := tx.FileStore().... |
package main
import (
"image"
"testing"
)
func TestCorrectThumbnailScaling(t *testing.T) {
srcImage := image.NewRGBA(image.Rect(0, 0, 1200, 200))
srcRectangle := srcImage.Bounds()
dstRectangle, err := computeDstBounds(srcRectangle, THUMBNAIL)
if err != nil {
t.Errorf("failed to convert: %s", err)
}
if dst... |
package database
import (
"gdemost/config"
"gdemost/models"
_ "github.com/go-sql-driver/mysql"
"github.com/jinzhu/gorm"
"log"
"sync"
)
type dataProvider struct {
db *gorm.DB
}
var once sync.Once
var DataInstance *dataProvider
func init() {
println("Hello bridges db!")
newDB := getDB(config.DbString)
on... |
// Copyright 2019 Google 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
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in ... |
package project
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os"
"path"
"strconv"
"strings"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
docker "github.com/docker/docker/client"
"github.com/ubclaunchpad/inertia/daemon/inertiad/containers"
"github.com/ubclaunchpa... |
package models
import (
"github.com/jinzhu/gorm"
)
// CategoryRating model
type CategoryRating struct {
gorm.Model
Communication float32 `sql:"DEFAULT:0.00"`
Expertise float32 `sql:"DEFAULT:0.00"`
Quality float32 `sql:"DEFAULT:0.00"`
HireAgain float32 `sql:"DEFAULT:0.00... |
package main
import (
"encoding/json"
"flag"
"fmt"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"io"
"log"
"net/http"
"os"
)
type connection struct {
ws *websocket.Conn
send chan []byte
q *qcl
}
func (c *connection) reader() {
for message := range c.send {
err := c.ws.WriteMessage(webs... |
package main
import (
"fmt"
"reflect"
)
type student struct{}
func reflectType(x interface{}) {
v := reflect.TypeOf(x)
fmt.Printf("type:%v\n", v)
}
func main() {
var a float32 = 3.14
reflectType(a) //type:float32
var b int64 = 100
reflectType(b) //type:int64
var c = student{}
//TypeOf 获取的时type name,想获取底层类... |
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-2019 Datadog, Inc.
package comparison
import "testing"
func TestGenerateHashFromEDSResourceNo... |
package main
import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
"encoding/gob"
"encoding/hex"
"encoding/json"
"fmt"
"log"
"math/big"
"time"
"github.com/btcsuite/btcutil/base58"
)
// GenesisRewards 100
const (
GenesisRewards = 100 // 1 lubit = 1 * 10^6 发
GenesisAuthor = ... |
package stockwork
import (
"encoding/csv"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
"strings"
"github.com/natefinch/lumberjack"
"github.com/sirupsen/logrus"
)
//::::::::::::::::::::::::::::::::::::::::::::::::::::::: DEFINE
var path_watch_list strin... |
package models
import (
"errors"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
"log"
"os"
"strconv"
"strings"
)
type Printer struct {
ID string
Manufacturer string
Model string
Description string
InWork bool
Barcode string
CurrentLocation string
HistoryL... |
package config
import (
"fmt"
"github.com/codegangsta/inject"
"github.com/phillihq/racoon/config/gather"
"github.com/phillihq/racoon/util"
)
type OutputContextConfig interface {
ContextConfig
Send(gather.GatherData) (err error)
}
//输出配置
type OutputConfig struct {
StandardConfig
}
type OutputHandler interface... |
package image
import (
"bytes"
"context"
"github.com/pkg/errors"
"io"
"io/ioutil"
"net/http"
)
type Downloader interface {
Download(url string, ctx context.Context) (io.Reader, error)
}
type DownloadFunc func(url string, ctx context.Context) (io.Reader, error)
func (df DownloadFunc) Download(url string, ctx ... |
package skpsilk
// silk/src/SKP_Silk_decode_pitch.go
func decode_pitch(lagIndex, contourIndex int, pitch_lags []int, Fs_kHz int) {
min_lag := int(SMULBB(PITCH_EST_MIN_LAG_MS, int32(Fs_kHz)))
lag := min_lag + lagIndex
if Fs_kHz == 8 {
for i := 0; i < PITCH_EST_NB_SUBFR; i++ {
pitch_lags[i] = lag + CB_lags_st... |
package main
import (
"io/ioutil"
"log"
"os"
"os/user"
"path/filepath"
"strconv"
"strings"
)
type Ranking struct {
scores []int
}
func NewRanking() *Ranking {
ranking := new(Ranking)
ranking.scores = make([]int, 10)
if fileExists(configFilePath()) {
buf, err := ioutil.ReadFile(configFilePath())
if er... |
// Copyright 2019 The go-interpreter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package compile
type dirtyState uint8
const (
stateScratch dirtyState = iota // We don't care about the value.
stateStackLen ... |
package main
import "fmt"
// QuickFind represents the eager approach for the Union-Find dynamic connectivity problem
type QuickFind struct {
ids []int
}
// ErrNotPositiveN used to handle when N is not a positive number
var ErrNotPositiveN = fmt.Errorf("N must be a positive number")
// NewQuickFind set id of each o... |
package diskstore
import (
"github.com/peterbourgon/diskv"
"fmt"
"os"
"encoding/json"
"github.com/pkg/errors"
logger "github.com/Sirupsen/logrus"
)
var DataDir string = fmt.Sprintf("%s/igrb-data", os.TempDir())
type DiskPersistor struct {
diskv *diskv.Diskv
}
func NewDiskPersistor() DiskPersistor {
flatTran... |
package proxy
import (
"log"
"net/http"
)
// Proxy holds our configured client
// and BaseURL to proxy to
type Proxy struct {
Client *http.Client
BaseURL string
}
// ServeHTTP means that proxy implments the Handler interface
// It manipulates the request, forwards it to BaseURL, then returns
// the response
fun... |
package drm
/*
[ModeFbDirtyCmd]
Mark a region of a framebuffer as dirty.
Some hardware does not automatically update display contents
as a hardware or software draw to a framebuffer. This ioctl
allows userspace to tell the kernel and the hardware what
regions of the framebuffer have changed.
The kernel or hard... |
// Copyright 2019, OpenTelemetry 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 ag... |
package main
import (
"flag"
"io/ioutil"
"log"
"net/http"
"strings"
)
func main() {
var url string
flag.StringVar(&url, "server_url", "http://localhost:3000", "flag to describe testServer")
resp, err := http.Get(url)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(... |
package main
// Sum gets a slice of numbers and returns their sum.
func Sum(numbers []int) int {
var r int
for _, n := range numbers {
r = r + n
}
return r
}
// SumAll gets a variable number of slices of numbers
// and returns the sum for each slice
func SumAll(slices ...[]int) []int {
var r []int
for _, s :=... |
//
// Copyright 2020 The AVFS 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 ag... |
package mira
import (
"encoding/json"
"net/http"
"github.com/thecsw/mira/models"
)
// Compose will send a message to next redditor.
func (c *Reddit) Compose(subject, text string) error {
name, _, err := c.checkType(redditorType)
if err != nil {
return err
}
target := RedditOauth + "/api/compose"
_, err = c... |
// DO NOT EDIT. This file was generated by "github.com/frk/gosql".
package testdata
import (
"github.com/frk/gosql"
"github.com/frk/gosql/internal/testdata/common"
)
func (q *SelectWithRecordNestedSliceQuery) Exec(c gosql.Conn) error {
const queryString = `SELECT
n."foo_bar_baz_val"
, n."foo_baz_val"
, n."foo2... |
package database
import (
. "challenge-SmartMEI/database/models"
)
type Database interface {
Collection(name string) (Collection, error)
}
type Collection interface {
CreateUser(data User) (*User, error)
AddBookToMyCollection(user User, data Book) (*Book, error)
LendBook(fromUser User, toUser User, data BookLoa... |
package service
import (
"context"
"time"
"github.com/golang/protobuf/ptypes/wrappers"
pb "github.com/johnbellone/persona-service/internal/gen/persona/api/v1"
"github.com/johnbellone/persona-service/internal/server"
"github.com/pascaldekloe/jwt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)... |
package day15
import (
"fmt"
"strconv"
"strings"
)
func Run(lines []string) error {
splat := strings.Split(lines[0], ",")
numbers := make([]int, 0, len(splat))
for _, s := range splat {
num, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("invalid number '%s'", s)
}
numbers = append(numbers,... |
package service
import (
"encoding/hex"
"encoding/json"
"fmt"
"math/big"
"strconv"
"walletApi/src/common"
"walletApi/src/model"
"github.com/beego/i18n"
"github.com/astaxie/beego"
)
type Result struct {
Status string `json:"status"`
Msg string `json:"msg"`
Data string `json:"data"`
}
func parseResu... |
// Copyright 2019 tree xie
//
// 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 wri... |
/*
Copyright 2019 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, ... |
/*
Copyright (C) 2016 Red Hat, 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, softwa... |
package account
import (
"net/http"
"qutils/dbwrapper"
)
const (
TABLENAME = "accounts"
APIPREFIX = "account"
)
var connection *dbwrapper.DBConnection = nil
//Initialize module to be able work with db.
//Required to work
func Init(conn *dbwrapper.DBConnection) {
connection = conn
}
func ExportedHandlers() map... |
package kafka100
import "github.com/golang/protobuf/proto"
//上线扩展类型定义
type ONLINE_EXT_TYPE int32
const (
ONLINE_EXT_TYPE_UNKNOWN ONLINE_EXT_TYPE = 0
ONLINE_EXT_TYPE_DATAMGR ONLINE_EXT_TYPE = 1
ONLINE_EXT_TYPE_SIGNAL ONLINE_EXT_TYPE = 2
ONLINE_EXT_TYPE_POWER ONLINE_EXT_TYPE = 3
ONLINE_EXT_TYPE_SCREEN ONLINE_... |
package model
import (
"encoding/json"
"io"
)
type Note struct {
ID uint `json:"id"`
Title string `json:"title"`
Detail string `json:"detail"`
}
func (n *Note) FromJSON(r io.Reader) error {
e := json.NewDecoder(r)
return e.Decode(n)
}
|
package models
type Message struct {
MessageTitle string `json:"messagetitle"`
}
|
package restore
import (
"context"
"os"
"os/exec"
"strconv"
"strings"
"github.com/facebook/fbthrift/thrift/lib/go/thrift"
"github.com/monadbobo/br/pkg/config"
"github.com/monadbobo/br/pkg/nebula"
"github.com/monadbobo/br/pkg/nebula/meta"
"github.com/monadbobo/br/pkg/ssh"
"github.com/monadbobo/br/pkg/storag... |
/*
* @lc app=leetcode.cn id=867 lang=golang
*
* [867] 转置矩阵
*/
package main
// @lc code=start
func transpose(matrix [][]int) [][]int {
if len(matrix) == len(matrix[0]) {
for i := 0; i < len(matrix); i++ {
for j := i + 1; j < len(matrix); j++ {
matrix[i][j], matrix[j][i] = matrix[j][i], matrix[i][j]
}
... |
package kci
import (
"testing"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestFinalizers(t *testing.T) {
md := metav1.ObjectMeta{}
addString1 := "db.test1"
addString2 := "db.test2"
addString3 := "db.test3"
AddFinalizer(&md, addString1)
finalizers := md.GetFina... |
package array
// MakeSlice returns []int with length and capacity
func MakeSlice(length, capacity byte) (output []int) {
output = make([]int, length, capacity)
return
}
|
// Copyright Jetstack Ltd. See LICENSE for details.
package instanceToken
import (
"path/filepath"
vault "github.com/hashicorp/vault/api"
"github.com/sirupsen/logrus"
)
const FlagInitRole = "init-role"
const FlagConfigPath = "config-path"
type InstanceToken struct {
token string
initRole strin... |
package sphere
import (
"github.com/go-gl/mathgl/mgl32"
"github.com/akosgarai/opengl_playground/pkg/primitives/material"
trans "github.com/akosgarai/opengl_playground/pkg/primitives/transformations"
"github.com/akosgarai/opengl_playground/pkg/vao"
)
const (
DRAW_MODE_COLOR = 0
DRAW_MODE_LIGHT = 1
)
type Shade... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.