text:
// Copyright 2020 Dolthub, 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, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sqlutil

import (
	"github.com/dolthub/go-mysql-server/sql"
)

type StaticErrorTable struct {
	sql.Table
	err error
}

func (t *StaticErrorTable) Partitions(_ *sql.Context) (sql.PartitionIter, error) {
	return nil, t.err
}

func (t *StaticErrorTable) PartitionRows(_ *sql.Context, _ sql.Partition) (sql.RowIter, error) {
	return nil, t.err
}

func (t *StaticErrorTable) LookupPartitions(_ *sql.Context, _ sql.IndexLookup) (sql.PartitionIter, error) {
	return nil, t.err
}

func NewStaticErrorTable(orig sql.Table, err error) sql.Table {
	return &StaticErrorTable{orig, err}
}

type StaticErrorRowIter struct {
	err error
}

func NewStaticErrorRowIter(err error) sql.RowIter {
	return &StaticErrorRowIter{err}
}

func (i *StaticErrorRowIter) Next(*sql.Context) (sql.Row, error) {
	return nil, i.err
}

func (i *StaticErrorRowIter) Close(*sql.Context) error {
	// Or i.err?
	return nil
}

type StaticErrorEditor struct {
	err error
}

var _ sql.ForeignKeyEditor = (*StaticErrorEditor)(nil)

func NewStaticErrorEditor(err error) *StaticErrorEditor {
	return &StaticErrorEditor{err}
}

func (e *StaticErrorEditor) Insert(*sql.Context, sql.Row) error {
	return e.err
}

func (e *StaticErrorEditor) Delete(*sql.Context, sql.Row) error {
	return e.err
}

func (e *StaticErrorEditor) Update(*sql.Context, sql.Row, sql.Row) error {
	return e.err
}

func (e *StaticErrorEditor) SetAutoIncrementValue(*sql.Context, uint64) error {
	return e.err
}

func (e *StaticErrorEditor) StatementBegin(ctx *sql.Context) {}

func (e *StaticErrorEditor) DiscardChanges(ctx *sql.Context, errorEncountered error) error {
	return nil
}

func (e *StaticErrorEditor) StatementComplete(ctx *sql.Context) error {
	return nil
}

func (e *StaticErrorEditor) WithIndexLookup(lookup sql.IndexLookup) sql.Table {
	return &StaticErrorTable{nil, e.err}
}

func (e *StaticErrorEditor) Close(*sql.Context) error {
	// Or e.err?
	return nil
}

func (e *StaticErrorEditor) IndexedAccess(_ sql.IndexLookup) sql.IndexedTable {
	return &StaticErrorTable{nil, e.err}
}

func (e *StaticErrorEditor) GetIndexes(ctx *sql.Context) ([]sql.Index, error) {
	return nil, nil
}

repository: dolthub/dolt

repo_name: dolthub/dolt


text:
@article{pub2000,
  title={Grating Couplers for Coupling between Optical Fibers and Nanophotonic Waveguides},
  author={Dirk TAILLAERT and Frederik VAN LAERE},
  journal={The Japan Society of Applied Physics},
  year={2006}
}
@article{oe241821027beamwidth,
  title={Accurate theoretical and experimental characterization of optical grating coupler},
  author={FAEZEH FESHARAKI and NADIR HOSSAIN},
  journal={Optics Express},
  year={2016}
}
@article{tamirPeng1977,
  title={Analysis and Design of Grating Couples},
  author={T Tamir and T. Peng},
  journal={Applied Physics by Spring Verlag},
  year={1977}
}
@article{hongChoSungFWHMsize,
  title={Design Parameter Optimization of a Silicon-Based Grating Waveguide for Performance Improvement in Biochemical Sensor Application},
  author={Yoo-Seung Hong and Chun-Hyung Cho},
  journal={Sensors},
  year={2018}
}
@article{00248941,
  title={Analysis and Design of Broadband Grating couplers},
  author={Zhang and Tamir},
  journal={IEEE},
  year={1993}
}
@article{pic2,
  title={High-resolution aliasing-free optical beam steering},
  author={DAVID N. HUTCHISON and JIE SUN},
  journal={Optica},
  year={2016}
}

license: MIT

repository: sanammt/lidar

license_type: permissive

repo_name: sanammt/lidar

branch_name: refs/heads/master

extension: bib


text:
package create

