text stringlengths 11 4.05M |
|---|
package e
import (
"fmt"
)
func Hello() {
fmt.Println("E v1.3.0")
}
|
package main
import (
"fmt"
ar "github.com/Axect/Numeric/array"
ss "github.com/Axect/Numeric/stats"
)
// Vector is type alias
type Vector = ar.Vector
func main() {
X := ss.NormalDist(2, 1, 100000)
Y := ss.NormalDist(5, 3, 100000)
C := ss.CovMatrix(X, Y)
R := ss.Cor(X, Y)
ar.MatrixForm(C)
fmt.Println(R)
D... |
package pipelines
import (
"encoding/json"
"fmt"
"log"
"strings"
"time"
"github.com/bosh-io/worker/src/worker/releases"
"github.com/concourse/concourse/atc"
)
type OrgPipeline struct {
name string
pipeline *atc.Config
}
func NewOrgPipeline(name string) *OrgPipeline {
return &OrgPipeline{
name: name,... |
package main
func findMin(nums []int) int {
l, r := 0, len(nums)-1
for l <= r {
// 上面的条件判断可以写为 l < r,之后在函数体外返回 nums[l]就可以了,但是我习惯了l<=r,所以就在
// 函数体里面判断了。
if l == r {
return nums[l]
}
mid := (l + r) / 2
// 由于数组没有重复元素,num[r] == nums[mid] 时表示扫描区域只有一个元素了()
if nums[r] == nums[mid] {
// 这句不会被执行到,只是为了符合结构... |
package algorithms_test
import (
"github.com/devinschulz/experiments/algorithms/search"
"testing"
)
var tests = []struct {
searchKey int
result int
}{
{90, 4},
{100, 5},
{250, 8},
{180, 7},
{0, -1},
{101, -1},
{10000, -1},
}
func TestBinarySearch(t *testing.T) {
searchList := []int{10, 15, 25, 45, 90,... |
package main
// Problem:
// Take an array of integers. Consider it as describing a histogram or set of
// adjacent blocks.
// Imagine pouring water into the top of the graph; find the area filled by the
// water:
// 4 2 1 3:
// //
// // >> // XX XX // >> answer is "3 units contained by bou... |
package database
import (
"fmt"
"gorm.io/driver/postgres"
"gorm.io/gorm"
)
// initPostGreSql: Initialise Postgresql DBHandle
func (db *Database) initPostGreSql() (err error) {
url := fmt.Sprintf(
"host=%s port=%s user=%s dbname=%s sslmode=disable password=%s",
db.Config["DB_HOST"], db.Config["DB_PORT"], db.Co... |
package zlog
import (
"bytes"
"path"
"path/filepath"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
var timestamp int64
var timeStr string
var mu sync.Mutex
type MultLogger map[string]*Zlog
type Zlog struct {
Origin *zap.Logger
log *zap.Logger
At... |
package slackevents
import (
"crypto/subtle"
"encoding/json"
"errors"
"fmt"
"reflect"
"github.com/slack-go/slack"
)
// eventsMap checks both slack.EventsMapping and
// and slackevents.EventsAPIInnerEventMapping. If the event
// exists, returns the unmarshalled struct instance of
// target for the matching even... |
package sset
import (
"sync"
"github.com/parthdesai/sset/internals"
)
const levelJumpProbability = 0.5 // 1/2 probability of level jump
const maxLevels = 32 // log n distribution, so 2^32
const minKey = 0
// SortedSet struct represent sorted set abstract data structure
// Under the hood, it uses skipl... |
package main
import (
"bufio"
"encoding/csv"
"flag"
"fmt"
"html/template"
"io"
"log"
"math/rand"
"os"
"strconv"
"time"
)
// Input is an input in a recipe (basically an ingredient)
type Input struct {
Name string
category string
calories float32
Quantity float32
Unit st... |
package handlers_test
import (
"bytes"
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"strings"
"github.com/pivotal-cf-experimental/envoy/domain"
"github.com/pivotal-cf-experimental/envoy/internal/handlers"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
type Binder struct {
WasCalled ... |
package beego2
import (
"bytes"
"errors"
"net/http"
"net/url"
"strings"
"github.com/GoAdminGroup/go-admin/adapter"
gctx "github.com/GoAdminGroup/go-admin/context"
"github.com/GoAdminGroup/go-admin/engine"
"github.com/GoAdminGroup/go-admin/modules/config"
"github.com/GoAdminGroup/go-admin/modules/constant"
... |
package main
import ()
type SeriesState int
//Not always loaded series data once db open
const (
S_NOTLOADED SeriesState = iota
S_NEW
S_LOADED
)
type Static struct {
Time int64
Value float64
}
type SeriesMeta struct {
Ref uint64
Relations []uint64
Statics []Static //min,max,sum,avg
Count int64... |
package trip
import (
"context"
"errors"
"fmt"
"strconv"
"strings"
"time"
"github.com/radekwlsk/go-travel/utils"
"googlemaps.github.io/maps"
)
var ErrZeroResults = errors.New("google maps API query returned no result")
type PlaceConfig struct {
Priority int `json:"priority,omitempty"`
StayDura... |
package main
import (
"log"
"os"
"github.com/go-redis/redis"
)
var redisClient *redis.Client
func stackInit() {
log.Println("Start redis")
redisClient = redis.NewClient(&redis.Options{
Addr: os.Getenv("REDIS_HOST"),
Password: os.Getenv("REDIS_PASSWORD"),
DB: 0,
})
if _, err := redisClient.P... |
package types
import (
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"
"github.com/cosmos/cosmos-sdk/x/ibc/04-channel/exported"
channelkeeper "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/keeper"
)
type PacketSender interface {
SendPacket(
ctx sdk.Con... |
// SPDX-License-Identifier: Apache-2.0
// Copyright © 2019-2020 Intel Corporation
package af
import (
"context"
"net/http"
"strings"
"github.com/gorilla/mux"
)
// DefaultNotifURL const
const DefaultNotifURL = "/af/v1/notifications"
type keyType string
// Route struct
type Route struct {
Name string
M... |
package config
const (
TEMP_PATH = "temp/"
TTS_TEMP_PATH = "temp/tts/"
TTS_SERVER_API = "http://fsociety.ink/api/v1/tts"
)
|
// Copyright 2017 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package sources
import (
"fmt"
"github.com/OWASP/Amass/amass/core"
"github.com/OWASP/Amass/amass/utils"
)
// ThreatCrowd is data source object type that implements ... |
package nmsrc
import (
"github.com/Centny/gwf/util"
"github.com/Centny/nms/nmsdb"
_ "github.com/Centny/nms/test"
"testing"
"time"
)
func TestRc(t *testing.T) {
var nms_s = NewNMS_S(":8323", "../nmstask", "abc")
var err = nms_s.L.Run()
if err != nil {
t.Error(err.Error())
return
}
var nms_c = NewNMS_C(":... |
package humanreltime
import (
"fmt"
"strings"
"time"
)
type Resolution uint8
const (
Years Resolution = iota
Weeks
Days
Hours
Minutes
Seconds
)
var Resolutions = []Resolution{Years, Weeks, Days, Hours, Minutes, Seconds}
const (
secYear = 60 * 60 * 24 * 365
secWeek = 60 * 60 * 24 * 7
secDay = 60 ... |
package light
import (
"testing"
"github.com/go-gl/mathgl/mgl32"
)
var (
DefaultLightPosition = mgl32.Vec3{0, 0, 0}
DefaultLightDirection = mgl32.Vec3{0, 1, 0}
DefaultAmbientComponent = mgl32.Vec3{1, 1, 1}
DefaultDiffuseComponent = mgl32.Vec3{0.2, 0.2, 0.2}
DefaultSpecularComponent = mgl32.Vec3{0.4, ... |
// Copyright (c) Authors of Clover
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Apache License, Version 2.0
// which accompanies this distribution, and is available at
// http://www.apache.org/licenses/LICENSE-2.0
package clovisor
import (
"en... |
package aws
import (
"github.com/openshift/installer/pkg/ipnet"
)
var (
// ValidRegions is a map of the known AWS regions. The key of the map is
// the short name of the region. The value of the map is the long name of
// the region.
ValidRegions = map[string]string{
"ap-northeast-1": "Tokyo",
"ap-northeast-... |
package telemetry
import (
"testing"
"time"
"github.com/reef-pi/reef-pi/controller/storage"
)
func TestEmitMetric(t *testing.T) {
store, err := storage.TestDB()
if err != nil {
t.Fatal(err)
}
tele := TestTelemetry(store)
tele.EmitMetric("test", "foo", 1.23)
tele.config.Throttle = 2
sent, err := tele.Aler... |
package main
import (
"arep/api"
"arep/config"
"arep/controller"
"arep/repository"
"arep/service"
"log"
)
func main() {
mongoRepository, err := repository.NewMongoRepository(config.GetMongoConfig())
if err != nil {
log.Fatal("Can not connect with MongoDB")
}
log.Print("connection success with MongoDB")
e... |
package kcp
import (
"io"
"sync"
"time"
"github.com/v2ray/v2ray-core/common/alloc"
)
type ReceivingWindow struct {
start uint32
size uint32
list []*DataSegment
}
func NewReceivingWindow(size uint32) *ReceivingWindow {
return &ReceivingWindow{
start: 0,
size: size,
list: make([]*DataSegment, size),... |
package service
import (
"errors"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/suite"
"github.com/taufanmahaputra/forex/pkg/repository"
"github.com/taufanmahaputra/forex/pkg/service"
mock "github.com/taufanmahaputra/forex/test/pkg/repository"
"testing"
)
ty... |
package db
import (
"context"
"time"
"github.com/rodzy/flash/models"
"go.mongodb.org/mongo-driver/bson"
)
//InsertFollower func charges the new follower to the database
func InsertFollower(f models.Follower) (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()... |
/*
Copyright (C) 2018 Black Duck Software, Inc.
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version... |
package app
import (
"net"
"net/http"
"time"
)
const dialTimeout = 3 * time.Second
const tlsHandshakeTimeout = 3 * time.Second
const requestTimeout = time.Second * 10
// New - returns the singleton http app used for stapi requests
func createHttpClient() *http.Client {
var netTransport = &http.Transport{
DialC... |
package amqp
import (
"context"
"errors"
"github.com/streadway/amqp"
"github.com/utilitywarehouse/go-pubsub"
)
var _ pubsub.MessageSource = (*messageSource)(nil)
type messageSource struct {
consumergroup string
topic string
address string
}
type MessageSourceConfig struct {
ConsumerGroup stri... |
package service
import "github.com/google/wire"
var (
ProviderSet = wire.NewSet(NewBlackJackService)
)
|
package util
type GenerateUUID interface {
}
|
package controllers
import (
"marketplace-api/application/base"
)
type TransactionController struct {
base.BaseController
}
|
package main
import (
"fmt"
"math"
"reflect"
)
func main() {
x := 3
fmt.Println("O tipo de x eh", reflect.TypeOf(x))
// sem sinal = apenas positivos
var b byte = 255
fmt.Println("O byte e", reflect.TypeOf(b)) //uint8
i1 := math.MaxInt64
fmt.Println("O valor maximo do int eh", i1)
s1 := "Olá meu nome é Y... |
package main
import (
"flag"
"log"
"net"
"os"
"time"
)
var conn *net.UDPConn
var done chan bool
func reply(addr *net.UDPAddr, idx int) {
dur := time.Duration(idx) * time.Second
log.Printf("%d: Sleeping %d[sec]", idx, idx)
//dur := time.Duration(idx) * time.Minute
//log.Printf("%d: Sleeping %d[min]", idx, id... |
// resources : https://www.digitalocean.com/community/tutorials/how-to-use-the-flag-package-in-go
// displays the first several lines of a given file:
// run the file : go run head.go -- filename
// ex : go run head.go -- boolean.go
package main
import (
"bufio"
"flag"
"fmt"
"io"
"os"
)
func main() {
var count ... |
package event
import (
"errors"
"fmt"
"qipai/dao"
"qipai/model"
"reflect"
"strings"
)
type EventType string
const (
RoomJoin EventType = "RoomJoin"
PlayerSitDown EventType = "PlayerSitDown"
RoomExit EventType = "RoomExit"
RoomList EventType = "RoomList"
RoomCreate EventType = "RoomCreate... |
package main
// Expense stores the information for an expenditure
type Expense struct {
name string
category string
amount float32
}
// CreateExpense takes in the arguments to create an expense
// returns a pointer to the created object
func CreateExpense (name string, category string, amount floa... |
package objects
import (
"bytes"
"context"
"errors"
"fmt"
"log"
"strconv"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
"github.com/spf13/viper"
)
type Entry struct {
Bucketname string
Key string
Urlval string
Sha1val string
Jld string
}
// Set up m... |
package main
import (
"fmt"
"github.com/mndrix/tap-go"
rspec "github.com/opencontainers/runtime-spec/specs-go"
"github.com/opencontainers/runtime-tools/cgroups"
"github.com/opencontainers/runtime-tools/validation/util"
)
func main() {
t := tap.New()
t.Header(0)
defer t.AutoPlan()
pageSizes, err := cgroups.G... |
// Copyright 2016 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... |
// Copyright 2020, Jeff Alder
//
// 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 a... |
/*
# -*- coding: utf-8 -*-
# @Author : joker
# @Time : 2020-07-21 09:21
# @File : _82_Remove_Duplicates_from_Sorted_List_II.go
# @Description : 有重复的元素就直接全部删除了,可能存在删除头节点的情况,所以需要引入dummyNode
并且是重复的都不能存在,所以需要 知道 当前节点,next 节点和 next.next节点
# @Attention :
唯一需要注意的就是小心头结点会被删除
*/
package v0
func deleteDuplicates(head *ListN... |
package internal
import "encoding/base64"
// Encode data into base64
func Encode(src []byte) []byte {
dst := make([]byte, base64.StdEncoding.EncodedLen(len(src)))
base64.StdEncoding.Encode(dst, src)
return dst
}
// Decode base64 back into bytes
func Decode(src []byte) ([]byte, error) {
dst := make([]byte, base... |
package main
import (
"fmt"
)
func test() {
var nilai1 int = 10
var penunjuk1 = &nilai1
var penunjuk2 = &penunjuk1
var penunjuk3 = &penunjuk2
fmt.Println("=======================================")
fmt.Println("Nilai 1 ", nilai1)
fmt.Println("Lokasi variabel nilai 1 ", penunjuk1)
fmt.Println("Lokasi variabel ... |
package main
import (
"fmt"
"math"
)
func main() {
fmt.Println(rampartDefensiveLine([][]int{{1, 2}, {7, 8}, {10, 13}, {18, 19}, {24, 26}, {29, 31}, {34, 39}, {43, 51}, {52, 57}, {63, 68}, {69, 73}, {75, 76}, {77, 78}, {80, 82}, {85, 91}, {105, 109}, {118, 123}, {130, 133}, {134, 146}, {154, 160}, {164, 165}, {178... |
package database_test
import (
"testing"
db "github.com/motonary/Fortuna/database"
)
func TestGetUserByName(t *testing.T) {
user, err := db.GetUserBy("name", "ririco")
if err != nil {
t.Fatalf("unexpected error occured: %v\n", err)
}
if user.Name != "ririco" {
t.Fatalf("user name not matched\n")
}
}
fun... |
package e2e
import (
"context"
"fmt"
"time"
"github.com/blang/semver/v4"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
operatorsv1 "github.com/operator-framework/api/pkg/operators/v1"
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/operator-framework/operat... |
package services
import (
"github.com/iino123/golang-microservices/src/api/config"
"github.com/iino123/golang-microservices/src/api/domain/github"
"github.com/iino123/golang-microservices/src/api/domain/repositories"
"github.com/iino123/golang-microservices/src/api/log/option_b"
"github.com/iino123/golang-microse... |
package main
import "fmt"
//import "math"
import "time"
func main(){
i:=2;
// simple switch
switch i {
case 1:
fmt.Println(" one ")
case 2:
fmt.Println( " two")
case 3:
fmt.Println("three")
}
// you can seperate multiple conditions in case using a comma
// using default as well
switch time.Now().Week... |
package PDU
import (
"github.com/andrewz1/gosmpp/Exception"
"github.com/andrewz1/gosmpp/PDU/Common"
"github.com/andrewz1/gosmpp/Utils"
)
type IPDUHeader interface {
GetSequenceNumber() uint32
SetSequenceNumber(seq uint32)
GetCommandId() uint32
SetCommandId(cmdId uint32)
GetCommandLength() uint32
SetCommandLe... |
package models
import (
"backend/models"
"golang.org/x/crypto/bcrypt"
)
type User struct {
ID int `gorm:"primary_key"`
Username string
PasswordDigest string
Nickname string
Status string
Mobile string
Role string
Avatar string `gorm:"size:1000"`
Sup... |
package parser
import (
//"fmt"
"strings"
)
const (
ElementOpen = iota
ElementClose
Text
Comment
CData
Other
)
const (
STAT_NONE = iota
STAT_AFTER_LT
STAT_START_TAG
STAT_END_TAG
STAT_TEXT
STAT_PRE_COMMENT1
STAT_PRE_COMMENT2
STAT_COMMENT
STAT_PROCESS... |
package controllers
import (
"devbook-api/security"
"devbook-api/src/authentication"
"devbook-api/src/database"
"devbook-api/src/models"
"devbook-api/src/repositories"
"devbook-api/src/responses"
"encoding/json"
"io/ioutil"
"net/http"
)
func Auth(w http.ResponseWriter, r *http.Request) {
requestBody, err :=... |
package 双指针
import "fmt"
func twoSum(nums []int, target int) []int {
var a [2]int
m1 := make(map[int]int)
for i := 0; i < len(nums); i++ {
m1[nums[i]] = i + 1 // 这+1的原因是map默认值为0,但是0可能是下标
}
for i := 0; i < len(nums); i++ {
if m1[target-nums[i]] != 0 && m1[target-nums[i]] - 1!=i {
a[0] = i
a[1] = m1[targ... |
package keva
import "testing"
func TestBucketCacheTrie(t *testing.T) {
t.Run("Find() should return entry at end of a given path", func(t *testing.T) {
var b1 = newBucket("aabbcc")
b1.path = bucketPath("aabbcc")
var e1 = &bucketCacheEntry{bucket: b1}
e1.Init()
var b2 = newBucket("aabbccdd")
b2.path = b... |
/*
Write a function that returns an anonymous function, which transforms its input by adding a particular suffix at the end.
Examples
add_ly = add_suffix("ly")
add_ly("hopeless") ➞ "hopelessly"
add_ly("total") ➞"totally"
add_less = add_suffix("less")
add_less("fear") ➞ "fearless"
add_less("ruth") ➞ "ruthless"
*/
... |
package main
import (
"fmt"
"log"
"net/http"
"sync"
common "./commom"
services "./services"
)
var sum int64 = 0
var productNum int64 = 0
var mutex sync.Mutex
func Get1Product() bool {
mutex.Lock()
defer mutex.Unlock()
if sum < productNum {
sum += 1
fmt.Println(sum)
return true
}
return false
}
fu... |
package tickets
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strconv"
"strings"
// Mongo DB
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
// Gorilla Mux
"github.com/gorilla/mux"
// QR Code generator
"github.com/skip2/go-qrcode"
)
// Type Booking stores the datastructure for a bookin... |
// SPDX-License-Identifier: Unlicense OR MIT
package ops
import (
"encoding/binary"
"math"
"github.com/gop9/olt/gio/f32"
"github.com/gop9/olt/gio/internal/opconst"
"github.com/gop9/olt/gio/op"
)
func DecodeTransformOp(d []byte) op.TransformOp {
bo := binary.LittleEndian
if opconst.OpType(d[0]) != opconst.Typ... |
package basket
type Item struct {
Sku int
Title string
Price int
Substituted bool
SubPrice int
}
func GetTotal(items []Item) int {
return 0
}
|
package main
//kieu dun lieu
import "fmt"
func main() {
// bool
var myBool bool = true // false
fmt.Println(myBool)
fmt.Println("==============")
// string
var myString string = "abcdef"
fmt.Println(myString)
fmt.Println("==============")
// int
var myInt int = 11
fmt.Println(myInt)
// int8, 16, 32... |
// ˅
package main
// ˄
type CreditCardFactory struct {
// ˅
// ˄
Factory
cardOwners []string
// ˅
// ˄
}
func NewCreditCardFactory() *CreditCardFactory {
// ˅
creditCardFactory := &CreditCardFactory{}
creditCardFactory.Factory = *NewFactory()
return creditCardFactory
// ˄
}
func (self *CreditCardFac... |
package main
func main() {
}
//变量作用域
// 1)函数内部声明/定义的变量叫局部变量,作用域仅限于函数内部
// 2)函数外部声明/定义的变量叫全局变量,作用域在整个包都有效,如果其首字母为大写,则作用域在整个程序有效
// 3)如果变量是在一个代码块,比如for/if中,那么这个变量的作用域就在该代码块
|
package main
import ("fmt")
var k int
func main() {
fmt.Println("请输入你要求素数的个数")
k=string("n")
get_prime(k)
}
func get_prime(n int) {
origin, wait := make(chan int), make(chan struct{})
go FilterPrime(origin, wait)
for i := 2; i <= n; i++ {
origin <- i
}
close(origin)
<-wait
}
func FilterPrime(seq chan in... |
package compute
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
)
// CustomerImages represents a page of CustomerImage results.
type CustomerImages struct {
// The current page of network domains.
Images []CustomerImage `json:"customerImage"`
// The current page number.
PageNumber int `json:"pageNumber"`... |
package functions
import (
"context"
"encoding/base64"
"fmt"
"net/url"
"strings"
igrpc "github.com/direktiv/direktiv/pkg/functions/grpc"
hash "github.com/mitchellh/hashstructure/v2"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
v1 "k8s.io/ap... |
// base/make/cap.
package main
import "fmt"
type Struct struct{ s string }
func main() {
ss := make([]*Struct, 0, 10)
fmt.Println("ss == nil:", ss == nil) // false
sss := []*Struct{{"hello"}}
sss = append(sss, ss...)
fmt.Printf("sss: len:%d cap:%d %+v\n", len(sss), cap(sss), sss)
}
|
package leetcode
/*Given an integer array sorted in non-decreasing order, there is exactly one integer in the array that occurs more than 25% of the time.
Return that integer.
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/element-appearing-more-than-25-in-sorted-array
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。*/
func... |
package main
import (
"./engine"
)
func main() {
engine.ServerExecute()
}
|
package main
type Column []Card
func (c *Column) CanReceive(card Card) bool {
activeCard, ok := c.ActiveCard()
if !ok {
return true
}
return (activeCard.Color() != card.Color()) && (activeCard.Rank == card.Rank+1)
}
func (c *Column) Receive(card Card) {
*c = append(*c, card)
}
func (c *Column) CanGiveCard() ... |
package frontend
import (
"github.com/gin-gonic/gin"
"errors"
"net/http"
"strconv"
)
type ServiceConfig struct {
Addr string
Password string
}
type Server struct {
bankService, authService ServiceConfig
engine *gin.Engine
}
func NewServer(bankService, authService ServiceConfig) *Server {
engine :=... |
package event
type NotAcceptable struct {
ActionType string
Reason string
}
func (*NotAcceptable) GetType() string {
return TypeNotAcceptable
}
|
package cli
import (
"fmt"
"github.com/10gen/realm-cli/internal/cloud/realm"
"github.com/10gen/realm-cli/internal/utils/flags"
)
const (
appFlagUsage = "Specify the name or ID of a Realm app"
// ProjectFlagName is the '--project' flag name
ProjectFlagName = "project"
)
// AppFlag is the '--app' flag
func App... |
package loadwhole
import (
"flag"
"path"
"testing"
)
var testFilesFolderPath = flag.String("path", "", "path to mock file")
func BenchmarkLoadWholeFile_sample2K(b *testing.B) {
var sample2K = path.Join(*testFilesFolderPath, "sample2K.log")
for i := 0; i < b.N; i++ {
LoadWholeFile(sample2K, func(a ...interface... |
package routes
import (
"io/ioutil"
"log"
"net/http"
"github.com/gorilla/mux"
"github.com/gorilla/websocket"
"github.com/mahendrakalkura/torrents/go/settings"
"github.com/mahendrakalkura/torrents/go/views"
)
// Connection ...
var Connection *mux.Router
var upgrader websocket.Upgrader
func init() {
Connecti... |
package consul
import (
"fmt"
"net/http"
consulAPI "github.com/hashicorp/consul/api"
)
// Client defines the consul client
type Client struct {
config *consulAPI.Config // consul config
consulClient *consulAPI.Client // consul Client
// service registration related
registryConfig *RegistryConfig
co... |
package main
import (
"flag"
"fmt"
"log"
"os"
"path"
"github.com/emicklei/proto"
)
var (
baseDir = flag.String("baseDir", "", "base directory of proto files")
memo = map[string]struct{}{}
)
func main() {
flag.Parse()
filenames := flag.Args()
for _, filename := range filenames {
if err := walk(filenam... |
// gopastebin - A Go library for the pastebin.com API
// Author: Matt Godshall
package gopastebin
import (
"encoding/xml"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
const pastebinURL = "http://pastebin.com/api/api_post.php"
const pastebinLoginURL = "http://pastebin.com/api/api_login.php"
... |
package tests
import (
"testing"
"github.com/almerlucke/kallos"
)
func TestNotes(t *testing.T) {
major := kallos.NewScale([]int{2, 2, 1, 2, 2, 2, 1})
triad1 := major.Triad(1)
triad2 := triad1.Invert(1)
triad3 := triad1.Invert(2)
triad4 := triad1.Invert(3)
c := kallos.Chord{2, 4, 6}.SnapToScale(major, 1).De... |
package rest
import (
"encoding/json"
"errors"
"net/http"
"net/http/httptest"
"testing"
)
func TestGone(t *testing.T) {
t.Parallel()
w := httptest.NewRecorder()
req := httptest.NewRequest("GET", "/", nil)
Gone(w, req)
if w.Code != 410 {
t.Errorf("expected code to be 410, got %d", w.Code)
}
var e Error
... |
package main
import (
"bytes"
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"text/template"
"github.com/BurntSushi/toml"
"github.com/kaneshin/genex"
"github.com/serenize/snaker"
)
var (
pkg = flag.String("pkg", "", "Package name to use in the generated code. (default \"main\")")
src... |
/*
This file handles RPC connections, usually from DVID clients.
*/
package server
import (
"fmt"
"os"
"time"
"github.com/janelia-flyem/dvid/datastore"
"github.com/janelia-flyem/dvid/dvid"
)
const helpMessage = `
Commands executed on the server (rpc address = %s):
help [command you are running]
about
log... |
package server
import (
"sync"
"io"
"golang.org/x/net/context"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"go.uber.org/zap"
"github.com/bclermont/whereru/proto"
"go.uber.org/zap/zapcore"
)
type whereAreYouServer struct {
peers map[string]func(*whereru.PeerUpdate)
mutex sync.Mutex
l... |
package ingest
import (
"context"
"encoding/json"
"fmt"
"net"
"strings"
"time"
"github.com/dylanratcliffe/sdp-go"
log "github.com/sirupsen/logrus"
"github.com/dgraph-io/dgo/v200"
"github.com/dgraph-io/dgo/v200/protos/api"
"google.golang.org/grpc"
"google.golang.org/grpc/encoding/gzip"
"google.golang.org... |
package compute
import (
"encoding/json"
"fmt"
"net/http"
"net/url"
"strconv"
"strings"
)
// PublicIPBlock represents an allocated block of public IPv4 addresses.
type PublicIPBlock struct {
ID string `json:"id"`
NetworkDomainID string `json:"networkDomainId"`
DataCenterID string `json:"datac... |
package main
import (
"fmt"
"strings"
"testing"
"github.com/jungju/circle_manager/modules"
"github.com/stretchr/testify/assert"
)
func TestCleanRouterSource(t *testing.T) {
regenRouterSource := cleanRouterSource(routerSource)
i := strings.Index(regenRouterSource, CIRCLE_AUTO_START_WORD+"\n\t\t"+CIRCLE_AUTO_EN... |
package transdsl
import (
"time"
)
type Wait struct {
EventId string
Timeout time.Duration //ms
Fragment Fragment
}
func (this *Wait) Exec(transInfo *TransInfo) error {
transInfo.EventId = this.EventId
select {
case <-transInfo.Ch:
transInfo.EventId = ""
return this.Fragment.Exec(transInfo)
case <-time... |
// +build windows
package tty
import (
"github.com/liamg/aminal/platform"
"k0s.io/k0s/pkg/agent"
)
func NewFactory(args []string) agent.TtyFactory {
return &factory{
args: args,
}
}
var (
_ agent.TtyFactory = (*factory)(nil)
_ agent.Tty = (*term)(nil)
)
type term struct {
platform.Pty
}
func (t *t... |
package checkup
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"
"strconv"
"strings"
"time"
"github.com/sourcegraph/checkup/utils"
)
// BTCChecker implements a Checker for BTC fullnode.
type BTCChecker struct {
// Name is the name of the endpoint.
Name string `json:"endpoint_name"`
/... |
/*
# -*- coding: utf-8 -*-
# @Author : joker
# @Time : 2020-08-18 09:22
# @File : lt_567_Permutation_in_String.go
# @Description :
# @Attention :
*/
package slide_window
import (
"fmt"
"testing"
)
func Test_checkInclusion(t *testing.T) {
fmt.Println(checkInclusion("ab", "eidboaoo"))
}
|
package main
func getMeSomething() string {
return "here is something for you"
}
|
package day13
import "fmt"
type Displayer interface {
Display() string
}
type Book struct {
Displayer
title string
author string
}
type MyBook struct {
Book
price int
}
func (b Book) NewBook(title, author string) Book {
return Book{title: title, author: author}
}
func (m MyBook) NewMyBook(title, author st... |
package main
import "fmt"
func main() {
fmt.Println("Result:", Add(1.0, 2.1))
fmt.Println("Result:", Add("sahil", "wale"))
}
func Add(a, b interface{}) interface{} {
switch val := a.(type) {
case string:
return val + "-" + b.(string)
case float64:
return val + b.(float64)
}
return "no case matched!!"
}
|
package pojo
import "tesou.io/platform/brush-parent/brush-api/common/base/pojo"
/**
亚赔历史,变化过程表
*/
type AsiaTrack struct {
/**
初主队盘口赔率
*/
Sp3 float64
Sp0 float64
//让球
SLetBall float64 `xorm:" comment('s让球') index"`
/**
即时客队盘口赔率
*/
Ep3 float64
Ep0 float64
//让球
ELetBall float64 `xorm:" comment('e让球') index... |
package notifier
//INotifier ...
type INotifier interface {
Create() error
GetName() string
Notify(string, ...string) error
Destroy()
}
|
package config
type Configuration struct {
SearchServiceEndPoint string
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.