text stringlengths 11 4.05M |
|---|
// +build js
package math4g
import (
"math"
"github.com/gopherjs/gopherjs/js"
)
var (
nan = Scala(js.Global.Get("NaN").Float())
)
func NaN() Scala {
return nan
}
func IsNaN(x Scala) bool {
/* slow implementation: 1
return js.Global.Get("isNaN").Invoke(x).Bool()
*/
return math.IsNaN(float64(x))
}
func Cbr... |
package main
func main() {
var a, b struct {
x []int
}
_ = (a == b)
}
|
// // SPDX-License-Identifier: MIT OR Unlicense
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
str "github.com/boyter/go-string"
"github.com/gdamore/tcell"
"github.com/rivo/tview"
"os"
"runtime"
"strconv"
"strings"
"sync"
"time"
)
type displayResult struct {
Title *tview.TextView
Body ... |
// Copyright 2019 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package platform
import (
"context"
"time"
"chromiumos/tast/local/memory/memoryuser"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test{
Func: ... |
package altrudos
import "testing"
func TestConfig(t *testing.T) {
c, err := ParseConfig("./config.example.toml")
if err != nil {
t.Fatal(err)
}
if c.JustGiving.Mode != "staging" {
t.Fatal("Expecting mode to be staging")
}
if c.JustGiving.AppId != "some-app-id" {
t.Fatal("Expecting app id to be some-app-... |
package logger
import (
"ekgo/api/boot/config"
rotatelogs "github.com/lestrrat-go/file-rotatelogs"
"github.com/rifflock/lfshook"
"github.com/sirupsen/logrus"
"log"
"os"
"time"
)
var Log = logrus.New()
//日志初始化
func Load(logPath string) *logrus.Logger {
src, err := os.OpenFile(os.DevNull, os.O_APPEND|os.O_WRO... |
package keypair
import (
"errors"
"golang.org/x/crypto/ssh"
admissionregv1 "k8s.io/api/admissionregistration/v1"
"k8s.io/apimachinery/pkg/runtime"
"github.com/harvester/harvester/pkg/apis/harvesterhci.io/v1beta1"
ctlharvesterv1 "github.com/harvester/harvester/pkg/generated/controllers/harvesterhci.io/v1beta1"
... |
package redlock
import (
"fmt"
"github.com/garyburd/redigo/redis"
"math/rand"
"runtime"
"sync"
"testing"
"time"
)
var locker *Rdm
var addrs []string = []string{
"127.0.0.1:6379",
"127.0.0.1:6377",
"127.0.0.1:6375",
"127.0.0.1:6373",
"127.0.0.1:6371",
}
func newPool(addr string) *redis.Pool {
return &re... |
package infrastructure
import (
"encoding/json"
"net/http"
)
//Response Response
type Response struct {
Body interface{}
}
//Error Error
type Error struct {
Message string `json:"message"`
}
//StatusOK StatusOK 200
func (r *Response) StatusOK(w http.ResponseWriter, data interface{}) {
r.statusSuccess(w, http.S... |
package leetcode
func addDigits0(num int) int {
return (num-1)%9 + 1
}
func addDigits1(num int) int {
if num <= 9 {
return num
}
for num > 9 {
var ans int
for num != 0 {
ans += num % 10
num /= 10
}
num = ans
}
return num
}
func addDigits(num int) int {
if num <= 9 {
return num
}
if num ... |
// Copyright 2019 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
package printer
import (
"context"
"chromiumos/tast/local/bundles/cros/printer/usbprintertests"
"chromiumos/tast/testing"
)
func init() {
testing.AddTest(&testing.Test... |
package cmd
import (
"errors"
"regexp"
"github.com/kronostechnologies/richman/action"
"github.com/spf13/cobra"
)
var appsRunCmd = &cobra.Command{
Use: "run -a APPLICATION",
Short: "run app ops env",
Long: "run app ops env",
Args: func(cmd *cobra.Command, args []string) error {
if len(args) != 0 {
//T... |
package main
import (
//"bufio"
"fmt"
//"math/rand"
//"os"
"regexp"
"strconv"
"strings"
"time"
"github.com/bwmarrin/discordgo"
)
//RegisterCommands registrates all commands to commandHandler
func RegisterCommands() {
commandHandler.RegisterCommand("best", bestCommand)
commandHandler.RegisterCommand("raffl... |
package shop
import (
sa "github.com/atymkiv/sa/model"
"github.com/atymkiv/sa/pkg/utl/messages"
"github.com/labstack/echo"
"log"
)
const TOPIC = "shops"
type Service interface {
View(echo.Context, string)(*sa.Shop, error)
ViewAll(echo.Context) ([]sa.Shop, error)
GetAddressByShopId(echo.Context, string) (*sa.Add... |
package Week_01
func trap(height []int) int {
l := len(height)
lefts := make([]int, l)
rights := make([]int, l)
for i := 1; i < l-1; i++ { // i表示当前的列,求它的左边 的最大的柱子
if height[i-1] > lefts[i-1] {
lefts[i] = height[i-1]
} else {
lefts[i] = lefts[i-1]
}
}
for i := l - 2; i >= 0; i-- { // i表示当前的列,求它的右边 的最... |
package main
import "fmt"
func main() {
nTask := 5
ch := make(chan int)
for i := 0; i < nTask; i++ {
go doTask(ch, i)
}
for i := 0; i < nTask; i++ {
fmt.Println(<-ch)
}
fmt.Println("run is finished")
}
func doTask(ch chan<- int, data int) {
//do sth
ch <- data
}
|
package metascraper
import (
"reflect"
"testing"
"github.com/twistedogic/spero/pkg/schema/match"
)
func setup() *MetaScraper {
eventURL := "https://lsc.fn.sportradar.com/hkjc/en"
return New(eventURL, 5)
}
func TestMetaScraper_GetMatchDetail(t *testing.T) {
m := setup()
id := 14728777
detail, err := m.GetMat... |
package main
import "fmt"
func main(){
var a int16 = 26
var out int16 =0
out = a%2 + a/2%2*10 + a/4%2*100 + a/8%2*1000+a/16%2*10000
fmt.Printf("作业一 十进制转二进制:")
fmt.Printf("%d %d \n",a,out)
a=31
out = 0
out = a%8 + a/8%8*10
fmt.Printf("作业二 十进制转八进制:")
fmt.Printf("%d %d \n",a,out)
a=1
... |
func RemoveStringDuplicate(strSlice []string) []string {
if len(strSlice) == 0 {
return strSlice
}
strMap := make(map[string]bool)
for _, d := range strSlice {
strMap[d] = true
}
result := make([]string, len(strMap))
i := 0
for k, _ := range strMap {
result[i] = k
i++
}
return result
}
|
package usecase
import (
"amazonOpenApi/internal/http/gen"
"amazonOpenApi/internal/repository"
"net/http"
"time"
"github.com/labstack/echo/v4"
"gorm.io/gorm"
)
type Amazon struct {
db *gorm.DB
}
func NewAmazon(db *gorm.DB) *Amazon {
return &Amazon{
db: db,
}
}
func (p *Amazon) AddAmazon(ctx echo.Context... |
package main
import "fmt"
func findMedianSortedArrays(nums1 []int, nums2 []int) float64 {
return 0
}
func main() {
nums1 := []int{1, 2}
nums2 := []int{3, 4}
fmt.Println(findMedianSortedArrays(nums1, nums2))
}
|
// Copyright 2020 Comcast Cable Communications Management, 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 ... |
package controllers
import (
"html/template"
"net/http"
)
func unit2Rot13(w http.ResponseWriter, r *http.Request) {
t, _ := template.ParseFiles("templates/rot13.html")
err := t.Execute(w, encodeROT13(r.FormValue("text")))
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}
func enc... |
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"os/exec"
"path"
"strings"
homedir "github.com/mitchellh/go-homedir"
)
const (
RESET = iota
BOLD
)
const (
BLACK = 30 + iota
RED
GREEN
YELLOW
)
var debug = flag.Bool("debug", false, "debug mode")
func DebugLogf(s string, v ...interface{}) {
if ... |
package post_store
const (
/*getPostsOfFollowing = `SELECT posts.username, images.path, posts.name, posts.created_on
FROM followers
INNER JOIN posts ON followers.following=posts.username
INNER JOIN images ON images.id = posts.image_id
WHERE followers.username = $1
ORDER BY posts.created_on DESC;`*/
ge... |
package bolt
import "github.com/boltdb/bolt"
// Truncate the whole database
func (b *Storage) Truncate() error {
db := b.Database
return db.Update(func(tx *bolt.Tx) error {
return tx.ForEach(func(name []byte, b *bolt.Bucket) error {
return tx.DeleteBucket(name)
})
})
}
|
package designBrowser
import (
"fmt"
"io/ioutil"
"net/http"
)
func GetMore(w http.ResponseWriter, r *http.Request, q string) {
url := fmt.Sprintf("http://design-seeds.com/index.php/P%v", q)
resp, err := http.Get(url)
if err != nil || resp.StatusCode != 200 {
return
}
body, err := ioutil.ReadAll(resp.Body)
... |
package main
import "fmt"
type Set map[interface{}]bool
func (s *Set) Add(key interface{}) {
(*s)[key] = true
}
func (s *Set) Find(key interface{}) bool {
return (*s)[key]
}
func (s *Set) Remove(key interface{}) {
delete(*s, key)
}
func (s *Set) Size() int {
return len(*s)
}
func main() {
set := make(Set)
... |
// 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 main
import "fmt"
func main(){
fmt.Println("Enter numbers=")
var n,m int
fmt.Scan(&n,&m)
a:=func(num1, num2 int) {
sum:=num1+num2
fmt.Println("addition=",sum)
}
a(n,m)
}
|
package utils
import (
"crypto/tls"
"fmt"
"github.com/parnurzeal/gorequest"
)
// request is a new SuperAgent object with a setting of not verifying
// server's certificate chain and host name.
var request = gorequest.New().TLSClientConfig(&tls.Config{InsecureSkipVerify: true})
func AgentGet() *gorequest.SuperAge... |
package flag
import (
"regexp"
"strings"
)
// StringArray defines a flag that can be invoked multiple times with values accumulated in an array.
// Comma-separated values may be combined in a single flag argument to be separated into the array.
// Extra space(s) around the commas are removed.
type StringArray []str... |
package task
import (
"context"
"encoding/json"
"fmt"
"io"
"log"
"os"
"strings"
"text/tabwriter"
"golang.org/x/sync/errgroup"
"github.com/go-task/task/v3/internal/editors"
"github.com/go-task/task/v3/internal/fingerprint"
"github.com/go-task/task/v3/internal/logger"
"github.com/go-task/task/v3/internal/... |
package wireguard
import (
"errors"
"net"
"os"
"path/filepath"
"github.com/vishvananda/netlink"
"golang.zx2c4.com/wireguard/device"
"golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"github.com/utilitywarehouse/semaphore-wireguard/log"
)
// Device is the struct to hold the lin... |
package strategies
import (
"fmt"
"github.com/matang28/reshape/reshape"
"time"
)
func tick() {
time.Sleep(100 * time.Millisecond)
}
func predefinedSource(ch chan interface{}, elements ...interface{}) {
defer func() {
recover()
}()
for _, e := range elements {
ch <- e
}
}
func delayedSource(ch chan inte... |
package handler
import (
"path/filepath"
"strings"
"time"
"github.com/futurehomeno/fimpgo/edgeapp"
"github.com/futurehomeno/fimpgo/utils"
"github.com/futurehomeno/fimpgo"
scribble "github.com/nanobox-io/golang-scribble"
log "github.com/sirupsen/logrus"
"github.com/tskaard/sensibo/model"
"github.com/tskaar... |
package main
import (
"fmt"
"os"
"strconv"
)
func main() {
arguments := os.Args[1:]
if len(arguments) == 0 {
fmt.Println("usage: main.exe <percent_1> <percent_2>...")
fmt.Println("ie main.exe 60")
return
}
for _, value := range arguments {
input, fail := strconv.ParseFloat(value, 10)
if fail != ... |
package main
import (
"fmt"
)
func spiralOrder(matrix [][]int) []int {
if len(matrix) == 0 {
return []int{}
}
d := [][]int{
{0, 1},
{1, 0},
{0, -1},
{-1, 0},
}
row := len(matrix)
col := len(matrix[0])
border := []int{col, row, 0, 0}
borderOp := []int{-1, -1, 1, 1}
ans := make([]int, row*col)
no... |
package ffmpeg
//#include <libavutil/avutil.h>
import "C"
const (
MediaTypeUnknown = MediaType(C.AVMEDIA_TYPE_UNKNOWN)
MediaTypeVideo = MediaType(C.AVMEDIA_TYPE_VIDEO)
MediaTypeAudio = MediaType(C.AVMEDIA_TYPE_AUDIO)
MediaTypeData = MediaType(C.AVMEDIA_TYPE_DATA)
MediaTypeSubtitle = MediaTyp... |
// This file is part of CycloneDX GoMod
//
// 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 alldebrid
import (
"encoding/json"
"errors"
"fmt"
"net/http"
)
//Domains is the domains response struct
type Domains struct {
Status string `json:"status"`
Data domainsData `json:"data,omitempty"`
Error alldebridError `json:"error,omitempty"`
}
type domainsData struct {
Hosts []st... |
package eoy
import (
"encoding/json"
"fmt"
"log"
"os"
"strings"
"time"
"github.com/360EntSecGroup-Skylar/excelize"
"github.com/jinzhu/gorm"
goengage "github.com/salsalabs/goengage/pkg"
)
const (
//DefaultColumnWidth is the Excel size for a column that contains numbers.
DefaultColumnWidth = 14.0
//Activit... |
// 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 statik
//This just for fixing the error in importing empty github.com/OCEChain/OCEChain/client/lcd/statik
|
package jsonvalidate
import (
"encoding/json"
"fmt"
"net/url"
"github.com/json-validate/json-pointer-go"
)
type Validator struct {
MaxErrors int
MaxDepth int
Registry Registry
}
type ValidationResult struct {
Errors []ValidationError `json:"errors"`
}
func (r ValidationResult) IsValid() bool {
return le... |
package anagrams
import "testing"
type testCase struct {
s string
n int32
}
func TestSherlock(t *testing.T) {
testCases := []testCase{
{"abba", 4},
{"abcd", 0},
{"ifailuhkqq", 3},
{"kkkk", 10},
{"cdcd", 5},
}
for _, tc := range testCases {
t.Run(tc.s, func(t *testing.T) {
got := Sherlock(tc.s)
... |
package main
import (
"fmt"
"log"
"net/http"
"os"
"strconv"
"time"
"github.com/baor/telegobot/habr"
"github.com/baor/telegobot/storage"
"github.com/baor/telegobot/telegram"
)
// HandlerStatus handler returns applications status
func status(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "telegabot ... |
package main
import (
jwtack "github.com/gobricks/jwtack/src"
app "github.com/gobricks/jwtack/src/app"
)
func main() {
jwtack.RunServer(app.NewApp())
} |
// +build !windows,!darwin
// 7 july 2014
package ui
import (
"unsafe"
)
// #include "gtk_unix.h"
import "C"
type label struct {
*controlSingleWidget
misc *C.GtkMisc
label *C.GtkLabel
}
func newLabel(text string) Label {
ctext := togstr(text)
defer freegstr(ctext)
widget := C.gtk_label_new(ctext... |
package main
import (
"JsGo/JsConfig"
"fmt"
)
func main() {
keys := make([]string, 2)
keys[0] = "Hello"
keys[1] = "Meng"
ret, err := JsConfig.GetConfigString(keys)
if err == nil {
fmt.Println(ret)
} else {
fmt.Println(err)
}
keys = make([]string, 3)
keys[0] = "xxx"
keys[1] = "yyy"
keys[2] = "zzz... |
package AesCtr
import (
"crypto/cipher"
)
type gcmAble interface {
NewGCM(size int) (cipher.AEAD, error)
}
type cbcEncAble interface {
NewCBCEncrypter(iv []byte) cipher.BlockMode
}
type cbcDecAble interface {
NewCBCDecrypter(iv []byte) cipher.BlockMode
}
type ctrAble interface {
NewCTR(iv []byte) cipher.Strea... |
package bean
import (
"errors"
"strconv"
"time"
)
type UrlTask struct {
Url string
Keywords []string
Info DataItem
}
type UrlResult struct {
Task UrlTask
Eval []int
}
func (result *UrlResult) Compare(another *UrlResult) (int, error) {
if len(result.Eval) != len(another.Eval) {
return 0, errors... |
package json
import (
"errors"
"fmt"
"strconv"
)
type stateFn func(l *dictgen) stateFn
const (
SPE_NONE = 0x00
SPE_K = 0x01
SPE_C = 0x02
SPE_S = 0x04
)
type Item struct {
id string
t string
scope string
desc string
v string
ri int
}
func NewItem(id, t, scope, desc, v string, ri... |
package nfe
import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
"net/http"
)
type NfeController struct{
Service INfeService
}
func NewNfeController(service INfeService) NfeController {
return NfeController{Service:service}
}
func (controller NfeController) RetrieveNfe(c *gin.Context) {
accessKey, ok ... |
package dependencies
import (
goerr "errors"
"io/ioutil"
"os"
"path/filepath"
"strings"
"wio/cmd/wio/commands/run/cmake"
"wio/cmd/wio/errors"
"wio/cmd/wio/log"
"wio/cmd/wio/types"
"wio/cmd/wio/utils"
"wio/cmd/wio/utils/io"
"wio/cmd/wio/constants"
)
var packageVersions =... |
package ymdRedisServer
import (
"testing"
"reflect"
"github.com/orestonce/ymd/ymdAssert"
"github.com/orestonce/ymd/ymdRedis/ymdRedisProtocol"
)
func TestRedisCore_LIndex(t *testing.T) {
core := newDebugRedisCore()
core.RPush(`key`, `a`, `b`, `c`, `d`, `e`)
reply, errMsg := core.LIndex(`key`, 2)
ymdAssert.True... |
package routes
import (
"to_do_list/module/todo/handlers"
"to_do_list/module/todo/repositories"
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
)
var todoRepo repositories.Todo
//SetupRouter untuk setup routernya bro
func SetupRouter(db *gorm.DB) *gin.Engine {
todoRepo = repositories.NewTodoRepositories(db... |
package epg
import (
"github.com/stretchr/testify/assert"
"github.com/yosisa/arec/reserve"
"os"
"testing"
"time"
)
func TestDeocdeJson(t *testing.T) {
f, err := os.Open("testdata/gr99.json")
if err != nil {
t.Fatal(err)
}
defer f.Close()
channels, err := DecodeJson(f)
ch := channels[0]
assert.Nil(t, er... |
/*
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
distributed under the License is ... |
package main
import (
"flag"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/sirupsen/logrus"
)
var (
listenAddress = flag.String("web.listen-address", ":8080", "Address to listen on for web interface and telemetry")
metricPath ... |
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"os"
"strconv"
"strings"
"time"
)
var debug = false
var dumpDir string
type UrbanAirship struct {
AppKey string
MasterSecret string
TokensLimitPerRequest int // Optional. A maximum value of only 10000 is accepted.
StartingTokenI... |
package ecdsatools
import (
"crypto/sha256"
"github.com/stretchr/testify/assert"
"testing"
)
func TestSignAndRecoverSignature(t *testing.T) {
privateKey, err := GenerateKey()
assert.True(t, err == nil)
println("privateKey: ", BytesToHex(PrivateKeyToBytes(privateKey)))
publicKeyBytes := CompactPubKeyToBytes(Pub... |
package main
import (
"io/ioutil"
"os"
"os/exec"
"github.com/sdwolfe32/anirip/anirip"
)
// Trims the first couple seconds off of the video to remove any logos
func trimMKV(adLength int, tempDir string) error {
// Removes a stale temp files to avoid conflcts in func
os.Remove(tempDir + string(os.PathSeparator) ... |
package template
import (
"bytes"
"fmt"
"html/template"
"syscall/js"
"github.com/factorapp/structure/dom"
)
type Renderer struct {
elt *dom.Element
}
func NewRenderer(elt *dom.Element) Renderer {
return Renderer{
elt: elt,
}
}
func (p Renderer) Render(tplName string, data map[string]interface{}) (string,... |
package main
const esbuildVersion = "0.5.9"
|
package main
import (
"testing"
)
func TestCode(t *testing.T) {
var tests = []struct {
input []int
output int
}{
{
input: []int{1, 1, 2, 2, 3},
output: 1,
},
{
input: []int{1, 4, 4, 4, 5, 3},
output: 4,
},
}
for _, test := range tests {
if got := migratoryBirds(test.input); got != t... |
package ravendb
type FieldIndexing string
const (
FieldIndexingNo = "No"
FieldIndexingSearch = "Search"
FieldIndexingExact = "Exact"
FieldIndexingDefault = "Default"
)
|
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
var line, out string
initmaps()
out = ""
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line = scanner.Text()
out = convgost(line)
fmt.Print(out, "\n")
}
}
|
package lib
import (
"fmt"
"io"
"net/http"
"os"
"time"
)
func GetToken() (token string) {
Info.Println("Trying to load TOKEN.")
token = os.Getenv("GH_TOKEN")
if token != "" {
return token
}
Warning.Println("Can't load GH_TOKEN env variable")
Info.Println("Trying to extract TOKEN.")
token, err := GetKey... |
package wallet
func run() {
//startd qitmeer
//current keys,hd wallet
//current addresses 1-10
//for blocks and check in out,,start blocks 0
//update block for index address in out balance
}
|
package logging
// checkLevel ログレベルをチェックします.
func checkLevel(level, configLevel Level) bool {
if level < configLevel {
return false
}
return true
}
// getLevelStr ログレベルを文字列として取得します.
func getLevelStr(level Level) string {
switch level {
case DEBUG:
return "DEBUG"
case INFO:
return "INFO"
case WARN:
retu... |
package turingapi
type Body struct {
ReqType int `json:"reqType"`
Perception *Query `json:"perception"`
UserInfo *UserInfo `json:"userInfo"`
}
type Query struct {
// 文本信息
InputText struct{ Text string `json:"text"` } `json:"inputText"`
// 图片信息
InputImage struct{ Url string `json:"url"` } `json:"in... |
/*
* @Author: tr3e
* @Date: 2019-11-26 20:50:43
* @Last Modified by: tr3e
* @Last Modified time: 2019-11-26 20:56:38
*/
package main
import "errors"
type Cipher interface {
Encrypt([]byte) []byte
Decrypt([]byte) []byte
Copy() Cipher
Reset()
}
var cipherMethod = map[string]func(string) (Cipher, error){
"pl... |
package lc
// Time: O(n)
// Benchmark: 8ms 6.4mb | 89% 69%
func getConcatenation(nums []int) []int {
return append(nums, nums...)
}
|
package queryme
import (
"fmt"
"errors"
"net/url"
"strconv"
"strings"
"time"
"unicode/utf8"
)
/*
predicates = predicate *("," predicate)
predicate = (not / and / or / eq / lt / le / gt / ge)
not = "not" "(" predicate ")"
and = "and" "(" predicates ")"
or = "or" "(" predica... |
// Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed t... |
package manager
import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
)
// 全部,包括子路径下文件
type Name struct {
Num int
Name string
IsDir bool
}
type Lists struct {
Num int
Href string
Name string
IsDir bool
}
type Img struct{
Num int
Name string
}
func ListSingle(pwd string)(result []Name,errs... |
package internal
// ContextKey is just an empty struct. It exists so context values can be
// an immutable public variable with a unique type. It's immutable
// because nobody else can create a ContextKey, being unexported.
type ContextKey struct{}
|
package main
import "fmt"
func main() {
ch := make(chan int, 2)
ch <- 1
ch <- 2
//ch <- 3 // fatal error: all goroutines are asleep - deadlock!
fmt.Println(<-ch)
fmt.Println(<-ch)
//fmt.Println(<-ch)
/*
fatal error: all goroutines are asleep - deadlock!
goroutine 1 [chan receive]:
main.main()
/User... |
/*
Copyright © 2021 Damien Coraboeuf <damien.coraboeuf@nemerosa.com>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modi... |
package dao
import (
"github.com/jinzhu/gorm"
"github.com/luxingwen/secret-game/conf"
"github.com/luxingwen/secret-game/model"
"context"
"github.com/BurntSushi/toml"
_ "github.com/jinzhu/gorm/dialects/mysql"
log "github.com/sirupsen/logrus"
"io/ioutil"
"time"
)
const (
TableTeam = "teams"
TableTeam... |
package gotification_test
import (
"github.com/mikegw/gotification/pkg/notification"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"net/http/httptest"
"strings"
"io/ioutil"
"encoding/json"
)
type savedNotification struct {
Payload string
ID string
}
type errorResponse struct {
Message stri... |
package main
import (
"flag"
"fmt"
"github.com/tarm/serial"
"os"
"time"
)
func main() {
flag.Parse()
if flag.NArg() < 2 {
fmt.Fprintf(os.Stderr, "usage: %s <port> <filename.hex>\n", os.Args[0])
os.Exit(2)
}
portConfig := &serial.Config{
Name: flag.Arg(0),
Baud: 9600,
ReadTimeout: ti... |
// Copyright © 2016 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 controller
import (
"context"
"database/sql"
"log"
"github.com/tonouchi510/goa2-sample/gen/admin"
)
// Admin service example implementation.
// The example methods log the requests and return zero values.
type adminsrvc struct {
logger *log.Logger
DB *sql.DB
}
// NewAdmin returns the Admin service... |
package main
import (
"fmt"
"github.com/todostreaming/fifo"
)
type Segment struct {
Name string
Dur float64
}
func main() {
ts_queue := fifo.NewQueue()
ts_queue.Add(&Segment{"stream1.ts", 10.56})
ts_queue.Add(&Segment{"stream2.ts", 9.02})
ts_queue.Add(&Segment{"stream3.ts", 11.00})
for q := ts_queue.Next(... |
package solutions
func twoSum(nums []int, target int) []int {
lookupMap := make(map[int]int)
for i, value := range nums {
j, complement := lookupMap[-value]
if complement {
return []int{j, i}
}
lookupMap[value - target] = i
}
return []int{}
} |
package moxings
type Yinpinshanchuxins struct {
Id int
Xuliehao string `gorm:"not null;DEFAULT:0"`
Yishanchu int64 `gorm:"not null;DEFAULT:0"`
Shanchubiaoji int64 `gorm:"not null;DEFAULT:0"`
}
func (Yinpinshanchuxins) TableName() string {
return "Yinpinshanchuxins"
}
|
package main
//944. 删列造序
//给你由 n 个小写字母字符串组成的数组 strs,其中每个字符串长度相等。
//
//这些字符串可以每个一行,排成一个网格。例如,strs = ["abc", "bce", "cae"] 可以排列为:
//
//abc
//bce
//cae
//你需要找出并删除 不是按字典序升序排列的 列。在上面的例子(下标从 0 开始)中,列 0('a', 'b', 'c')和列 2('c', 'e', 'e')都是按升序排列的,而列 1('b', 'c', 'a')不是,所以要删除列 1 。
//
//返回你需要删除的列数。
//
//
//示例 1:
//
//输入:strs = ["... |
package Sieve
import "math"
func Sieve(n int) (result []int) {
var start []int
for i := 2; i <= n; i++ {
start = append(start, i)
}
p := int(math.Floor(math.Sqrt(float64(n))))
for i := 2; i <= p; i++ {
if start[i-2] != 0 {
j := start[i-2] * start[i-2]
for j <= n {
start[j-2] = 0
j += i
}
}... |
// Copyright 2018-present The Yumcoder Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//
// Author: yumcoder (omid.jn@gmail.com)
//
package one
import (
"sync"
"testing"
)
type onceFunCall int
func (o *onceFunCall) Increment() ... |
package main
import (
"flag"
"os"
"net/http"
"fmt"
"log"
"strings"
)
var (
listenPort int
redirectCode int
)
func init() {
flagset := flag.NewFlagSet(os.Args[0], flag.ExitOnError)
flagset.IntVar(&listenPort, "port", 8080, "The port to listen on")
flagset.IntVar(&redirectCode, "status", 301, "The HTTP s... |
package svr
import (
"github.com/gin-gonic/gin"
"go4eat-api/pkg/svr"
"go4eat-api/svc"
"go4eat-api/svr/ctx"
"go4eat-api/svr/domain"
"go4eat-api/svr/domain/orders"
"go4eat-api/svr/domain/places"
"go4eat-api/svr/domain/users"
)
func router(container *svc.Container) svr.Router {
return func(engine *gin.Engine)... |
package db
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http/httptest"
"net/url"
"strings"
"testing"
"github.com/gomodule/redigo/redis"
)
const (
testConfigName = "/tmp/config.example.json"
testDbIndex = 1 // forced overwrite db index for tests
)
var (
cipherKey = []byte{
0, 0, 0, 0, 0, 0, 0, 0,
... |
package spider
import (
"strings"
"net/url"
"github.com/PuerkitoBio/goquery"
. "DesertEagleSite/bean"
)
func GetBingData(keyword string) ([]DataItem, string, error) {
resp, err := goquery.NewDocument("http://cn.bing.com/search?q=" + keyword)
if err != nil {
return nil, "", err
}
return ParseBingHTML(resp)
... |
package example
import (
"context"
"github.com/qhenkart/gosqs"
)
func initWorker(c gosqs.Config) {
// create the connection to AWS or the emulator
consumer, err := gosqs.NewConsumer(c, "post-worker")
if err != nil {
panic(err)
}
h := Consumer{
consumer,
}
// add any adapters and middleware, you can al... |
package doc
import (
"text/template"
)
var (
attributeTmpl *template.Template
attributeFmt = " + {{.Name.Quote}}: {{.Value.Quote}} ({{.Type.String}}, {{with .IsRequired}}required{{else}}optional{{end}}){{with .Description}} - {{.}}{{end}}{{with .DefaultValue}}\n + Default: {{.}}{{end}}"
)
func ... |
package main
import (
"github.com/valyala/fasthttp"
"fmt"
)
type MyHandler struct {
foobar string
l int
}
// request handler in net/http style, i.e. method bound to MyHandler struct.
func (h *MyHandler) HandleFastHTTP(ctx *fasthttp.RequestCtx) {
// notice that we may access MyHandler properties here - see h.foo... |
package config
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"github.com/cloudflare/cfssl/cli"
"github.com/cloudflare/cfssl/log"
)
// Config is COP config structure
type Config struct {
Debug bool `json:"debug,omitempty"`
Authentication bool `json:"authentication,omitempty"... |
package iputil
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestParseIP(t *testing.T) {
testCases := []struct {
input string
expectedVer IPVersion
expectedIP net.IP
}{
{"", IPvUnknown, nil},
{"1.1.1.1", IPv4, net.IPv4(1, 1, 1, 1)},
{"-1.-1.-1.-1", IPvUnknown, nil},
{... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.