import (
	"fmt"

	"github.com/spf13/cobra"

	"k8s.io/apimachinery/pkg/api/meta"
	"k8s.io/cli-runtime/pkg/genericclioptions"
	"k8s.io/cli-runtime/pkg/printers"
	corev1client "k8s.io/client-go/kubernetes/typed/core/v1"
	cmdutil "k8s.io/kubectl/pkg/cmd/util"
	kcmdutil "k8s.io/kubectl/pkg/cmd/util"
	"k8s.io/kubectl/pkg/scheme"
	"k8s.io/kubectl/pkg/util/templates"

	routev1client "github.com/openshift/client-go/route/clientset/versioned/typed/route/v1"
)

var (
	routeLong = templates.LongDesc(`
		Expose containers externally via secured routes.

		Three types of secured routes are supported: edge, passthrough, and reencrypt.
		If you want to create unsecured routes, see "oc expose -h".
	`)
)

// NewCmdCreateRoute is a macro command to create a secured route.
func NewCmdCreateRoute(f kcmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
	cmd := &cobra.Command{
		Use:   "route",
		Short: "Expose containers externally via secured routes",
		Long:  routeLong,
		Run:   kcmdutil.DefaultSubCommandRun(streams.ErrOut),
	}

	cmd.AddCommand(NewCmdCreateEdgeRoute(f, streams))
	cmd.AddCommand(NewCmdCreatePassthroughRoute(f, streams))
	cmd.AddCommand(NewCmdCreateReencryptRoute(f, streams))

	return cmd
}

// CreateRouteSubcommandOptions is an options struct to support create subcommands
type CreateRouteSubcommandOptions struct {
	// PrintFlags holds options necessary for obtaining a printer
	PrintFlags *genericclioptions.PrintFlags
	// Name of resource being created
	Name        string
	ServiceName string

	DryRunStrategy kcmdutil.DryRunStrategy

	Namespace        string
	EnforceNamespace bool
	CreateAnnotation bool

	Mapper meta.RESTMapper

	Printer printers.ResourcePrinter

	Client     routev1client.RoutesGetter
	CoreClient corev1client.CoreV1Interface

	genericclioptions.IOStreams
}

func NewCreateRouteSubcommandOptions(ioStreams genericclioptions.IOStreams) *CreateRouteSubcommandOptions {
	return &CreateRouteSubcommandOptions{
		PrintFlags: genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme),
		IOStreams:  ioStreams,
	}
}

func (o *CreateRouteSubcommandOptions) AddFlags(cmd *cobra.Command) {
	o.PrintFlags.AddFlags(cmd)
	cmdutil.AddApplyAnnotationVarFlags(cmd, &o.CreateAnnotation)
}

func (o *CreateRouteSubcommandOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, args []string) error {
	var err error
	o.Name, err = resolveRouteName(args)
	if err != nil {
		return err
	}

	clientConfig, err := f.ToRESTConfig()
	if err != nil {
		return err
	}

	o.CoreClient, err = corev1client.NewForConfig(clientConfig)
	if err != nil {
		return err
	}

	o.Client, err = routev1client.NewForConfig(clientConfig)
	if err != nil {
		return err
	}

	o.Mapper, err = f.ToRESTMapper()
	if err != nil {
		return err
	}
	o.Namespace, o.EnforceNamespace, err = f.ToRawKubeConfigLoader().Namespace()
	if err != nil {
		return err
	}

	o.CreateAnnotation = cmdutil.GetFlagBool(cmd, cmdutil.ApplyAnnotationsFlag)

	o.DryRunStrategy, err = kcmdutil.GetDryRunStrategy(cmd)
	if err != nil {
		return err
	}
	kcmdutil.PrintFlagsWithDryRunStrategy(o.PrintFlags, o.DryRunStrategy)
	o.Printer, err = o.PrintFlags.ToPrinter()
	if err != nil {
		return err
	}

	return nil
}

func resolveRouteName(args []string) (string, error) {
	switch len(args) {
	case 0:
	case 1:
		return args[0], nil
	default:
		return "", fmt.Errorf("multiple names provided. Please specify at most one")
	}
	return "", nil
}

repository: openshift/oc

repo_name: openshift/oc

gha_language: Go

extension: go


text:
package dfile

import (
	"bufio"
	"github.com/osgochina/donkeygo/util/dconv"
	"io"
	"io/ioutil"
	"os"
)

var (
	// DefaultReadBuffer 读取文件的缓冲区大小
	DefaultReadBuffer = 1024
)

// GetContents 获取文件内容，返回字符串信息
func GetContents(path string) string {
	return dconv.UnsafeBytesToStr(GetBytes(path))
}

// GetBytes 获取文件内容，返回byte数组
func GetBytes(path string) []byte {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		return nil
	}
	return data
}

