_id stringlengths 2 7 | title stringlengths 1 118 | partition stringclasses 3
values | text stringlengths 52 85.5k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q28600 | Init | train | func (ft *FieldType) Init(tp byte) {
ft.Tp = tp
ft.Flen = UnspecifiedLength
ft.Decimal = UnspecifiedLength
} | go | {
"resource": ""
} |
q28601 | String | train | func (ft *FieldType) String() string {
strs := []string{ft.CompactStr()}
if mysql.HasUnsignedFlag(ft.Flag) {
strs = append(strs, "UNSIGNED")
}
if mysql.HasZerofillFlag(ft.Flag) {
strs = append(strs, "ZEROFILL")
}
if mysql.HasBinaryFlag(ft.Flag) {
strs = append(strs, "BINARY")
}
if IsTypeChar(ft.Tp) || Is... | go | {
"resource": ""
} |
q28602 | Sha1Hash | train | func Sha1Hash(bs []byte) []byte {
crypt := sha1.New()
crypt.Write(bs)
return crypt.Sum(nil)
} | go | {
"resource": ""
} |
q28603 | EncodePassword | train | func EncodePassword(pwd string) string {
if len(pwd) == 0 {
return ""
}
hash := Sha1Hash([]byte(pwd))
return hex.EncodeToString(hash)
} | go | {
"resource": ""
} |
q28604 | DecodePassword | train | func DecodePassword(pwd string) ([]byte, error) {
x, err := hex.DecodeString(pwd)
if err != nil {
return nil, errors.Trace(err)
}
return x, nil
} | go | {
"resource": ""
} |
q28605 | Join | train | func (d *Dataset) Join(name string, other *Dataset, sortOption *SortOption) *Dataset {
return d.DoJoin(name, other, false, false, sortOption)
} | go | {
"resource": ""
} |
q28606 | JoinPartitionedSorted | train | func (this *Dataset) JoinPartitionedSorted(name string, that *Dataset, sortOption *SortOption,
isLeftOuterJoin, isRightOuterJoin bool) *Dataset {
ret := this.Flow.NewNextDataset(len(this.Shards))
ret.IsPartitionedBy = that.IsPartitionedBy
ret.IsLocalSorted = that.IsLocalSorted
inputs := []*Dataset{this, that}
st... | go | {
"resource": ""
} |
q28607 | EvalBool | train | func EvalBool(expr Expression, row []types.Datum, ctx context.Context) (bool, error) {
data, err := expr.Eval(row, ctx)
if err != nil {
return false, errors.Trace(err)
}
if data.IsNull() {
return false, nil
}
i, err := data.ToBool(ctx.GetSessionVars().StmtCtx)
if err != nil {
return false, errors.Trace(er... | go | {
"resource": ""
} |
q28608 | TableInfo2Schema | train | func TableInfo2Schema(tbl *model.TableInfo) Schema {
schema := NewSchema(make([]*Column, 0, len(tbl.Columns)))
keys := make([]KeyInfo, 0, len(tbl.Indices)+1)
for i, col := range tbl.Columns {
newCol := &Column{
ColName: col.Name,
TblName: tbl.Name,
RetType: &col.FieldType,
Position: i,
}
schema.... | go | {
"resource": ""
} |
q28609 | NewCastFunc | train | func NewCastFunc(tp *types.FieldType, arg Expression, ctx context.Context) *ScalarFunction {
bt := &builtinCastSig{newBaseBuiltinFunc([]Expression{arg}, ctx), tp}
return &ScalarFunction{
FuncName: model.NewCIStr(ast.Cast),
RetType: tp,
Function: bt,
}
} | go | {
"resource": ""
} |
q28610 | FoldConstant | train | func FoldConstant(ctx context.Context, expr Expression) Expression {
scalarFunc, ok := expr.(*ScalarFunction)
if !ok {
return expr
}
if _, isDynamic := DynamicFuncs[scalarFunc.FuncName.L]; isDynamic {
return expr
}
args := scalarFunc.GetArgs()
canFold := true
for i := 0; i < len(args); i++ {
foldedArg := ... | go | {
"resource": ""
} |
q28611 | TakeMessage | train | func TakeMessage(reader io.Reader, count int, f func([]byte) error) (err error) {
if _, isBufioReader := reader.(*bufio.Reader); !isBufioReader {
reader = bufio.NewReader(reader)
}
for err == nil {
if count == 0 {
io.Copy(ioutil.Discard, reader)
return nil
}
message, readError := ReadMessage(reader)
... | go | {
"resource": ""
} |
q28612 | ProcessMessage | train | func ProcessMessage(reader io.Reader, f func([]byte) error) (err error) {
return TakeMessage(reader, -1, f)
} | go | {
"resource": ""
} |
q28613 | Write | train | func (l *SingleFileStore) Write(p []byte) (n int, err error) {
l.mu.Lock()
defer l.mu.Unlock()
if l.file == nil {
if err = l.openNew(); err != nil {
return 0, err
}
}
l.file.Seek(0, 2)
n, err = l.file.Write(p)
l.size += int64(n)
l.Position += int64(n)
l.waitForReading.Broadcast()
return n, err
} | go | {
"resource": ""
} |
q28614 | mergeStats | train | func mergeStats(a, b []*pb.InstructionStat) (ret []*pb.InstructionStat) {
var nonOverlapping []*pb.InstructionStat
for _, ai := range a {
var found bool
for _, bi := range b {
if ai.StepId == bi.StepId {
found = true
if ai.InputCounter > bi.InputCounter {
ret = append(ret, ai)
} else {
re... | go | {
"resource": ""
} |
q28615 | tryToConvert2DummyScan | train | func (p *DataSource) tryToConvert2DummyScan(prop *requiredProperty) (*physicalPlanInfo, error) {
sel, isSel := p.GetParentByIndex(0).(*Selection)
if !isSel {
return nil, nil
}
for _, cond := range sel.Conditions {
if con, ok := cond.(*expression.Constant); ok {
result, err := expression.EvalBool(con, nil, p... | go | {
"resource": ""
} |
q28616 | removeLimit | train | func removeLimit(prop *requiredProperty) *requiredProperty {
ret := &requiredProperty{
props: prop.props,
sortKeyLen: prop.sortKeyLen,
}
return ret
} | go | {
"resource": ""
} |
q28617 | replaceColsInPropBySchema | train | func replaceColsInPropBySchema(prop *requiredProperty, schema expression.Schema) *requiredProperty {
newProps := make([]*columnProp, 0, len(prop.props))
for _, p := range prop.props {
idx := schema.GetColumnIndex(p.col)
if idx == -1 {
log.Printf("Can't find column %s in schema", p.col)
}
newProps = append(... | go | {
"resource": ""
} |
q28618 | convert2PhysicalPlanHash | train | func (p *Aggregation) convert2PhysicalPlanHash() (*physicalPlanInfo, error) {
childInfo, err := p.children[0].(LogicalPlan).convert2PhysicalPlan(&requiredProperty{})
if err != nil {
return nil, errors.Trace(err)
}
distinct := false
for _, fun := range p.AggFuncs {
if fun.IsDistinct() {
distinct = true
br... | go | {
"resource": ""
} |
q28619 | physicalInitialize | train | func physicalInitialize(p PhysicalPlan) {
for _, child := range p.GetChildren() {
physicalInitialize(child.(PhysicalPlan))
}
// initialize attributes
p.SetCorrelated()
} | go | {
"resource": ""
} |
q28620 | EncodeInt | train | func EncodeInt(b []byte, v int64) []byte {
var data [8]byte
u := encodeIntToCmpUint(v)
binary.BigEndian.PutUint64(data[:], u)
return append(b, data[:]...)
} | go | {
"resource": ""
} |
q28621 | DecodeIntDesc | train | func DecodeIntDesc(b []byte) ([]byte, int64, error) {
if len(b) < 8 {
return nil, 0, errors.New("insufficient bytes to decode value")
}
u := binary.BigEndian.Uint64(b[:8])
v := decodeCmpUintToInt(^u)
b = b[8:]
return b, v, nil
} | go | {
"resource": ""
} |
q28622 | StrToInt | train | func StrToInt(sc *variable.StatementContext, str string) (int64, error) {
str = strings.TrimSpace(str)
validPrefix, err := getValidIntPrefix(sc, str)
iVal, err1 := strconv.ParseInt(validPrefix, 10, 64)
if err1 != nil {
return iVal, errors.Trace(ErrOverflow)
}
return iVal, errors.Trace(err)
} | go | {
"resource": ""
} |
q28623 | floatStrToIntStr | train | func floatStrToIntStr(validFloat string) (string, error) {
var dotIdx = -1
var eIdx = -1
for i := 0; i < len(validFloat); i++ {
switch validFloat[i] {
case '.':
dotIdx = i
case 'e', 'E':
eIdx = i
}
}
if eIdx == -1 {
if dotIdx == -1 {
return validFloat, nil
}
return validFloat[:dotIdx], nil
... | go | {
"resource": ""
} |
q28624 | getValidFloatPrefix | train | func getValidFloatPrefix(sc *variable.StatementContext, s string) (valid string, err error) {
var (
sawDot bool
sawDigit bool
validLen int
eIdx int
)
for i := 0; i < len(s); i++ {
c := s[i]
if c == '+' || c == '-' {
if i != 0 && i != eIdx+1 { // "1e+1" is valid.
break
}
} else if c == '... | go | {
"resource": ""
} |
q28625 | ToString | train | func ToString(value interface{}) (string, error) {
switch v := value.(type) {
case bool:
if v {
return "1", nil
}
return "0", nil
case int:
return strconv.FormatInt(int64(v), 10), nil
case int64:
return strconv.FormatInt(int64(v), 10), nil
case uint64:
return strconv.FormatUint(uint64(v), 10), nil
... | go | {
"resource": ""
} |
q28626 | Validate | train | func Validate(node ast.Node, inPrepare bool) error {
v := validator{inPrepare: inPrepare}
node.Accept(&v)
return v.err
} | go | {
"resource": ""
} |
q28627 | outerJoinSimplify | train | func outerJoinSimplify(p *Join, predicates []expression.Expression) error {
var innerTable, outerTable LogicalPlan
child1 := p.GetChildByIndex(0).(LogicalPlan)
child2 := p.GetChildByIndex(1).(LogicalPlan)
var fullConditions []expression.Expression
if p.JoinType == LeftOuterJoin {
innerTable = child2
outerTable... | go | {
"resource": ""
} |
q28628 | concatOnAndWhereConds | train | func concatOnAndWhereConds(join *Join, predicates []expression.Expression) []expression.Expression {
equalConds, leftConds, rightConds, otherConds := join.EqualConditions, join.LeftConditions, join.RightConditions, join.OtherConditions
ans := make([]expression.Expression, 0, len(equalConds)+len(leftConds)+len(rightCo... | go | {
"resource": ""
} |
q28629 | fieldsNotEmpty | train | func (z *Row) fieldsNotEmpty(isempty []bool) uint32 {
if len(isempty) == 0 {
return 3
}
var fieldsInUse uint32 = 3
isempty[0] = (len(z.K) == 0) // string, omitempty
if isempty[0] {
fieldsInUse--
}
isempty[1] = (len(z.V) == 0) // string, omitempty
if isempty[1] {
fieldsInUse--
}
isempty[2] = (z.T == 0) /... | go | {
"resource": ""
} |
q28630 | PropagateConstant | train | func PropagateConstant(ctx context.Context, conditions []Expression) []Expression {
solver := &propagateConstantSolver{
colMapper: make(map[string]int),
ctx: ctx,
}
return solver.solve(conditions)
} | go | {
"resource": ""
} |
q28631 | By | train | func (o *SortOption) By(index int, ascending bool) *SortOption {
order := instruction.Descending
if ascending {
order = instruction.Ascending
}
o.orderByList = append(o.orderByList, instruction.OrderBy{
Index: index,
Order: order,
})
return o
} | go | {
"resource": ""
} |
q28632 | Indexes | train | func (o *SortOption) Indexes() []int {
var ret []int
for _, x := range o.orderByList {
ret = append(ret, x.Index)
}
return ret
} | go | {
"resource": ""
} |
q28633 | RetrieveColumn | train | func (s Schema) RetrieveColumn(col *Column) *Column {
index := s.GetColumnIndex(col)
if index != -1 {
return s.Columns[index]
}
return nil
} | go | {
"resource": ""
} |
q28634 | GetColumnIndex | train | func (s Schema) GetColumnIndex(col *Column) int {
for i, c := range s.Columns {
if c.FromID == col.FromID && c.Position == col.Position {
return i
}
}
return -1
} | go | {
"resource": ""
} |
q28635 | Append | train | func (s *Schema) Append(col *Column) {
s.Columns = append(s.Columns, col)
} | go | {
"resource": ""
} |
q28636 | GetColumnsIndices | train | func (s Schema) GetColumnsIndices(cols []*Column) (ret []int) {
ret = make([]int, 0, len(cols))
for _, col := range cols {
pos := s.GetColumnIndex(col)
if pos != -1 {
ret = append(ret, pos)
} else {
return nil
}
}
return
} | go | {
"resource": ""
} |
q28637 | MergeSchema | train | func MergeSchema(lSchema, rSchema Schema) Schema {
tmpL := lSchema.Clone()
tmpR := rSchema.Clone()
ret := NewSchema(append(tmpL.Columns, tmpR.Columns...))
ret.SetUniqueKeys(append(tmpL.Keys, tmpR.Keys...))
return ret
} | go | {
"resource": ""
} |
q28638 | HashJoin | train | func (bigger *Dataset) HashJoin(name string, smaller *Dataset, sortOption *SortOption) *Dataset {
return smaller.Broadcast(name, len(bigger.Shards)).LocalHashAndJoinWith(name, bigger, sortOption)
} | go | {
"resource": ""
} |
q28639 | Broadcast | train | func (d *Dataset) Broadcast(name string, shardCount int) *Dataset {
if shardCount == 1 && len(d.Shards) == shardCount {
return d
}
ret := d.Flow.NewNextDataset(shardCount)
step := d.Flow.AddOneToAllStep(d, ret)
step.SetInstruction(name, instruction.NewBroadcast())
return ret
} | go | {
"resource": ""
} |
q28640 | linelabel | train | func linelabel(canvas *svg.SVG, x1, y1, x2, y2 int, label string, mark string, d1 string, d2 string, dir string, color string) {
aw := linesize * 4
ah := linesize * 3
if len(color) == 0 {
color = lcolor
}
switch mark {
case "b":
lx1, ly1 := arrow(canvas, x1, y1, aw, ah, d1, color)
lx2, ly2 := arrow(canvas,... | go | {
"resource": ""
} |
q28641 | arrow | train | func arrow(canvas *svg.SVG, x, y, w, h int, dir string, color string) (xl, yl int) {
var xp = []int{x, x, x, x}
var yp = []int{y, y, y, y}
n := notchsize
switch dir {
case "r":
xp[1] = x - w
yp[1] = y - h/2
xp[2] = (x - w) + n
yp[2] = y
xp[3] = x - w
yp[3] = y + h/2
xl, yl = xp[2], y
case "l":
xp... | go | {
"resource": ""
} |
q28642 | doline | train | func doline(canvas *svg.SVG, x1, y1, x2, y2 int, style, direction, label string) {
var labelstyle string
var upflag bool
tadjust := 6
mx := (x2 - x1) / 2
my := (y2 - y1) / 2
lx := x1 + mx
ly := y1 + my
m, _ := sloper(x1, y1, x2, y2)
hline := m == 0
vline := m == math.Inf(-1) || m == math.Inf(1)
straight := ... | go | {
"resource": ""
} |
q28643 | sloper | train | func sloper(x1, y1, x2, y2 int) (m, r float64) {
dy := float64(y1 - y2)
dx := float64(x1 - x2)
m = dy / dx
r = math.Atan2(dy, dx) * (180 / math.Pi)
return m, r
} | go | {
"resource": ""
} |
q28644 | RegisterMapper | train | func RegisterMapper(fn Mapper) MapperId {
mappersLock.Lock()
defer mappersLock.Unlock()
mapperId := MapperId(fmt.Sprintf("m%d", len(mappers)+1))
mappers[mapperId] = MapperObject{fn, runtime.FuncForPC(reflect.ValueOf(fn).Pointer()).Name()}
return mapperId
} | go | {
"resource": ""
} |
q28645 | ListRegisteredFunctions | train | func ListRegisteredFunctions() {
for k, fn := range mappers {
println(k, "=>", fn.Name)
}
for k, fn := range reducers {
println(k, "=>", fn.Name)
}
} | go | {
"resource": ""
} |
q28646 | getHashKey | train | func (p *requiredProperty) getHashKey() ([]byte, error) {
datums := make([]types.Datum, 0, len(p.props)*3+1)
datums = append(datums, types.NewDatum(p.sortKeyLen))
for _, c := range p.props {
datums = append(datums, types.NewDatum(c.desc), types.NewDatum(c.col.FromID), types.NewDatum(c.col.Index))
}
bytes, err :=... | go | {
"resource": ""
} |
q28647 | ResolveIndicesAndCorCols | train | func (p *baseLogicalPlan) ResolveIndicesAndCorCols() {
for _, child := range p.children {
child.(LogicalPlan).ResolveIndicesAndCorCols()
}
} | go | {
"resource": ""
} |
q28648 | AddParent | train | func (p *basePlan) AddParent(parent Plan) {
p.parents = append(p.parents, parent)
} | go | {
"resource": ""
} |
q28649 | AddChild | train | func (p *basePlan) AddChild(child Plan) {
p.children = append(p.children, child)
} | go | {
"resource": ""
} |
q28650 | ReplaceParent | train | func (p *basePlan) ReplaceParent(parent, newPar Plan) error {
for i, par := range p.parents {
if par.GetID() == parent.GetID() {
p.parents[i] = newPar
return nil
}
}
return SystemInternalErrorType.Gen("ReplaceParent Failed!")
} | go | {
"resource": ""
} |
q28651 | ReplaceChild | train | func (p *basePlan) ReplaceChild(child, newChild Plan) error {
for i, ch := range p.children {
if ch.GetID() == child.GetID() {
p.children[i] = newChild
return nil
}
}
return SystemInternalErrorType.Gen("ReplaceChildren Failed!")
} | go | {
"resource": ""
} |
q28652 | GetParentByIndex | train | func (p *basePlan) GetParentByIndex(index int) (parent Plan) {
if index < len(p.parents) && index >= 0 {
return p.parents[index]
}
return nil
} | go | {
"resource": ""
} |
q28653 | GetChildByIndex | train | func (p *basePlan) GetChildByIndex(index int) (parent Plan) {
if index < len(p.children) && index >= 0 {
return p.children[index]
}
return nil
} | go | {
"resource": ""
} |
q28654 | serveTcp | train | func (as *AgentServer) serveTcp(listener net.Listener) {
for {
// Listen for an incoming connection.
conn, err := listener.Accept()
if err != nil {
fmt.Println("Error accepting: ", err.Error())
continue
}
// Handle connections in a new goroutine.
go func() {
defer conn.Close()
if err = conn.Se... | go | {
"resource": ""
} |
q28655 | IsTypeBlob | train | func IsTypeBlob(tp byte) bool {
switch tp {
case mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeBlob, mysql.TypeLongBlob:
return true
default:
return false
}
} | go | {
"resource": ""
} |
q28656 | IsTypeChar | train | func IsTypeChar(tp byte) bool {
switch tp {
case mysql.TypeString, mysql.TypeVarchar:
return true
default:
return false
}
} | go | {
"resource": ""
} |
q28657 | overflow | train | func overflow(v interface{}, tp byte) error {
return errors.Errorf("constant %v overflows %s", v, TypeStr(tp))
} | go | {
"resource": ""
} |
q28658 | DoSelect | train | func DoSelect(reader io.Reader, writer io.Writer, keyIndexes, valueIndexes []int, stats *pb.InstructionStat) error {
return util.ProcessRow(reader, nil, func(row *util.Row) error {
stats.InputCounter++
var keys, values []interface{}
kLen := len(row.K)
for _, x := range keyIndexes {
if x <= kLen {
keys... | go | {
"resource": ""
} |
q28659 | NextInterval | train | func (r *retrier) NextInterval(retry int) time.Duration {
return r.backoff.Next(retry)
} | go | {
"resource": ""
} |
q28660 | WithHTTPTimeout | train | func WithHTTPTimeout(timeout time.Duration) Option {
return func(c *Client) {
c.timeout = timeout
}
} | go | {
"resource": ""
} |
q28661 | WithHystrixTimeout | train | func WithHystrixTimeout(timeout time.Duration) Option {
return func(c *Client) {
c.hystrixTimeout = timeout
}
} | go | {
"resource": ""
} |
q28662 | WithRetrier | train | func WithRetrier(retrier heimdall.Retriable) Option {
return func(c *Client) {
c.retrier = retrier
}
} | go | {
"resource": ""
} |
q28663 | WithHTTPClient | train | func WithHTTPClient(client heimdall.Doer) Option {
return func(c *Client) {
c.client = client
}
} | go | {
"resource": ""
} |
q28664 | NewClient | train | func NewClient(opts ...Option) *Client {
client := Client{
timeout: defaultHTTPTimeout,
retryCount: defaultRetryCount,
retrier: heimdall.NewNoRetrier(),
}
for _, opt := range opts {
opt(&client)
}
if client.client == nil {
client.client = &http.Client{
Timeout: client.timeout,
}
}
return ... | go | {
"resource": ""
} |
q28665 | Next | train | func (cb *constantBackoff) Next(retry int) time.Duration {
if retry <= 0 {
return 0 * time.Millisecond
}
return (time.Duration(cb.backoffInterval) * time.Millisecond) + (time.Duration(rand.Int63n(cb.maximumJitterInterval)) * time.Millisecond)
} | go | {
"resource": ""
} |
q28666 | Next | train | func (eb *exponentialBackoff) Next(retry int) time.Duration {
if retry <= 0 {
return 0 * time.Millisecond
}
return time.Duration(math.Min(eb.initialTimeout+math.Pow(eb.exponentFactor, float64(retry)), eb.maxTimeout)+float64(rand.Int63n(eb.maximumJitterInterval))) * time.Millisecond
} | go | {
"resource": ""
} |
q28667 | NewClient | train | func NewClient(opts ...Option) *Client {
client := Client{
timeout: defaultHTTPTimeout,
hystrixTimeout: defaultHystrixTimeout,
maxConcurrentRequests: defaultMaxConcurrentRequests,
errorPercentThreshold: defaultErrorPercentThreshold,
sleepWindow: defaultSleepWindow,
reque... | go | {
"resource": ""
} |
q28668 | Patch | train | func (hhc *Client) Patch(url string, body io.Reader, headers http.Header) (*http.Response, error) {
var response *http.Response
request, err := http.NewRequest(http.MethodPatch, url, body)
if err != nil {
return response, errors.Wrap(err, "PATCH - request creation failed")
}
request.Header = headers
return hh... | go | {
"resource": ""
} |
q28669 | Delete | train | func (hhc *Client) Delete(url string, headers http.Header) (*http.Response, error) {
var response *http.Response
request, err := http.NewRequest(http.MethodDelete, url, nil)
if err != nil {
return response, errors.Wrap(err, "DELETE - request creation failed")
}
request.Header = headers
return hhc.Do(request)
... | go | {
"resource": ""
} |
q28670 | CopyTo | train | func CopyTo(ctx context.Context, name string, content []byte) error {
if clipboard.Unsupported {
out.Yellow(ctx, "%s", ErrNotSupported)
return nil
}
if err := clipboard.WriteAll(string(content)); err != nil {
return errors.Wrapf(err, "failed to write to clipboard")
}
if err := clear(ctx, content, ctxutil.G... | go | {
"resource": ""
} |
q28671 | GetCryptoBackend | train | func GetCryptoBackend(ctx context.Context, cb backend.CryptoBackend, cfgdir string, agent *client.Client) (backend.Crypto, error) {
ctx = client.WithClient(ctx, agent)
ctx = ctxutil.WithConfigDir(ctx, cfgdir)
crypto, err := backend.NewCrypto(ctx, cb)
if err != nil {
return nil, errors.Wrapf(err, "unknown crypto b... | go | {
"resource": ""
} |
q28672 | Generate | train | func (s *Action) Generate(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
edit := c.Bool("edit")
args, kvps := parseArgs(c)
name := args.Get(0)
key, length := keyAndLength(args)
// ask for name of the secret if it wasn't provided already
if name == "" {
var err error
name, err = termi... | go | {
"resource": ""
} |
q28673 | generateCopyOrPrint | train | func (s *Action) generateCopyOrPrint(ctx context.Context, c *cli.Context, name, key, password string) error {
if ctxutil.IsAutoPrint(ctx) || c.Bool("print") {
if key != "" {
key = " " + key
}
out.Print(
ctx,
"The generated password for %s%s is:\n%s", name, key,
color.YellowString(password),
)
}
... | go | {
"resource": ""
} |
q28674 | generatePassword | train | func (s *Action) generatePassword(ctx context.Context, c *cli.Context, length string) (string, error) {
if c.Bool("xkcd") || c.IsSet("xkcdsep") {
return s.generatePasswordXKCD(ctx, c, length)
}
symbols := ctxutil.IsUseSymbols(ctx)
if c.IsSet("symbols") {
symbols = c.Bool("symbols")
}
var pwlen int
if lengt... | go | {
"resource": ""
} |
q28675 | generatePasswordXKCD | train | func (s *Action) generatePasswordXKCD(ctx context.Context, c *cli.Context, length string) (string, error) {
xkcdSeparator := " "
if c.IsSet("xkcdsep") {
xkcdSeparator = c.String("xkcdsep")
}
var pwlen int
if length == "" {
candidateLength := defaultXKCDLength
question := "How many words should be combined t... | go | {
"resource": ""
} |
q28676 | generateSetPassword | train | func (s *Action) generateSetPassword(ctx context.Context, name, key, password string, kvps map[string]string) (context.Context, error) {
// set a single key in a yaml doc
if key != "" {
sec, ctx, err := s.Store.GetContext(ctx, name)
if err != nil {
return ctx, ExitError(ctx, ExitEncrypt, err, "failed to set ke... | go | {
"resource": ""
} |
q28677 | CompleteGenerate | train | func (s *Action) CompleteGenerate(ctx context.Context, c *cli.Context) {
args := c.Args()
if len(args) < 1 {
return
}
needle := args[0]
_, err := s.Store.Initialized(ctx) // important to make sure the structs are not nil
if err != nil {
out.Error(ctx, "Store not initialized: %s", err)
return
}
list, err ... | go | {
"resource": ""
} |
q28678 | Invoke | train | func Invoke(ctx context.Context, editor string, content []byte) ([]byte, error) {
if !ctxutil.IsTerminal(ctx) {
return nil, errors.New("need terminal")
}
tmpfile, err := tempfile.New(ctx, "gopass-edit")
if err != nil {
return []byte{}, errors.Errorf("failed to create tmpfile %s: %s", editor, err)
}
defer fun... | go | {
"resource": ""
} |
q28679 | Batch | train | func Batch(ctx context.Context, secrets []string, secStore secretGetter) error {
out.Print(ctx, "Checking %d secrets. This may take some time ...\n", len(secrets))
// Secrets that still need auditing.
pending := make(chan string, 100)
// Secrets that have been audited.
checked := make(chan auditedSecret, 100)
... | go | {
"resource": ""
} |
q28680 | Single | train | func Single(ctx context.Context, password string) {
validator := crunchy.NewValidator()
if err := validator.Check(password); err != nil {
out.Cyan(ctx, fmt.Sprintf("Warning: %s", err))
}
} | go | {
"resource": ""
} |
q28681 | Bytes | train | func (s *Secret) Bytes() ([]byte, error) {
if s.d == nil {
return []byte{}, nil
}
buf := &bytes.Buffer{}
if pw, found := s.d[passwordKey]; found {
if sv, ok := pw.(string); ok {
_, _ = buf.WriteString(sv)
}
}
_, _ = buf.WriteString("\n")
keys := make([]string, 0, len(s.d))
for k := range s.d {
keys ... | go | {
"resource": ""
} |
q28682 | Data | train | func (s *Secret) Data() map[string]interface{} {
if s.d == nil {
s.d = make(map[string]interface{})
}
return s.d
} | go | {
"resource": ""
} |
q28683 | DeleteKey | train | func (s *Secret) DeleteKey(key string) error {
if s.d == nil {
return nil
}
delete(s.d, key)
return nil
} | go | {
"resource": ""
} |
q28684 | Equal | train | func (s *Secret) Equal(other store.Secret) bool {
b1, err := s.Bytes()
if err != nil {
return false
}
b2, err := other.Bytes()
if err != nil {
return false
}
return string(b1) == string(b2)
} | go | {
"resource": ""
} |
q28685 | Password | train | func (s *Secret) Password() string {
v := s.d[passwordKey]
if sv, ok := v.(string); ok {
return sv
}
return ""
} | go | {
"resource": ""
} |
q28686 | SetValue | train | func (s *Secret) SetValue(key string, value string) error {
s.d[key] = value
return nil
} | go | {
"resource": ""
} |
q28687 | Value | train | func (s *Secret) Value(key string) (string, error) {
v := s.d[key]
if sv, ok := v.(string); ok {
return sv, nil
}
return "", nil
} | go | {
"resource": ""
} |
q28688 | Initialized | train | func (s *Store) Initialized(ctx context.Context) bool {
if s == nil || s.storage == nil {
return false
}
return s.storage.Exists(ctx, s.idFile(ctx, ""))
} | go | {
"resource": ""
} |
q28689 | List | train | func (r *Store) List(ctx context.Context, maxDepth int) ([]string, error) {
t, err := r.Tree(ctx)
if err != nil {
return []string{}, err
}
return t.List(maxDepth), nil
} | go | {
"resource": ""
} |
q28690 | Tree | train | func (r *Store) Tree(ctx context.Context) (tree.Tree, error) {
root := simple.New("gopass")
addFileFunc := func(in ...string) {
for _, f := range in {
var ct string
switch {
case strings.HasSuffix(f, ".b64"):
ct = "application/octet-stream"
case strings.HasSuffix(f, ".yml"):
ct = "text/yaml"
... | go | {
"resource": ""
} |
q28691 | HIBP | train | func (s *Action) HIBP(ctx context.Context, c *cli.Context) error {
force := c.Bool("force")
api := c.Bool("api")
if api {
return s.hibpAPI(ctx, force)
}
out.Yellow(ctx, "WARNING: Using the HIBPv2 dumps is very expensive. If you can condone leaking a few bits of entropy per secret you should probably use the '-... | go | {
"resource": ""
} |
q28692 | RecipientIDs | train | func (x *XC) RecipientIDs(ctx context.Context, ciphertext []byte) ([]string, error) {
msg := &xcpb.Message{}
if err := proto.Unmarshal(ciphertext, msg); err != nil {
return nil, err
}
ids := make([]string, 0, len(msg.Header.Recipients))
for k := range msg.Header.Recipients {
ids = append(ids, k)
}
sort.Stri... | go | {
"resource": ""
} |
q28693 | ReadNamesFromKey | train | func (x *XC) ReadNamesFromKey(ctx context.Context, buf []byte) ([]string, error) {
pk := &xcpb.PublicKey{}
if err := proto.Unmarshal(buf, pk); err != nil {
return nil, errors.Wrapf(err, "failed to unmarshal public key: %s", err)
}
return []string{pk.Identity.Name}, nil
} | go | {
"resource": ""
} |
q28694 | ListPublicKeyIDs | train | func (x *XC) ListPublicKeyIDs(ctx context.Context) ([]string, error) {
return x.pubring.KeyIDs(), nil
} | go | {
"resource": ""
} |
q28695 | ListPrivateKeyIDs | train | func (x *XC) ListPrivateKeyIDs(ctx context.Context) ([]string, error) {
return x.secring.KeyIDs(), nil
} | go | {
"resource": ""
} |
q28696 | FindPublicKeys | train | func (x *XC) FindPublicKeys(ctx context.Context, search ...string) ([]string, error) {
ids := make([]string, 0, 1)
candidates, _ := x.ListPublicKeyIDs(ctx)
for _, needle := range search {
for _, fp := range candidates {
if strings.HasSuffix(fp, needle) {
ids = append(ids, fp)
}
}
}
sort.Strings(ids)
... | go | {
"resource": ""
} |
q28697 | FormatKey | train | func (x *XC) FormatKey(ctx context.Context, id string) string {
if key := x.pubring.Get(id); key != nil {
return id + " - " + key.Identity.ID()
}
if key := x.secring.Get(id); key != nil {
return id + " - " + key.PublicKey.Identity.ID()
}
return id
} | go | {
"resource": ""
} |
q28698 | NameFromKey | train | func (x *XC) NameFromKey(ctx context.Context, id string) string {
if key := x.pubring.Get(id); key != nil {
return key.Identity.Name
}
if key := x.secring.Get(id); key != nil {
return key.PublicKey.Identity.Name
}
return id
} | go | {
"resource": ""
} |
q28699 | EmailFromKey | train | func (x *XC) EmailFromKey(ctx context.Context, id string) string {
if key := x.pubring.Get(id); key != nil {
return key.Identity.Email
}
if key := x.secring.Get(id); key != nil {
return key.PublicKey.Identity.Email
}
return id
} | go | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.