//写入内容到文件
func putContents(path string, data []byte, flag int, perm os.FileMode) error {
	dir := Dir(path)
	if !Exists(dir) {
		if err := Mkdir(dir); err != nil {
			return err
		}
	}
	//使用特殊的标识打开文件
	f, err := OpenWithFlagPerm(path, flag, perm)
	if err != nil {
		return err
	}
	defer f.Close()
	if n, e := f.Write(data); e != nil {
		return e
	} else if n < len(data) {
		return io.ErrShortWrite
	}
	return nil
}

// Truncate 截断文件到指定的大小
func Truncate(path string, size int) error {
	return os.Truncate(path, int64(size))
}

// PutContents 写入字符串内容到文件，文件不存在则创建，如果存在则从头开始写
func PutContents(path string, content string) error {
	return putContents(path, []byte(content), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, DefaultPermOpen)
}

// PutContentsAppend 追加写入字符串内容到文件末尾，文件不存在则创建，已存在则写到末尾
func PutContentsAppend(path string, content string) error {
	return putContents(path, []byte(content), os.O_WRONLY|os.O_CREATE|os.O_APPEND, DefaultPermOpen)
}

// PutBytes 写入字节数组内容到文件，文件不存在则创建，如果存在则从头开始写
func PutBytes(path string, content []byte) error {
	return putContents(path, content, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, DefaultPermOpen)
}

// PutBytesAppend 追加写入字节数组内容到文件末尾，文件不存在则创建，已存在则写到末尾
func PutBytesAppend(path string, content []byte) error {
	return putContents(path, content, os.O_WRONLY|os.O_CREATE|os.O_APPEND, DefaultPermOpen)
}

// GetNextCharOffset 从指定位置开始读取数据，碰到与char相等的字节返回它所在的位置
func GetNextCharOffset(reader io.ReaderAt, char byte, start int64) int64 {
	buffer := make([]byte, DefaultReadBuffer)
	offset := start
	for {
		if n, err := reader.ReadAt(buffer, offset); n > 0 {
			for i := 0; i < n; i++ {
				if buffer[i] == char {
					return int64(i) + offset
				}
			}
			offset += int64(n)
		} else if err != nil {
			break
		}
	}
	return -1
}

// GetNextCharOffsetByPath 获取指定文件中char所在的位置，从start开始查找
func GetNextCharOffsetByPath(path string, char byte, start int64) int64 {
	if f, err := OpenWithFlagPerm(path, os.O_RDONLY, DefaultPermOpen); err == nil {
		defer f.Close()
		return GetNextCharOffset(f, char, start)
	}
	return -1
}

// GetBytesTilChar 获取从指定字符到结尾所有的字符数组
func GetBytesTilChar(reader io.ReaderAt, char byte, start int64) ([]byte, int64) {
	if offset := GetNextCharOffset(reader, char, start); offset != -1 {
		return GetBytesByTwoOffsets(reader, start, offset+1), offset
	}
	return nil, -1
}

// GetBytesTilCharByPath 获取文件中从start位置开始，找到的第一个char字符，一直到文件结尾的内容
func GetBytesTilCharByPath(path string, char byte, start int64) ([]byte, int64) {
	if f, err := OpenWithFlagPerm(path, os.O_RDONLY, DefaultPermOpen); err == nil {
		defer f.Close()
		return GetBytesTilChar(f, char, start)
	}
	return nil, -1
}

// GetBytesByTwoOffsets 获取指定区间的字符内容
func GetBytesByTwoOffsets(reader io.ReaderAt, start int64, end int64) []byte {
	buffer := make([]byte, end-start)
	if _, err := reader.ReadAt(buffer, start); err != nil {
		return nil
	}
	return buffer
}

// GetBytesByTwoOffsetsByPath 获取文件中从start开始到end结束区间的内容
func GetBytesByTwoOffsetsByPath(path string, start int64, end int64) []byte {
	if f, err := OpenWithFlagPerm(path, os.O_RDONLY, DefaultPermOpen); err == nil {
		defer f.Close()
		return GetBytesByTwoOffsets(f, start, end)
	}
	return nil
}

// ReadLines 逐行读取文件内容，读取一行则回调一次callback方法
func ReadLines(file string, callback func(text string) error) error {
	f, err := os.Open(file)
	if err != nil {
		return err
	}
	defer f.Close()

	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		if err = callback(scanner.Text()); err != nil {
			return err
		}
	}
	return nil
}

// ReadByteLines 逐行读取文件内容，读取一行回调一次callback方法
func ReadByteLines(file string, callback func(bytes []byte) error) error {
	return ReadLinesBytes(file, callback)
}

// ReadLinesBytes 逐行读取文件内容，读取一行回调一次callback方法
func ReadLinesBytes(file string, callback func(bytes []byte) error) error {
	f, err := os.Open(file)
	if err != nil {
		return err
	}
	defer f.Close()

	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		if err = callback(scanner.Bytes()); err != nil {
			return err
		}
	}
	return nil
}

repository: osgochina/donkeygo

repo_name: osgochina/donkeygo


text:
/**
 *  Copyright 2014 Paul Querna
 *
 *  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 distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package terminfo

type winsize struct {
	ws_row    uint16 /* rows, in characters */
	ws_col    uint16 /* columns, in characters */
	ws_xpixel uint16 /* horizontal size, pixels */
	ws_ypixel uint16 /* vertical size, pixels */
}

func WindowWidth() uint16 {
	ws := getwinsize()
	return ws.ws_col
}

repository: pquerna/termchalk

repo_name: pquerna/termchalk


text:
/*
Copyright © 2020 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 or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
	"fmt"
	"os"

	"github.com/go-redis/redis/v8"
	"github.com/spf13/cobra"
	"github.com/spf13/viper"
)

// applyCmd represents the apply command
var applyCmd = &cobra.Command{
	Use:   "apply <file-path>",
	Short: "Apply environment configuration to cluster",
	Long:  `Loads all the scripts and endpoints to configure a cluster.`,
	Run: func(cmd *cobra.Command, args []string) {
		redisAddress := viper.GetViper().GetString("redis-address")
		redisPassword := viper.GetViper().GetString("redis-password")

		client := redis.NewClient(&redis.Options{
			Addr:     redisAddress,
			Password: redisPassword, // no password set
			DB:       0,             // use default DB
		})

		if len(os.Args) > 2 {
			fileName := os.Args[2]
			fmt.Println(loadEnvironment(client, fileName))
		} else {
			fmt.Println("No file")
			return
		}
	},
}

func init() {
	rootCmd.AddCommand(applyCmd)

	// Here you will define your flags and configuration settings.

	// Cobra supports Persistent Flags which will work for this command
	// and all subcommands, e.g.:
	// applyCmd.PersistentFlags().String("foo", "", "A help for foo")

	// Cobra supports local flags which will only run when this command
	// is called directly, e.g.:
	// applyCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

repository: jaeg/hatter

repo_name: jaeg/hatter


text:
// Copyright 2014 Tim Heckman. All rights reserved.
// Use of this source code is governed by the BSD 3-Clause
// license that can be found in the LICENSE file.

package main

import (
	"bytes"
	"fmt"
	"net"
	"os"
	"strings"

	"github.com/jessevdk/go-flags"
)

type args struct {
	Host string `short:"h" long:"host" default:"127.0.0.1" description:"IP to bind to"`
	Port uint16 `short:"p" long:"port" default:"8125" description:"UDP port to bind to"`
}

func (a *args) parse() {
	parser := flags.NewParser(a, flags.HelpFlag|flags.PassDoubleDash)

	_, err := parser.Parse()

	// if parsing bombed and it's not the help message
	// we need to print the error
	if err != nil {
		if !strings.Contains(err.Error(), "Usage") {
			fmt.Fprintf(os.Stderr, "error: %v\n", err.Error())
			os.Exit(1)
		} else {
			fmt.Fprintf(os.Stderr, "%v\n", err.Error())
			os.Exit(0)
		}
	}
}

func NewUDPListener(host string, port uint16) *net.UDPConn {
	addr, err := net.ResolveUDPAddr("udp", fmt.Sprintf("%v:%d", host, port))

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	l, err := net.ListenUDP("udp", addr)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	return l
}

func Printer(listener *net.UDPConn, out chan<- []byte) {
	defer func() {
		_ = recover()
	}()

	defer close(out)

	for {
		b := make([]byte, 8192)

		_, err := listener.Read(b)

		if err != nil {
			close(out)
			break
		}

		out <- bytes.Trim(b, "\x00")
	}
}

func main() {
	var (
		a  = &args{}
		ch = make(chan []byte, 8)
	)

	a.parse()

	l := NewUDPListener(a.Host, a.Port)

	fmt.Fprintf(os.Stderr, ">> Starting UDPDumper...\n")
	fmt.Fprintf(os.Stderr, ">> Listening at %v:%d...\n\n", a.Host, a.Port)

	go Printer(l, ch)

	for v := range ch {
		fmt.Printf("%v<EOF>\n", string(v))
	}
}

repository: theckman/udpdumper

repo_name: theckman/udpdumper