id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
7,600
gorilla/schema
encoder.go
RegisterEncoder
func (e *Encoder) RegisterEncoder(value interface{}, encoder func(reflect.Value) string) { e.regenc[reflect.TypeOf(value)] = encoder }
go
func (e *Encoder) RegisterEncoder(value interface{}, encoder func(reflect.Value) string) { e.regenc[reflect.TypeOf(value)] = encoder }
[ "func", "(", "e", "*", "Encoder", ")", "RegisterEncoder", "(", "value", "interface", "{", "}", ",", "encoder", "func", "(", "reflect", ".", "Value", ")", "string", ")", "{", "e", ".", "regenc", "[", "reflect", ".", "TypeOf", "(", "value", ")", "]", "=", "encoder", "\n", "}" ]
// RegisterEncoder registers a converter for encoding a custom type.
[ "RegisterEncoder", "registers", "a", "converter", "for", "encoding", "a", "custom", "type", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/encoder.go#L33-L35
7,601
gorilla/schema
encoder.go
isValidStructPointer
func isValidStructPointer(v reflect.Value) bool { return v.Type().Kind() == reflect.Ptr && v.Elem().IsValid() && v.Elem().Type().Kind() == reflect.Struct }
go
func isValidStructPointer(v reflect.Value) bool { return v.Type().Kind() == reflect.Ptr && v.Elem().IsValid() && v.Elem().Type().Kind() == reflect.Struct }
[ "func", "isValidStructPointer", "(", "v", "reflect", ".", "Value", ")", "bool", "{", "return", "v", ".", "Type", "(", ")", ".", "Kind", "(", ")", "==", "reflect", ".", "Ptr", "&&", "v", ".", "Elem", "(", ")", ".", "IsValid", "(", ")", "&&", "v", ".", "Elem", "(", ")", ".", "Type", "(", ")", ".", "Kind", "(", ")", "==", "reflect", ".", "Struct", "\n", "}" ]
// isValidStructPointer test if input value is a valid struct pointer.
[ "isValidStructPointer", "test", "if", "input", "value", "is", "a", "valid", "struct", "pointer", "." ]
d768c7020973d24fadced0db99bfdc261241d85f
https://github.com/gorilla/schema/blob/d768c7020973d24fadced0db99bfdc261241d85f/encoder.go#L44-L46
7,602
go-xorm/builder
cond_or.go
Or
func Or(conds ...Cond) Cond { var result = make(condOr, 0, len(conds)) for _, cond := range conds { if cond == nil || !cond.IsValid() { continue } result = append(result, cond) } return result }
go
func Or(conds ...Cond) Cond { var result = make(condOr, 0, len(conds)) for _, cond := range conds { if cond == nil || !cond.IsValid() { continue } result = append(result, cond) } return result }
[ "func", "Or", "(", "conds", "...", "Cond", ")", "Cond", "{", "var", "result", "=", "make", "(", "condOr", ",", "0", ",", "len", "(", "conds", ")", ")", "\n", "for", "_", ",", "cond", ":=", "range", "conds", "{", "if", "cond", "==", "nil", "||", "!", "cond", ".", "IsValid", "(", ")", "{", "continue", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "cond", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// Or sets OR conditions
[ "Or", "sets", "OR", "conditions" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond_or.go#L14-L23
7,603
go-xorm/builder
cond_or.go
WriteTo
func (o condOr) WriteTo(w Writer) error { for i, cond := range o { var needQuote bool switch cond.(type) { case condAnd, expr: needQuote = true case Eq: needQuote = (len(cond.(Eq)) > 1) case Neq: needQuote = (len(cond.(Neq)) > 1) } if needQuote { fmt.Fprint(w, "(") } err := cond.WriteTo(w) if err != nil { return err } if needQuote { fmt.Fprint(w, ")") } if i != len(o)-1 { fmt.Fprint(w, " OR ") } } return nil }
go
func (o condOr) WriteTo(w Writer) error { for i, cond := range o { var needQuote bool switch cond.(type) { case condAnd, expr: needQuote = true case Eq: needQuote = (len(cond.(Eq)) > 1) case Neq: needQuote = (len(cond.(Neq)) > 1) } if needQuote { fmt.Fprint(w, "(") } err := cond.WriteTo(w) if err != nil { return err } if needQuote { fmt.Fprint(w, ")") } if i != len(o)-1 { fmt.Fprint(w, " OR ") } } return nil }
[ "func", "(", "o", "condOr", ")", "WriteTo", "(", "w", "Writer", ")", "error", "{", "for", "i", ",", "cond", ":=", "range", "o", "{", "var", "needQuote", "bool", "\n", "switch", "cond", ".", "(", "type", ")", "{", "case", "condAnd", ",", "expr", ":", "needQuote", "=", "true", "\n", "case", "Eq", ":", "needQuote", "=", "(", "len", "(", "cond", ".", "(", "Eq", ")", ")", ">", "1", ")", "\n", "case", "Neq", ":", "needQuote", "=", "(", "len", "(", "cond", ".", "(", "Neq", ")", ")", ">", "1", ")", "\n", "}", "\n\n", "if", "needQuote", "{", "fmt", ".", "Fprint", "(", "w", ",", "\"", "\"", ")", "\n", "}", "\n\n", "err", ":=", "cond", ".", "WriteTo", "(", "w", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "if", "needQuote", "{", "fmt", ".", "Fprint", "(", "w", ",", "\"", "\"", ")", "\n", "}", "\n\n", "if", "i", "!=", "len", "(", "o", ")", "-", "1", "{", "fmt", ".", "Fprint", "(", "w", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "return", "nil", "\n", "}" ]
// WriteTo implments Cond
[ "WriteTo", "implments", "Cond" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond_or.go#L26-L57
7,604
go-xorm/builder
string_builder.go
WriteByte
func (b *StringBuilder) WriteByte(c byte) error { b.copyCheck() b.buf = append(b.buf, c) return nil }
go
func (b *StringBuilder) WriteByte(c byte) error { b.copyCheck() b.buf = append(b.buf, c) return nil }
[ "func", "(", "b", "*", "StringBuilder", ")", "WriteByte", "(", "c", "byte", ")", "error", "{", "b", ".", "copyCheck", "(", ")", "\n", "b", ".", "buf", "=", "append", "(", "b", ".", "buf", ",", "c", ")", "\n", "return", "nil", "\n", "}" ]
// WriteByte appends the byte c to b's buffer. // The returned error is always nil.
[ "WriteByte", "appends", "the", "byte", "c", "to", "b", "s", "buffer", ".", "The", "returned", "error", "is", "always", "nil", "." ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/string_builder.go#L90-L94
7,605
go-xorm/builder
string_builder.go
WriteRune
func (b *StringBuilder) WriteRune(r rune) (int, error) { b.copyCheck() if r < utf8.RuneSelf { b.buf = append(b.buf, byte(r)) return 1, nil } l := len(b.buf) if cap(b.buf)-l < utf8.UTFMax { b.grow(utf8.UTFMax) } n := utf8.EncodeRune(b.buf[l:l+utf8.UTFMax], r) b.buf = b.buf[:l+n] return n, nil }
go
func (b *StringBuilder) WriteRune(r rune) (int, error) { b.copyCheck() if r < utf8.RuneSelf { b.buf = append(b.buf, byte(r)) return 1, nil } l := len(b.buf) if cap(b.buf)-l < utf8.UTFMax { b.grow(utf8.UTFMax) } n := utf8.EncodeRune(b.buf[l:l+utf8.UTFMax], r) b.buf = b.buf[:l+n] return n, nil }
[ "func", "(", "b", "*", "StringBuilder", ")", "WriteRune", "(", "r", "rune", ")", "(", "int", ",", "error", ")", "{", "b", ".", "copyCheck", "(", ")", "\n", "if", "r", "<", "utf8", ".", "RuneSelf", "{", "b", ".", "buf", "=", "append", "(", "b", ".", "buf", ",", "byte", "(", "r", ")", ")", "\n", "return", "1", ",", "nil", "\n", "}", "\n", "l", ":=", "len", "(", "b", ".", "buf", ")", "\n", "if", "cap", "(", "b", ".", "buf", ")", "-", "l", "<", "utf8", ".", "UTFMax", "{", "b", ".", "grow", "(", "utf8", ".", "UTFMax", ")", "\n", "}", "\n", "n", ":=", "utf8", ".", "EncodeRune", "(", "b", ".", "buf", "[", "l", ":", "l", "+", "utf8", ".", "UTFMax", "]", ",", "r", ")", "\n", "b", ".", "buf", "=", "b", ".", "buf", "[", ":", "l", "+", "n", "]", "\n", "return", "n", ",", "nil", "\n", "}" ]
// WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. // It returns the length of r and a nil error.
[ "WriteRune", "appends", "the", "UTF", "-", "8", "encoding", "of", "Unicode", "code", "point", "r", "to", "b", "s", "buffer", ".", "It", "returns", "the", "length", "of", "r", "and", "a", "nil", "error", "." ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/string_builder.go#L98-L111
7,606
go-xorm/builder
string_builder.go
WriteString
func (b *StringBuilder) WriteString(s string) (int, error) { b.copyCheck() b.buf = append(b.buf, s...) return len(s), nil }
go
func (b *StringBuilder) WriteString(s string) (int, error) { b.copyCheck() b.buf = append(b.buf, s...) return len(s), nil }
[ "func", "(", "b", "*", "StringBuilder", ")", "WriteString", "(", "s", "string", ")", "(", "int", ",", "error", ")", "{", "b", ".", "copyCheck", "(", ")", "\n", "b", ".", "buf", "=", "append", "(", "b", ".", "buf", ",", "s", "...", ")", "\n", "return", "len", "(", "s", ")", ",", "nil", "\n", "}" ]
// WriteString appends the contents of s to b's buffer. // It returns the length of s and a nil error.
[ "WriteString", "appends", "the", "contents", "of", "s", "to", "b", "s", "buffer", ".", "It", "returns", "the", "length", "of", "s", "and", "a", "nil", "error", "." ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/string_builder.go#L115-L119
7,607
go-xorm/builder
builder_delete.go
Delete
func Delete(conds ...Cond) *Builder { builder := &Builder{cond: NewCond()} return builder.Delete(conds...) }
go
func Delete(conds ...Cond) *Builder { builder := &Builder{cond: NewCond()} return builder.Delete(conds...) }
[ "func", "Delete", "(", "conds", "...", "Cond", ")", "*", "Builder", "{", "builder", ":=", "&", "Builder", "{", "cond", ":", "NewCond", "(", ")", "}", "\n", "return", "builder", ".", "Delete", "(", "conds", "...", ")", "\n", "}" ]
// Delete creates a delete Builder
[ "Delete", "creates", "a", "delete", "Builder" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder_delete.go#L12-L15
7,608
go-xorm/builder
cond_if.go
If
func If(condition bool, condTrue Cond, condFalse ...Cond) Cond { var c = condIf{ condition: condition, condTrue: condTrue, } if len(condFalse) > 0 { c.condFalse = condFalse[0] } return c }
go
func If(condition bool, condTrue Cond, condFalse ...Cond) Cond { var c = condIf{ condition: condition, condTrue: condTrue, } if len(condFalse) > 0 { c.condFalse = condFalse[0] } return c }
[ "func", "If", "(", "condition", "bool", ",", "condTrue", "Cond", ",", "condFalse", "...", "Cond", ")", "Cond", "{", "var", "c", "=", "condIf", "{", "condition", ":", "condition", ",", "condTrue", ":", "condTrue", ",", "}", "\n", "if", "len", "(", "condFalse", ")", ">", "0", "{", "c", ".", "condFalse", "=", "condFalse", "[", "0", "]", "\n", "}", "\n", "return", "c", "\n", "}" ]
// If returns Cond via condition
[ "If", "returns", "Cond", "via", "condition" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond_if.go#L16-L25
7,609
go-xorm/builder
builder.go
Dialect
func Dialect(dialect string) *Builder { builder := &Builder{cond: NewCond(), dialect: dialect} return builder }
go
func Dialect(dialect string) *Builder { builder := &Builder{cond: NewCond(), dialect: dialect} return builder }
[ "func", "Dialect", "(", "dialect", "string", ")", "*", "Builder", "{", "builder", ":=", "&", "Builder", "{", "cond", ":", "NewCond", "(", ")", ",", "dialect", ":", "dialect", "}", "\n", "return", "builder", "\n", "}" ]
// Dialect sets the db dialect of Builder.
[ "Dialect", "sets", "the", "db", "dialect", "of", "Builder", "." ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L70-L73
7,610
go-xorm/builder
builder.go
Where
func (b *Builder) Where(cond Cond) *Builder { if b.cond.IsValid() { b.cond = b.cond.And(cond) } else { b.cond = cond } return b }
go
func (b *Builder) Where(cond Cond) *Builder { if b.cond.IsValid() { b.cond = b.cond.And(cond) } else { b.cond = cond } return b }
[ "func", "(", "b", "*", "Builder", ")", "Where", "(", "cond", "Cond", ")", "*", "Builder", "{", "if", "b", ".", "cond", ".", "IsValid", "(", ")", "{", "b", ".", "cond", "=", "b", ".", "cond", ".", "And", "(", "cond", ")", "\n", "}", "else", "{", "b", ".", "cond", "=", "cond", "\n", "}", "\n", "return", "b", "\n", "}" ]
// Where sets where SQL
[ "Where", "sets", "where", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L101-L108
7,611
go-xorm/builder
builder.go
TableName
func (b *Builder) TableName() string { if b.optype == insertType { return b.into } return b.from }
go
func (b *Builder) TableName() string { if b.optype == insertType { return b.into } return b.from }
[ "func", "(", "b", "*", "Builder", ")", "TableName", "(", ")", "string", "{", "if", "b", ".", "optype", "==", "insertType", "{", "return", "b", ".", "into", "\n", "}", "\n", "return", "b", ".", "from", "\n", "}" ]
// TableName returns the table name
[ "TableName", "returns", "the", "table", "name" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L133-L138
7,612
go-xorm/builder
builder.go
Join
func (b *Builder) Join(joinType, joinTable string, joinCond interface{}) *Builder { switch joinCond.(type) { case Cond: b.joins = append(b.joins, join{joinType, joinTable, joinCond.(Cond)}) case string: b.joins = append(b.joins, join{joinType, joinTable, Expr(joinCond.(string))}) } return b }
go
func (b *Builder) Join(joinType, joinTable string, joinCond interface{}) *Builder { switch joinCond.(type) { case Cond: b.joins = append(b.joins, join{joinType, joinTable, joinCond.(Cond)}) case string: b.joins = append(b.joins, join{joinType, joinTable, Expr(joinCond.(string))}) } return b }
[ "func", "(", "b", "*", "Builder", ")", "Join", "(", "joinType", ",", "joinTable", "string", ",", "joinCond", "interface", "{", "}", ")", "*", "Builder", "{", "switch", "joinCond", ".", "(", "type", ")", "{", "case", "Cond", ":", "b", ".", "joins", "=", "append", "(", "b", ".", "joins", ",", "join", "{", "joinType", ",", "joinTable", ",", "joinCond", ".", "(", "Cond", ")", "}", ")", "\n", "case", "string", ":", "b", ".", "joins", "=", "append", "(", "b", ".", "joins", ",", "join", "{", "joinType", ",", "joinTable", ",", "Expr", "(", "joinCond", ".", "(", "string", ")", ")", "}", ")", "\n", "}", "\n\n", "return", "b", "\n", "}" ]
// Join sets join table and conditions
[ "Join", "sets", "join", "table", "and", "conditions" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L147-L156
7,613
go-xorm/builder
builder.go
Union
func (b *Builder) Union(unionTp string, unionCond *Builder) *Builder { var builder *Builder if b.optype != unionType { builder = &Builder{cond: NewCond()} builder.optype = unionType builder.dialect = b.dialect builder.selects = b.selects currentUnions := b.unions // erase sub unions (actually append to new Builder.unions) b.unions = nil for e := range currentUnions { currentUnions[e].builder.dialect = b.dialect } builder.unions = append(append(builder.unions, union{"", b}), currentUnions...) } else { builder = b } if unionCond != nil { if unionCond.dialect == "" && builder.dialect != "" { unionCond.dialect = builder.dialect } builder.unions = append(builder.unions, union{unionTp, unionCond}) } return builder }
go
func (b *Builder) Union(unionTp string, unionCond *Builder) *Builder { var builder *Builder if b.optype != unionType { builder = &Builder{cond: NewCond()} builder.optype = unionType builder.dialect = b.dialect builder.selects = b.selects currentUnions := b.unions // erase sub unions (actually append to new Builder.unions) b.unions = nil for e := range currentUnions { currentUnions[e].builder.dialect = b.dialect } builder.unions = append(append(builder.unions, union{"", b}), currentUnions...) } else { builder = b } if unionCond != nil { if unionCond.dialect == "" && builder.dialect != "" { unionCond.dialect = builder.dialect } builder.unions = append(builder.unions, union{unionTp, unionCond}) } return builder }
[ "func", "(", "b", "*", "Builder", ")", "Union", "(", "unionTp", "string", ",", "unionCond", "*", "Builder", ")", "*", "Builder", "{", "var", "builder", "*", "Builder", "\n", "if", "b", ".", "optype", "!=", "unionType", "{", "builder", "=", "&", "Builder", "{", "cond", ":", "NewCond", "(", ")", "}", "\n", "builder", ".", "optype", "=", "unionType", "\n", "builder", ".", "dialect", "=", "b", ".", "dialect", "\n", "builder", ".", "selects", "=", "b", ".", "selects", "\n\n", "currentUnions", ":=", "b", ".", "unions", "\n", "// erase sub unions (actually append to new Builder.unions)", "b", ".", "unions", "=", "nil", "\n\n", "for", "e", ":=", "range", "currentUnions", "{", "currentUnions", "[", "e", "]", ".", "builder", ".", "dialect", "=", "b", ".", "dialect", "\n", "}", "\n\n", "builder", ".", "unions", "=", "append", "(", "append", "(", "builder", ".", "unions", ",", "union", "{", "\"", "\"", ",", "b", "}", ")", ",", "currentUnions", "...", ")", "\n", "}", "else", "{", "builder", "=", "b", "\n", "}", "\n\n", "if", "unionCond", "!=", "nil", "{", "if", "unionCond", ".", "dialect", "==", "\"", "\"", "&&", "builder", ".", "dialect", "!=", "\"", "\"", "{", "unionCond", ".", "dialect", "=", "builder", ".", "dialect", "\n", "}", "\n\n", "builder", ".", "unions", "=", "append", "(", "builder", ".", "unions", ",", "union", "{", "unionTp", ",", "unionCond", "}", ")", "\n", "}", "\n\n", "return", "builder", "\n", "}" ]
// Union sets union conditions
[ "Union", "sets", "union", "conditions" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L159-L189
7,614
go-xorm/builder
builder.go
Limit
func (b *Builder) Limit(limitN int, offset ...int) *Builder { b.limitation = &limit{limitN: limitN} if len(offset) > 0 { b.limitation.offset = offset[0] } return b }
go
func (b *Builder) Limit(limitN int, offset ...int) *Builder { b.limitation = &limit{limitN: limitN} if len(offset) > 0 { b.limitation.offset = offset[0] } return b }
[ "func", "(", "b", "*", "Builder", ")", "Limit", "(", "limitN", "int", ",", "offset", "...", "int", ")", "*", "Builder", "{", "b", ".", "limitation", "=", "&", "limit", "{", "limitN", ":", "limitN", "}", "\n\n", "if", "len", "(", "offset", ")", ">", "0", "{", "b", ".", "limitation", ".", "offset", "=", "offset", "[", "0", "]", "\n", "}", "\n\n", "return", "b", "\n", "}" ]
// Limit sets limitN condition
[ "Limit", "sets", "limitN", "condition" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L192-L200
7,615
go-xorm/builder
builder.go
InnerJoin
func (b *Builder) InnerJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("INNER", joinTable, joinCond) }
go
func (b *Builder) InnerJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("INNER", joinTable, joinCond) }
[ "func", "(", "b", "*", "Builder", ")", "InnerJoin", "(", "joinTable", "string", ",", "joinCond", "interface", "{", "}", ")", "*", "Builder", "{", "return", "b", ".", "Join", "(", "\"", "\"", ",", "joinTable", ",", "joinCond", ")", "\n", "}" ]
// InnerJoin sets inner join
[ "InnerJoin", "sets", "inner", "join" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L203-L205
7,616
go-xorm/builder
builder.go
LeftJoin
func (b *Builder) LeftJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("LEFT", joinTable, joinCond) }
go
func (b *Builder) LeftJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("LEFT", joinTable, joinCond) }
[ "func", "(", "b", "*", "Builder", ")", "LeftJoin", "(", "joinTable", "string", ",", "joinCond", "interface", "{", "}", ")", "*", "Builder", "{", "return", "b", ".", "Join", "(", "\"", "\"", ",", "joinTable", ",", "joinCond", ")", "\n", "}" ]
// LeftJoin sets left join SQL
[ "LeftJoin", "sets", "left", "join", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L208-L210
7,617
go-xorm/builder
builder.go
RightJoin
func (b *Builder) RightJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("RIGHT", joinTable, joinCond) }
go
func (b *Builder) RightJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("RIGHT", joinTable, joinCond) }
[ "func", "(", "b", "*", "Builder", ")", "RightJoin", "(", "joinTable", "string", ",", "joinCond", "interface", "{", "}", ")", "*", "Builder", "{", "return", "b", ".", "Join", "(", "\"", "\"", ",", "joinTable", ",", "joinCond", ")", "\n", "}" ]
// RightJoin sets right join SQL
[ "RightJoin", "sets", "right", "join", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L213-L215
7,618
go-xorm/builder
builder.go
CrossJoin
func (b *Builder) CrossJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("CROSS", joinTable, joinCond) }
go
func (b *Builder) CrossJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("CROSS", joinTable, joinCond) }
[ "func", "(", "b", "*", "Builder", ")", "CrossJoin", "(", "joinTable", "string", ",", "joinCond", "interface", "{", "}", ")", "*", "Builder", "{", "return", "b", ".", "Join", "(", "\"", "\"", ",", "joinTable", ",", "joinCond", ")", "\n", "}" ]
// CrossJoin sets cross join SQL
[ "CrossJoin", "sets", "cross", "join", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L218-L220
7,619
go-xorm/builder
builder.go
FullJoin
func (b *Builder) FullJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("FULL", joinTable, joinCond) }
go
func (b *Builder) FullJoin(joinTable string, joinCond interface{}) *Builder { return b.Join("FULL", joinTable, joinCond) }
[ "func", "(", "b", "*", "Builder", ")", "FullJoin", "(", "joinTable", "string", ",", "joinCond", "interface", "{", "}", ")", "*", "Builder", "{", "return", "b", ".", "Join", "(", "\"", "\"", ",", "joinTable", ",", "joinCond", ")", "\n", "}" ]
// FullJoin sets full join SQL
[ "FullJoin", "sets", "full", "join", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L223-L225
7,620
go-xorm/builder
builder.go
And
func (b *Builder) And(cond Cond) *Builder { b.cond = And(b.cond, cond) return b }
go
func (b *Builder) And(cond Cond) *Builder { b.cond = And(b.cond, cond) return b }
[ "func", "(", "b", "*", "Builder", ")", "And", "(", "cond", "Cond", ")", "*", "Builder", "{", "b", ".", "cond", "=", "And", "(", "b", ".", "cond", ",", "cond", ")", "\n", "return", "b", "\n", "}" ]
// And sets AND condition
[ "And", "sets", "AND", "condition" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L237-L240
7,621
go-xorm/builder
builder.go
Or
func (b *Builder) Or(cond Cond) *Builder { b.cond = Or(b.cond, cond) return b }
go
func (b *Builder) Or(cond Cond) *Builder { b.cond = Or(b.cond, cond) return b }
[ "func", "(", "b", "*", "Builder", ")", "Or", "(", "cond", "Cond", ")", "*", "Builder", "{", "b", ".", "cond", "=", "Or", "(", "b", ".", "cond", ",", "cond", ")", "\n", "return", "b", "\n", "}" ]
// Or sets OR condition
[ "Or", "sets", "OR", "condition" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L243-L246
7,622
go-xorm/builder
builder.go
Delete
func (b *Builder) Delete(conds ...Cond) *Builder { b.cond = b.cond.And(conds...) b.optype = deleteType return b }
go
func (b *Builder) Delete(conds ...Cond) *Builder { b.cond = b.cond.And(conds...) b.optype = deleteType return b }
[ "func", "(", "b", "*", "Builder", ")", "Delete", "(", "conds", "...", "Cond", ")", "*", "Builder", "{", "b", ".", "cond", "=", "b", ".", "cond", ".", "And", "(", "conds", "...", ")", "\n", "b", ".", "optype", "=", "deleteType", "\n", "return", "b", "\n", "}" ]
// Delete sets delete SQL
[ "Delete", "sets", "delete", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder.go#L317-L321
7,623
go-xorm/builder
cond_and.go
And
func And(conds ...Cond) Cond { var result = make(condAnd, 0, len(conds)) for _, cond := range conds { if cond == nil || !cond.IsValid() { continue } result = append(result, cond) } return result }
go
func And(conds ...Cond) Cond { var result = make(condAnd, 0, len(conds)) for _, cond := range conds { if cond == nil || !cond.IsValid() { continue } result = append(result, cond) } return result }
[ "func", "And", "(", "conds", "...", "Cond", ")", "Cond", "{", "var", "result", "=", "make", "(", "condAnd", ",", "0", ",", "len", "(", "conds", ")", ")", "\n", "for", "_", ",", "cond", ":=", "range", "conds", "{", "if", "cond", "==", "nil", "||", "!", "cond", ".", "IsValid", "(", ")", "{", "continue", "\n", "}", "\n", "result", "=", "append", "(", "result", ",", "cond", ")", "\n", "}", "\n", "return", "result", "\n", "}" ]
// And generates AND conditions
[ "And", "generates", "AND", "conditions" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond_and.go#L14-L23
7,624
go-xorm/builder
builder_update.go
Update
func Update(updates ...Eq) *Builder { builder := &Builder{cond: NewCond()} return builder.Update(updates...) }
go
func Update(updates ...Eq) *Builder { builder := &Builder{cond: NewCond()} return builder.Update(updates...) }
[ "func", "Update", "(", "updates", "...", "Eq", ")", "*", "Builder", "{", "builder", ":=", "&", "Builder", "{", "cond", ":", "NewCond", "(", ")", "}", "\n", "return", "builder", ".", "Update", "(", "updates", "...", ")", "\n", "}" ]
// Update creates an update Builder
[ "Update", "creates", "an", "update", "Builder" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder_update.go#L12-L15
7,625
go-xorm/builder
cond_between.go
And
func (between Between) And(conds ...Cond) Cond { return And(between, And(conds...)) }
go
func (between Between) And(conds ...Cond) Cond { return And(between, And(conds...)) }
[ "func", "(", "between", "Between", ")", "And", "(", "conds", "...", "Cond", ")", "Cond", "{", "return", "And", "(", "between", ",", "And", "(", "conds", "...", ")", ")", "\n", "}" ]
// And implments And with other conditions
[ "And", "implments", "And", "with", "other", "conditions" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond_between.go#L53-L55
7,626
go-xorm/builder
cond_between.go
Or
func (between Between) Or(conds ...Cond) Cond { return Or(between, Or(conds...)) }
go
func (between Between) Or(conds ...Cond) Cond { return Or(between, Or(conds...)) }
[ "func", "(", "between", "Between", ")", "Or", "(", "conds", "...", "Cond", ")", "Cond", "{", "return", "Or", "(", "between", ",", "Or", "(", "conds", "...", ")", ")", "\n", "}" ]
// Or implments Or with other conditions
[ "Or", "implments", "Or", "with", "other", "conditions" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond_between.go#L58-L60
7,627
go-xorm/builder
builder_select.go
Select
func Select(cols ...string) *Builder { builder := &Builder{cond: NewCond()} return builder.Select(cols...) }
go
func Select(cols ...string) *Builder { builder := &Builder{cond: NewCond()} return builder.Select(cols...) }
[ "func", "Select", "(", "cols", "...", "string", ")", "*", "Builder", "{", "builder", ":=", "&", "Builder", "{", "cond", ":", "NewCond", "(", ")", "}", "\n", "return", "builder", ".", "Select", "(", "cols", "...", ")", "\n", "}" ]
// Select creates a select Builder
[ "Select", "creates", "a", "select", "Builder" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder_select.go#L12-L15
7,628
go-xorm/builder
builder_select.go
OrderBy
func (b *Builder) OrderBy(orderBy string) *Builder { b.orderBy = orderBy return b }
go
func (b *Builder) OrderBy(orderBy string) *Builder { b.orderBy = orderBy return b }
[ "func", "(", "b", "*", "Builder", ")", "OrderBy", "(", "orderBy", "string", ")", "*", "Builder", "{", "b", ".", "orderBy", "=", "orderBy", "\n", "return", "b", "\n", "}" ]
// OrderBy orderBy SQL
[ "OrderBy", "orderBy", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder_select.go#L130-L133
7,629
go-xorm/builder
builder_select.go
GroupBy
func (b *Builder) GroupBy(groupby string) *Builder { b.groupBy = groupby return b }
go
func (b *Builder) GroupBy(groupby string) *Builder { b.groupBy = groupby return b }
[ "func", "(", "b", "*", "Builder", ")", "GroupBy", "(", "groupby", "string", ")", "*", "Builder", "{", "b", ".", "groupBy", "=", "groupby", "\n", "return", "b", "\n", "}" ]
// GroupBy groupby SQL
[ "GroupBy", "groupby", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder_select.go#L136-L139
7,630
go-xorm/builder
builder_select.go
Having
func (b *Builder) Having(having string) *Builder { b.having = having return b }
go
func (b *Builder) Having(having string) *Builder { b.having = having return b }
[ "func", "(", "b", "*", "Builder", ")", "Having", "(", "having", "string", ")", "*", "Builder", "{", "b", ".", "having", "=", "having", "\n", "return", "b", "\n", "}" ]
// Having having SQL
[ "Having", "having", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder_select.go#L142-L145
7,631
go-xorm/builder
builder_insert.go
Insert
func Insert(eq ...interface{}) *Builder { builder := &Builder{cond: NewCond()} return builder.Insert(eq...) }
go
func Insert(eq ...interface{}) *Builder { builder := &Builder{cond: NewCond()} return builder.Insert(eq...) }
[ "func", "Insert", "(", "eq", "...", "interface", "{", "}", ")", "*", "Builder", "{", "builder", ":=", "&", "Builder", "{", "cond", ":", "NewCond", "(", ")", "}", "\n", "return", "builder", ".", "Insert", "(", "eq", "...", ")", "\n", "}" ]
// Insert creates an insert Builder
[ "Insert", "creates", "an", "insert", "Builder" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/builder_insert.go#L13-L16
7,632
go-xorm/builder
cond.go
Write
func (s *BytesWriter) Write(buf []byte) (int, error) { return s.writer.Write(buf) }
go
func (s *BytesWriter) Write(buf []byte) (int, error) { return s.writer.Write(buf) }
[ "func", "(", "s", "*", "BytesWriter", ")", "Write", "(", "buf", "[", "]", "byte", ")", "(", "int", ",", "error", ")", "{", "return", "s", ".", "writer", ".", "Write", "(", "buf", ")", "\n", "}" ]
// Write writes data to Writer
[ "Write", "writes", "data", "to", "Writer" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond.go#L34-L36
7,633
go-xorm/builder
cond.go
Append
func (s *BytesWriter) Append(args ...interface{}) { s.args = append(s.args, args...) }
go
func (s *BytesWriter) Append(args ...interface{}) { s.args = append(s.args, args...) }
[ "func", "(", "s", "*", "BytesWriter", ")", "Append", "(", "args", "...", "interface", "{", "}", ")", "{", "s", ".", "args", "=", "append", "(", "s", ".", "args", ",", "args", "...", ")", "\n", "}" ]
// Append appends args to Writer
[ "Append", "appends", "args", "to", "Writer" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/cond.go#L39-L41
7,634
go-xorm/builder
sql.go
ToSQL
func ToSQL(cond interface{}) (string, []interface{}, error) { switch cond.(type) { case Cond: return condToSQL(cond.(Cond)) case *Builder: return cond.(*Builder).ToSQL() } return "", nil, ErrNotSupportType }
go
func ToSQL(cond interface{}) (string, []interface{}, error) { switch cond.(type) { case Cond: return condToSQL(cond.(Cond)) case *Builder: return cond.(*Builder).ToSQL() } return "", nil, ErrNotSupportType }
[ "func", "ToSQL", "(", "cond", "interface", "{", "}", ")", "(", "string", ",", "[", "]", "interface", "{", "}", ",", "error", ")", "{", "switch", "cond", ".", "(", "type", ")", "{", "case", "Cond", ":", "return", "condToSQL", "(", "cond", ".", "(", "Cond", ")", ")", "\n", "case", "*", "Builder", ":", "return", "cond", ".", "(", "*", "Builder", ")", ".", "ToSQL", "(", ")", "\n", "}", "\n", "return", "\"", "\"", ",", "nil", ",", "ErrNotSupportType", "\n", "}" ]
// ToSQL convert a builder or conditions to SQL and args
[ "ToSQL", "convert", "a", "builder", "or", "conditions", "to", "SQL", "and", "args" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/sql.go#L39-L47
7,635
go-xorm/builder
sql.go
ToBoundSQL
func ToBoundSQL(cond interface{}) (string, error) { switch cond.(type) { case Cond: return condToBoundSQL(cond.(Cond)) case *Builder: return cond.(*Builder).ToBoundSQL() } return "", ErrNotSupportType }
go
func ToBoundSQL(cond interface{}) (string, error) { switch cond.(type) { case Cond: return condToBoundSQL(cond.(Cond)) case *Builder: return cond.(*Builder).ToBoundSQL() } return "", ErrNotSupportType }
[ "func", "ToBoundSQL", "(", "cond", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "switch", "cond", ".", "(", "type", ")", "{", "case", "Cond", ":", "return", "condToBoundSQL", "(", "cond", ".", "(", "Cond", ")", ")", "\n", "case", "*", "Builder", ":", "return", "cond", ".", "(", "*", "Builder", ")", ".", "ToBoundSQL", "(", ")", "\n", "}", "\n", "return", "\"", "\"", ",", "ErrNotSupportType", "\n", "}" ]
// ToBoundSQL convert a builder or conditions to parameters bound SQL
[ "ToBoundSQL", "convert", "a", "builder", "or", "conditions", "to", "parameters", "bound", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/sql.go#L50-L58
7,636
go-xorm/builder
sql.go
ConvertToBoundSQL
func ConvertToBoundSQL(sql string, args []interface{}) (string, error) { buf := StringBuilder{} var i, j, start int for ; i < len(sql); i++ { if sql[i] == '?' { _, err := buf.WriteString(sql[start:i]) if err != nil { return "", err } start = i + 1 if len(args) == j { return "", ErrNeedMoreArguments } arg := args[j] if namedArg, ok := arg.(sql2.NamedArg); ok { arg = namedArg.Value } if noSQLQuoteNeeded(arg) { _, err = fmt.Fprint(&buf, arg) } else { _, err = fmt.Fprintf(&buf, "'%v'", arg) } if err != nil { return "", err } j = j + 1 } } _, err := buf.WriteString(sql[start:]) if err != nil { return "", err } return buf.String(), nil }
go
func ConvertToBoundSQL(sql string, args []interface{}) (string, error) { buf := StringBuilder{} var i, j, start int for ; i < len(sql); i++ { if sql[i] == '?' { _, err := buf.WriteString(sql[start:i]) if err != nil { return "", err } start = i + 1 if len(args) == j { return "", ErrNeedMoreArguments } arg := args[j] if namedArg, ok := arg.(sql2.NamedArg); ok { arg = namedArg.Value } if noSQLQuoteNeeded(arg) { _, err = fmt.Fprint(&buf, arg) } else { _, err = fmt.Fprintf(&buf, "'%v'", arg) } if err != nil { return "", err } j = j + 1 } } _, err := buf.WriteString(sql[start:]) if err != nil { return "", err } return buf.String(), nil }
[ "func", "ConvertToBoundSQL", "(", "sql", "string", ",", "args", "[", "]", "interface", "{", "}", ")", "(", "string", ",", "error", ")", "{", "buf", ":=", "StringBuilder", "{", "}", "\n", "var", "i", ",", "j", ",", "start", "int", "\n", "for", ";", "i", "<", "len", "(", "sql", ")", ";", "i", "++", "{", "if", "sql", "[", "i", "]", "==", "'?'", "{", "_", ",", "err", ":=", "buf", ".", "WriteString", "(", "sql", "[", "start", ":", "i", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "start", "=", "i", "+", "1", "\n\n", "if", "len", "(", "args", ")", "==", "j", "{", "return", "\"", "\"", ",", "ErrNeedMoreArguments", "\n", "}", "\n\n", "arg", ":=", "args", "[", "j", "]", "\n", "if", "namedArg", ",", "ok", ":=", "arg", ".", "(", "sql2", ".", "NamedArg", ")", ";", "ok", "{", "arg", "=", "namedArg", ".", "Value", "\n", "}", "\n\n", "if", "noSQLQuoteNeeded", "(", "arg", ")", "{", "_", ",", "err", "=", "fmt", ".", "Fprint", "(", "&", "buf", ",", "arg", ")", "\n", "}", "else", "{", "_", ",", "err", "=", "fmt", ".", "Fprintf", "(", "&", "buf", ",", "\"", "\"", ",", "arg", ")", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "j", "=", "j", "+", "1", "\n", "}", "\n", "}", "\n", "_", ",", "err", ":=", "buf", ".", "WriteString", "(", "sql", "[", "start", ":", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "buf", ".", "String", "(", ")", ",", "nil", "\n", "}" ]
// ConvertToBoundSQL will convert SQL and args to a bound SQL
[ "ConvertToBoundSQL", "will", "convert", "SQL", "and", "args", "to", "a", "bound", "SQL" ]
0c156dfdb0619fec336cc5b87b15b06f858ce6c7
https://github.com/go-xorm/builder/blob/0c156dfdb0619fec336cc5b87b15b06f858ce6c7/sql.go#L94-L130
7,637
akavel/rsrc
coff/coff.go
Freeze
func (coff *Coff) Freeze() { switch coff.SectionHeader32.Name { case STRING_RSRC: coff.freezeRSRC() case STRING_RDATA: coff.freezeRDATA() } }
go
func (coff *Coff) Freeze() { switch coff.SectionHeader32.Name { case STRING_RSRC: coff.freezeRSRC() case STRING_RDATA: coff.freezeRDATA() } }
[ "func", "(", "coff", "*", "Coff", ")", "Freeze", "(", ")", "{", "switch", "coff", ".", "SectionHeader32", ".", "Name", "{", "case", "STRING_RSRC", ":", "coff", ".", "freezeRSRC", "(", ")", "\n", "case", "STRING_RDATA", ":", "coff", ".", "freezeRDATA", "(", ")", "\n", "}", "\n", "}" ]
// Freeze fills in some important offsets in resulting file.
[ "Freeze", "fills", "in", "some", "important", "offsets", "in", "resulting", "file", "." ]
b9f6b78f792dc3dddaf295854d968f5b6fdcdba1
https://github.com/akavel/rsrc/blob/b9f6b78f792dc3dddaf295854d968f5b6fdcdba1/coff/coff.go#L296-L303
7,638
montanaflynn/stats
max.go
Max
func Max(input Float64Data) (max float64, err error) { // Return an error if there are no numbers if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Get the first value as the starting point max = input.Get(0) // Loop and replace higher values for i := 1; i < input.Len(); i++ { if input.Get(i) > max { max = input.Get(i) } } return max, nil }
go
func Max(input Float64Data) (max float64, err error) { // Return an error if there are no numbers if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Get the first value as the starting point max = input.Get(0) // Loop and replace higher values for i := 1; i < input.Len(); i++ { if input.Get(i) > max { max = input.Get(i) } } return max, nil }
[ "func", "Max", "(", "input", "Float64Data", ")", "(", "max", "float64", ",", "err", "error", ")", "{", "// Return an error if there are no numbers", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Get the first value as the starting point", "max", "=", "input", ".", "Get", "(", "0", ")", "\n\n", "// Loop and replace higher values", "for", "i", ":=", "1", ";", "i", "<", "input", ".", "Len", "(", ")", ";", "i", "++", "{", "if", "input", ".", "Get", "(", "i", ")", ">", "max", "{", "max", "=", "input", ".", "Get", "(", "i", ")", "\n", "}", "\n", "}", "\n\n", "return", "max", ",", "nil", "\n", "}" ]
// Max finds the highest number in a slice
[ "Max", "finds", "the", "highest", "number", "in", "a", "slice" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/max.go#L8-L26
7,639
montanaflynn/stats
percentile.go
PercentileNearestRank
func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) { // Find the length of items in the slice il := input.Len() // Return an error for empty slices if il == 0 { return math.NaN(), EmptyInputErr } // Return error for less than 0 or greater than 100 percentages if percent < 0 || percent > 100 { return math.NaN(), BoundsErr } // Start by sorting a copy of the slice c := sortedCopy(input) // Return the last item if percent == 100.0 { return c[il-1], nil } // Find ordinal ranking or := int(math.Ceil(float64(il) * percent / 100)) // Return the item that is in the place of the ordinal rank if or == 0 { return c[0], nil } return c[or-1], nil }
go
func PercentileNearestRank(input Float64Data, percent float64) (percentile float64, err error) { // Find the length of items in the slice il := input.Len() // Return an error for empty slices if il == 0 { return math.NaN(), EmptyInputErr } // Return error for less than 0 or greater than 100 percentages if percent < 0 || percent > 100 { return math.NaN(), BoundsErr } // Start by sorting a copy of the slice c := sortedCopy(input) // Return the last item if percent == 100.0 { return c[il-1], nil } // Find ordinal ranking or := int(math.Ceil(float64(il) * percent / 100)) // Return the item that is in the place of the ordinal rank if or == 0 { return c[0], nil } return c[or-1], nil }
[ "func", "PercentileNearestRank", "(", "input", "Float64Data", ",", "percent", "float64", ")", "(", "percentile", "float64", ",", "err", "error", ")", "{", "// Find the length of items in the slice", "il", ":=", "input", ".", "Len", "(", ")", "\n\n", "// Return an error for empty slices", "if", "il", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Return error for less than 0 or greater than 100 percentages", "if", "percent", "<", "0", "||", "percent", ">", "100", "{", "return", "math", ".", "NaN", "(", ")", ",", "BoundsErr", "\n", "}", "\n\n", "// Start by sorting a copy of the slice", "c", ":=", "sortedCopy", "(", "input", ")", "\n\n", "// Return the last item", "if", "percent", "==", "100.0", "{", "return", "c", "[", "il", "-", "1", "]", ",", "nil", "\n", "}", "\n\n", "// Find ordinal ranking", "or", ":=", "int", "(", "math", ".", "Ceil", "(", "float64", "(", "il", ")", "*", "percent", "/", "100", ")", ")", "\n\n", "// Return the item that is in the place of the ordinal rank", "if", "or", "==", "0", "{", "return", "c", "[", "0", "]", ",", "nil", "\n", "}", "\n", "return", "c", "[", "or", "-", "1", "]", ",", "nil", "\n\n", "}" ]
// PercentileNearestRank finds the relative standing in a slice of floats using the Nearest Rank method
[ "PercentileNearestRank", "finds", "the", "relative", "standing", "in", "a", "slice", "of", "floats", "using", "the", "Nearest", "Rank", "method" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/percentile.go#L50-L82
7,640
montanaflynn/stats
outlier.go
QuartileOutliers
func QuartileOutliers(input Float64Data) (Outliers, error) { if input.Len() == 0 { return Outliers{}, EmptyInputErr } // Start by sorting a copy of the slice copy := sortedCopy(input) // Calculate the quartiles and interquartile range qs, _ := Quartile(copy) iqr, _ := InterQuartileRange(copy) // Calculate the lower and upper inner and outer fences lif := qs.Q1 - (1.5 * iqr) uif := qs.Q3 + (1.5 * iqr) lof := qs.Q1 - (3 * iqr) uof := qs.Q3 + (3 * iqr) // Find the data points that are outside of the // inner and upper fences and add them to mild // and extreme outlier slices var mild Float64Data var extreme Float64Data for _, v := range copy { if v < lof || v > uof { extreme = append(extreme, v) } else if v < lif || v > uif { mild = append(mild, v) } } // Wrap them into our struct return Outliers{mild, extreme}, nil }
go
func QuartileOutliers(input Float64Data) (Outliers, error) { if input.Len() == 0 { return Outliers{}, EmptyInputErr } // Start by sorting a copy of the slice copy := sortedCopy(input) // Calculate the quartiles and interquartile range qs, _ := Quartile(copy) iqr, _ := InterQuartileRange(copy) // Calculate the lower and upper inner and outer fences lif := qs.Q1 - (1.5 * iqr) uif := qs.Q3 + (1.5 * iqr) lof := qs.Q1 - (3 * iqr) uof := qs.Q3 + (3 * iqr) // Find the data points that are outside of the // inner and upper fences and add them to mild // and extreme outlier slices var mild Float64Data var extreme Float64Data for _, v := range copy { if v < lof || v > uof { extreme = append(extreme, v) } else if v < lif || v > uif { mild = append(mild, v) } } // Wrap them into our struct return Outliers{mild, extreme}, nil }
[ "func", "QuartileOutliers", "(", "input", "Float64Data", ")", "(", "Outliers", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "Outliers", "{", "}", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Start by sorting a copy of the slice", "copy", ":=", "sortedCopy", "(", "input", ")", "\n\n", "// Calculate the quartiles and interquartile range", "qs", ",", "_", ":=", "Quartile", "(", "copy", ")", "\n", "iqr", ",", "_", ":=", "InterQuartileRange", "(", "copy", ")", "\n\n", "// Calculate the lower and upper inner and outer fences", "lif", ":=", "qs", ".", "Q1", "-", "(", "1.5", "*", "iqr", ")", "\n", "uif", ":=", "qs", ".", "Q3", "+", "(", "1.5", "*", "iqr", ")", "\n", "lof", ":=", "qs", ".", "Q1", "-", "(", "3", "*", "iqr", ")", "\n", "uof", ":=", "qs", ".", "Q3", "+", "(", "3", "*", "iqr", ")", "\n\n", "// Find the data points that are outside of the", "// inner and upper fences and add them to mild", "// and extreme outlier slices", "var", "mild", "Float64Data", "\n", "var", "extreme", "Float64Data", "\n", "for", "_", ",", "v", ":=", "range", "copy", "{", "if", "v", "<", "lof", "||", "v", ">", "uof", "{", "extreme", "=", "append", "(", "extreme", ",", "v", ")", "\n", "}", "else", "if", "v", "<", "lif", "||", "v", ">", "uif", "{", "mild", "=", "append", "(", "mild", ",", "v", ")", "\n", "}", "\n", "}", "\n\n", "// Wrap them into our struct", "return", "Outliers", "{", "mild", ",", "extreme", "}", ",", "nil", "\n", "}" ]
// QuartileOutliers finds the mild and extreme outliers
[ "QuartileOutliers", "finds", "the", "mild", "and", "extreme", "outliers" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/outlier.go#L10-L44
7,641
montanaflynn/stats
quartile.go
Quartile
func Quartile(input Float64Data) (Quartiles, error) { il := input.Len() if il == 0 { return Quartiles{}, EmptyInputErr } // Start by sorting a copy of the slice copy := sortedCopy(input) // Find the cutoff places depeding on if // the input slice length is even or odd var c1 int var c2 int if il%2 == 0 { c1 = il / 2 c2 = il / 2 } else { c1 = (il - 1) / 2 c2 = c1 + 1 } // Find the Medians with the cutoff points Q1, _ := Median(copy[:c1]) Q2, _ := Median(copy) Q3, _ := Median(copy[c2:]) return Quartiles{Q1, Q2, Q3}, nil }
go
func Quartile(input Float64Data) (Quartiles, error) { il := input.Len() if il == 0 { return Quartiles{}, EmptyInputErr } // Start by sorting a copy of the slice copy := sortedCopy(input) // Find the cutoff places depeding on if // the input slice length is even or odd var c1 int var c2 int if il%2 == 0 { c1 = il / 2 c2 = il / 2 } else { c1 = (il - 1) / 2 c2 = c1 + 1 } // Find the Medians with the cutoff points Q1, _ := Median(copy[:c1]) Q2, _ := Median(copy) Q3, _ := Median(copy[c2:]) return Quartiles{Q1, Q2, Q3}, nil }
[ "func", "Quartile", "(", "input", "Float64Data", ")", "(", "Quartiles", ",", "error", ")", "{", "il", ":=", "input", ".", "Len", "(", ")", "\n", "if", "il", "==", "0", "{", "return", "Quartiles", "{", "}", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Start by sorting a copy of the slice", "copy", ":=", "sortedCopy", "(", "input", ")", "\n\n", "// Find the cutoff places depeding on if", "// the input slice length is even or odd", "var", "c1", "int", "\n", "var", "c2", "int", "\n", "if", "il", "%", "2", "==", "0", "{", "c1", "=", "il", "/", "2", "\n", "c2", "=", "il", "/", "2", "\n", "}", "else", "{", "c1", "=", "(", "il", "-", "1", ")", "/", "2", "\n", "c2", "=", "c1", "+", "1", "\n", "}", "\n\n", "// Find the Medians with the cutoff points", "Q1", ",", "_", ":=", "Median", "(", "copy", "[", ":", "c1", "]", ")", "\n", "Q2", ",", "_", ":=", "Median", "(", "copy", ")", "\n", "Q3", ",", "_", ":=", "Median", "(", "copy", "[", "c2", ":", "]", ")", "\n\n", "return", "Quartiles", "{", "Q1", ",", "Q2", ",", "Q3", "}", ",", "nil", "\n\n", "}" ]
// Quartile returns the three quartile points from a slice of data
[ "Quartile", "returns", "the", "three", "quartile", "points", "from", "a", "slice", "of", "data" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/quartile.go#L13-L42
7,642
montanaflynn/stats
quartile.go
InterQuartileRange
func InterQuartileRange(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } qs, _ := Quartile(input) iqr := qs.Q3 - qs.Q1 return iqr, nil }
go
func InterQuartileRange(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } qs, _ := Quartile(input) iqr := qs.Q3 - qs.Q1 return iqr, nil }
[ "func", "InterQuartileRange", "(", "input", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n", "qs", ",", "_", ":=", "Quartile", "(", "input", ")", "\n", "iqr", ":=", "qs", ".", "Q3", "-", "qs", ".", "Q1", "\n", "return", "iqr", ",", "nil", "\n", "}" ]
// InterQuartileRange finds the range between Q1 and Q3
[ "InterQuartileRange", "finds", "the", "range", "between", "Q1", "and", "Q3" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/quartile.go#L45-L52
7,643
montanaflynn/stats
quartile.go
Midhinge
func Midhinge(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } qs, _ := Quartile(input) mh := (qs.Q1 + qs.Q3) / 2 return mh, nil }
go
func Midhinge(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } qs, _ := Quartile(input) mh := (qs.Q1 + qs.Q3) / 2 return mh, nil }
[ "func", "Midhinge", "(", "input", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n", "qs", ",", "_", ":=", "Quartile", "(", "input", ")", "\n", "mh", ":=", "(", "qs", ".", "Q1", "+", "qs", ".", "Q3", ")", "/", "2", "\n", "return", "mh", ",", "nil", "\n", "}" ]
// Midhinge finds the average of the first and third quartiles
[ "Midhinge", "finds", "the", "average", "of", "the", "first", "and", "third", "quartiles" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/quartile.go#L55-L62
7,644
montanaflynn/stats
quartile.go
Trimean
func Trimean(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } c := sortedCopy(input) q, _ := Quartile(c) return (q.Q1 + (q.Q2 * 2) + q.Q3) / 4, nil }
go
func Trimean(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } c := sortedCopy(input) q, _ := Quartile(c) return (q.Q1 + (q.Q2 * 2) + q.Q3) / 4, nil }
[ "func", "Trimean", "(", "input", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "c", ":=", "sortedCopy", "(", "input", ")", "\n", "q", ",", "_", ":=", "Quartile", "(", "c", ")", "\n\n", "return", "(", "q", ".", "Q1", "+", "(", "q", ".", "Q2", "*", "2", ")", "+", "q", ".", "Q3", ")", "/", "4", ",", "nil", "\n", "}" ]
// Trimean finds the average of the median and the midhinge
[ "Trimean", "finds", "the", "average", "of", "the", "median", "and", "the", "midhinge" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/quartile.go#L65-L74
7,645
montanaflynn/stats
min.go
Min
func Min(input Float64Data) (min float64, err error) { // Get the count of numbers in the slice l := input.Len() // Return an error if there are no numbers if l == 0 { return math.NaN(), EmptyInputErr } // Get the first value as the starting point min = input.Get(0) // Iterate until done checking for a lower value for i := 1; i < l; i++ { if input.Get(i) < min { min = input.Get(i) } } return min, nil }
go
func Min(input Float64Data) (min float64, err error) { // Get the count of numbers in the slice l := input.Len() // Return an error if there are no numbers if l == 0 { return math.NaN(), EmptyInputErr } // Get the first value as the starting point min = input.Get(0) // Iterate until done checking for a lower value for i := 1; i < l; i++ { if input.Get(i) < min { min = input.Get(i) } } return min, nil }
[ "func", "Min", "(", "input", "Float64Data", ")", "(", "min", "float64", ",", "err", "error", ")", "{", "// Get the count of numbers in the slice", "l", ":=", "input", ".", "Len", "(", ")", "\n\n", "// Return an error if there are no numbers", "if", "l", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Get the first value as the starting point", "min", "=", "input", ".", "Get", "(", "0", ")", "\n\n", "// Iterate until done checking for a lower value", "for", "i", ":=", "1", ";", "i", "<", "l", ";", "i", "++", "{", "if", "input", ".", "Get", "(", "i", ")", "<", "min", "{", "min", "=", "input", ".", "Get", "(", "i", ")", "\n", "}", "\n", "}", "\n", "return", "min", ",", "nil", "\n", "}" ]
// Min finds the lowest number in a set of data
[ "Min", "finds", "the", "lowest", "number", "in", "a", "set", "of", "data" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/min.go#L6-L26
7,646
montanaflynn/stats
round.go
Round
func Round(input float64, places int) (rounded float64, err error) { // If the float is not a number if math.IsNaN(input) { return math.NaN(), NaNErr } // Find out the actual sign and correct the input for later sign := 1.0 if input < 0 { sign = -1 input *= -1 } // Use the places arg to get the amount of precision wanted precision := math.Pow(10, float64(places)) // Find the decimal place we are looking to round digit := input * precision // Get the actual decimal number as a fraction to be compared _, decimal := math.Modf(digit) // If the decimal is less than .5 we round down otherwise up if decimal >= 0.5 { rounded = math.Ceil(digit) } else { rounded = math.Floor(digit) } // Finally we do the math to actually create a rounded number return rounded / precision * sign, nil }
go
func Round(input float64, places int) (rounded float64, err error) { // If the float is not a number if math.IsNaN(input) { return math.NaN(), NaNErr } // Find out the actual sign and correct the input for later sign := 1.0 if input < 0 { sign = -1 input *= -1 } // Use the places arg to get the amount of precision wanted precision := math.Pow(10, float64(places)) // Find the decimal place we are looking to round digit := input * precision // Get the actual decimal number as a fraction to be compared _, decimal := math.Modf(digit) // If the decimal is less than .5 we round down otherwise up if decimal >= 0.5 { rounded = math.Ceil(digit) } else { rounded = math.Floor(digit) } // Finally we do the math to actually create a rounded number return rounded / precision * sign, nil }
[ "func", "Round", "(", "input", "float64", ",", "places", "int", ")", "(", "rounded", "float64", ",", "err", "error", ")", "{", "// If the float is not a number", "if", "math", ".", "IsNaN", "(", "input", ")", "{", "return", "math", ".", "NaN", "(", ")", ",", "NaNErr", "\n", "}", "\n\n", "// Find out the actual sign and correct the input for later", "sign", ":=", "1.0", "\n", "if", "input", "<", "0", "{", "sign", "=", "-", "1", "\n", "input", "*=", "-", "1", "\n", "}", "\n\n", "// Use the places arg to get the amount of precision wanted", "precision", ":=", "math", ".", "Pow", "(", "10", ",", "float64", "(", "places", ")", ")", "\n\n", "// Find the decimal place we are looking to round", "digit", ":=", "input", "*", "precision", "\n\n", "// Get the actual decimal number as a fraction to be compared", "_", ",", "decimal", ":=", "math", ".", "Modf", "(", "digit", ")", "\n\n", "// If the decimal is less than .5 we round down otherwise up", "if", "decimal", ">=", "0.5", "{", "rounded", "=", "math", ".", "Ceil", "(", "digit", ")", "\n", "}", "else", "{", "rounded", "=", "math", ".", "Floor", "(", "digit", ")", "\n", "}", "\n\n", "// Finally we do the math to actually create a rounded number", "return", "rounded", "/", "precision", "*", "sign", ",", "nil", "\n", "}" ]
// Round a float to a specific decimal place or precision
[ "Round", "a", "float", "to", "a", "specific", "decimal", "place", "or", "precision" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/round.go#L6-L38
7,647
montanaflynn/stats
entropy.go
Entropy
func Entropy(input Float64Data) (float64, error) { input, err := normalize(input) if err != nil { return math.NaN(), err } var result float64 for i := 0; i < input.Len(); i++ { v := input.Get(i) if v == 0 { continue } result += (v * math.Log(v)) } return -result, nil }
go
func Entropy(input Float64Data) (float64, error) { input, err := normalize(input) if err != nil { return math.NaN(), err } var result float64 for i := 0; i < input.Len(); i++ { v := input.Get(i) if v == 0 { continue } result += (v * math.Log(v)) } return -result, nil }
[ "func", "Entropy", "(", "input", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "input", ",", "err", ":=", "normalize", "(", "input", ")", "\n", "if", "err", "!=", "nil", "{", "return", "math", ".", "NaN", "(", ")", ",", "err", "\n", "}", "\n", "var", "result", "float64", "\n", "for", "i", ":=", "0", ";", "i", "<", "input", ".", "Len", "(", ")", ";", "i", "++", "{", "v", ":=", "input", ".", "Get", "(", "i", ")", "\n", "if", "v", "==", "0", "{", "continue", "\n", "}", "\n", "result", "+=", "(", "v", "*", "math", ".", "Log", "(", "v", ")", ")", "\n", "}", "\n", "return", "-", "result", ",", "nil", "\n", "}" ]
// Entropy provides calculation of the entropy
[ "Entropy", "provides", "calculation", "of", "the", "entropy" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/entropy.go#L6-L20
7,648
montanaflynn/stats
cumulative_sum.go
CumulativeSum
func CumulativeSum(input Float64Data) ([]float64, error) { if input.Len() == 0 { return Float64Data{}, EmptyInput } cumSum := make([]float64, input.Len()) for i, val := range input { if i == 0 { cumSum[i] = val } else { cumSum[i] = cumSum[i-1] + val } } return cumSum, nil }
go
func CumulativeSum(input Float64Data) ([]float64, error) { if input.Len() == 0 { return Float64Data{}, EmptyInput } cumSum := make([]float64, input.Len()) for i, val := range input { if i == 0 { cumSum[i] = val } else { cumSum[i] = cumSum[i-1] + val } } return cumSum, nil }
[ "func", "CumulativeSum", "(", "input", "Float64Data", ")", "(", "[", "]", "float64", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "Float64Data", "{", "}", ",", "EmptyInput", "\n", "}", "\n\n", "cumSum", ":=", "make", "(", "[", "]", "float64", ",", "input", ".", "Len", "(", ")", ")", "\n\n", "for", "i", ",", "val", ":=", "range", "input", "{", "if", "i", "==", "0", "{", "cumSum", "[", "i", "]", "=", "val", "\n", "}", "else", "{", "cumSum", "[", "i", "]", "=", "cumSum", "[", "i", "-", "1", "]", "+", "val", "\n", "}", "\n", "}", "\n\n", "return", "cumSum", ",", "nil", "\n", "}" ]
// CumulativeSum calculates the cumulative sum of the input slice
[ "CumulativeSum", "calculates", "the", "cumulative", "sum", "of", "the", "input", "slice" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/cumulative_sum.go#L4-L21
7,649
montanaflynn/stats
softmax.go
SoftMax
func SoftMax(input Float64Data) ([]float64, error) { if input.Len() == 0 { return Float64Data{}, EmptyInput } s := 0.0 c, _ := Max(input) for _, e := range input { s += math.Exp(e - c) } sm := make([]float64, len(input)) for i, v := range input { sm[i] = math.Exp(v-c) / s } return sm, nil }
go
func SoftMax(input Float64Data) ([]float64, error) { if input.Len() == 0 { return Float64Data{}, EmptyInput } s := 0.0 c, _ := Max(input) for _, e := range input { s += math.Exp(e - c) } sm := make([]float64, len(input)) for i, v := range input { sm[i] = math.Exp(v-c) / s } return sm, nil }
[ "func", "SoftMax", "(", "input", "Float64Data", ")", "(", "[", "]", "float64", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "Float64Data", "{", "}", ",", "EmptyInput", "\n", "}", "\n\n", "s", ":=", "0.0", "\n", "c", ",", "_", ":=", "Max", "(", "input", ")", "\n", "for", "_", ",", "e", ":=", "range", "input", "{", "s", "+=", "math", ".", "Exp", "(", "e", "-", "c", ")", "\n", "}", "\n\n", "sm", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "input", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "input", "{", "sm", "[", "i", "]", "=", "math", ".", "Exp", "(", "v", "-", "c", ")", "/", "s", "\n", "}", "\n\n", "return", "sm", ",", "nil", "\n", "}" ]
// SoftMax returns the input values in the range of 0 to 1 // with sum of all the probabilities being equal to one. It // is commonly used in machine learning neural networks.
[ "SoftMax", "returns", "the", "input", "values", "in", "the", "range", "of", "0", "to", "1", "with", "sum", "of", "all", "the", "probabilities", "being", "equal", "to", "one", ".", "It", "is", "commonly", "used", "in", "machine", "learning", "neural", "networks", "." ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/softmax.go#L8-L25
7,650
montanaflynn/stats
deviation.go
MedianAbsoluteDeviationPopulation
func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } i := copyslice(input) m, _ := Median(i) for key, value := range i { i[key] = math.Abs(value - m) } return Median(i) }
go
func MedianAbsoluteDeviationPopulation(input Float64Data) (mad float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } i := copyslice(input) m, _ := Median(i) for key, value := range i { i[key] = math.Abs(value - m) } return Median(i) }
[ "func", "MedianAbsoluteDeviationPopulation", "(", "input", "Float64Data", ")", "(", "mad", "float64", ",", "err", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "i", ":=", "copyslice", "(", "input", ")", "\n", "m", ",", "_", ":=", "Median", "(", "i", ")", "\n\n", "for", "key", ",", "value", ":=", "range", "i", "{", "i", "[", "key", "]", "=", "math", ".", "Abs", "(", "value", "-", "m", ")", "\n", "}", "\n\n", "return", "Median", "(", "i", ")", "\n", "}" ]
// MedianAbsoluteDeviationPopulation finds the median of the absolute deviations from the population median
[ "MedianAbsoluteDeviationPopulation", "finds", "the", "median", "of", "the", "absolute", "deviations", "from", "the", "population", "median" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/deviation.go#L11-L24
7,651
montanaflynn/stats
deviation.go
StandardDeviationPopulation
func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Get the population variance vp, _ := PopulationVariance(input) // Return the population standard deviation return math.Pow(vp, 0.5), nil }
go
func StandardDeviationPopulation(input Float64Data) (sdev float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Get the population variance vp, _ := PopulationVariance(input) // Return the population standard deviation return math.Pow(vp, 0.5), nil }
[ "func", "StandardDeviationPopulation", "(", "input", "Float64Data", ")", "(", "sdev", "float64", ",", "err", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Get the population variance", "vp", ",", "_", ":=", "PopulationVariance", "(", "input", ")", "\n\n", "// Return the population standard deviation", "return", "math", ".", "Pow", "(", "vp", ",", "0.5", ")", ",", "nil", "\n", "}" ]
// StandardDeviationPopulation finds the amount of variation from the population
[ "StandardDeviationPopulation", "finds", "the", "amount", "of", "variation", "from", "the", "population" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/deviation.go#L32-L43
7,652
montanaflynn/stats
deviation.go
StandardDeviationSample
func StandardDeviationSample(input Float64Data) (sdev float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Get the sample variance vs, _ := SampleVariance(input) // Return the sample standard deviation return math.Pow(vs, 0.5), nil }
go
func StandardDeviationSample(input Float64Data) (sdev float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Get the sample variance vs, _ := SampleVariance(input) // Return the sample standard deviation return math.Pow(vs, 0.5), nil }
[ "func", "StandardDeviationSample", "(", "input", "Float64Data", ")", "(", "sdev", "float64", ",", "err", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Get the sample variance", "vs", ",", "_", ":=", "SampleVariance", "(", "input", ")", "\n\n", "// Return the sample standard deviation", "return", "math", ".", "Pow", "(", "vs", ",", "0.5", ")", ",", "nil", "\n", "}" ]
// StandardDeviationSample finds the amount of variation from a sample
[ "StandardDeviationSample", "finds", "the", "amount", "of", "variation", "from", "a", "sample" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/deviation.go#L46-L57
7,653
montanaflynn/stats
distances.go
validateData
func validateData(dataPointX, dataPointY Float64Data) error { if len(dataPointX) == 0 || len(dataPointY) == 0 { return EmptyInputErr } if len(dataPointX) != len(dataPointY) { return SizeErr } return nil }
go
func validateData(dataPointX, dataPointY Float64Data) error { if len(dataPointX) == 0 || len(dataPointY) == 0 { return EmptyInputErr } if len(dataPointX) != len(dataPointY) { return SizeErr } return nil }
[ "func", "validateData", "(", "dataPointX", ",", "dataPointY", "Float64Data", ")", "error", "{", "if", "len", "(", "dataPointX", ")", "==", "0", "||", "len", "(", "dataPointY", ")", "==", "0", "{", "return", "EmptyInputErr", "\n", "}", "\n\n", "if", "len", "(", "dataPointX", ")", "!=", "len", "(", "dataPointY", ")", "{", "return", "SizeErr", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Validate data for distance calculation
[ "Validate", "data", "for", "distance", "calculation" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/distances.go#L8-L17
7,654
montanaflynn/stats
distances.go
ChebyshevDistance
func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { return math.NaN(), err } var tempDistance float64 for i := 0; i < len(dataPointY); i++ { tempDistance = math.Abs(dataPointX[i] - dataPointY[i]) if distance < tempDistance { distance = tempDistance } } return distance, nil }
go
func ChebyshevDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { return math.NaN(), err } var tempDistance float64 for i := 0; i < len(dataPointY); i++ { tempDistance = math.Abs(dataPointX[i] - dataPointY[i]) if distance < tempDistance { distance = tempDistance } } return distance, nil }
[ "func", "ChebyshevDistance", "(", "dataPointX", ",", "dataPointY", "Float64Data", ")", "(", "distance", "float64", ",", "err", "error", ")", "{", "err", "=", "validateData", "(", "dataPointX", ",", "dataPointY", ")", "\n", "if", "err", "!=", "nil", "{", "return", "math", ".", "NaN", "(", ")", ",", "err", "\n", "}", "\n", "var", "tempDistance", "float64", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "dataPointY", ")", ";", "i", "++", "{", "tempDistance", "=", "math", ".", "Abs", "(", "dataPointX", "[", "i", "]", "-", "dataPointY", "[", "i", "]", ")", "\n", "if", "distance", "<", "tempDistance", "{", "distance", "=", "tempDistance", "\n", "}", "\n", "}", "\n", "return", "distance", ",", "nil", "\n", "}" ]
// ChebyshevDistance computes the Chebyshev distance between two data sets
[ "ChebyshevDistance", "computes", "the", "Chebyshev", "distance", "between", "two", "data", "sets" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/distances.go#L20-L33
7,655
montanaflynn/stats
distances.go
EuclideanDistance
func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { return math.NaN(), err } distance = 0 for i := 0; i < len(dataPointX); i++ { distance = distance + ((dataPointX[i] - dataPointY[i]) * (dataPointX[i] - dataPointY[i])) } return math.Sqrt(distance), nil }
go
func EuclideanDistance(dataPointX, dataPointY Float64Data) (distance float64, err error) { err = validateData(dataPointX, dataPointY) if err != nil { return math.NaN(), err } distance = 0 for i := 0; i < len(dataPointX); i++ { distance = distance + ((dataPointX[i] - dataPointY[i]) * (dataPointX[i] - dataPointY[i])) } return math.Sqrt(distance), nil }
[ "func", "EuclideanDistance", "(", "dataPointX", ",", "dataPointY", "Float64Data", ")", "(", "distance", "float64", ",", "err", "error", ")", "{", "err", "=", "validateData", "(", "dataPointX", ",", "dataPointY", ")", "\n", "if", "err", "!=", "nil", "{", "return", "math", ".", "NaN", "(", ")", ",", "err", "\n", "}", "\n", "distance", "=", "0", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "dataPointX", ")", ";", "i", "++", "{", "distance", "=", "distance", "+", "(", "(", "dataPointX", "[", "i", "]", "-", "dataPointY", "[", "i", "]", ")", "*", "(", "dataPointX", "[", "i", "]", "-", "dataPointY", "[", "i", "]", ")", ")", "\n", "}", "\n", "return", "math", ".", "Sqrt", "(", "distance", ")", ",", "nil", "\n", "}" ]
// EuclideanDistance computes the Euclidean distance between two data sets
[ "EuclideanDistance", "computes", "the", "Euclidean", "distance", "between", "two", "data", "sets" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/distances.go#L36-L47
7,656
montanaflynn/stats
mean.go
Mean
func Mean(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } sum, _ := input.Sum() return sum / float64(input.Len()), nil }
go
func Mean(input Float64Data) (float64, error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } sum, _ := input.Sum() return sum / float64(input.Len()), nil }
[ "func", "Mean", "(", "input", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "sum", ",", "_", ":=", "input", ".", "Sum", "(", ")", "\n\n", "return", "sum", "/", "float64", "(", "input", ".", "Len", "(", ")", ")", ",", "nil", "\n", "}" ]
// Mean gets the average of a slice of numbers
[ "Mean", "gets", "the", "average", "of", "a", "slice", "of", "numbers" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/mean.go#L6-L15
7,657
montanaflynn/stats
mean.go
GeometricMean
func GeometricMean(input Float64Data) (float64, error) { l := input.Len() if l == 0 { return math.NaN(), EmptyInputErr } // Get the product of all the numbers var p float64 for _, n := range input { if p == 0 { p = n } else { p *= n } } // Calculate the geometric mean return math.Pow(p, 1/float64(l)), nil }
go
func GeometricMean(input Float64Data) (float64, error) { l := input.Len() if l == 0 { return math.NaN(), EmptyInputErr } // Get the product of all the numbers var p float64 for _, n := range input { if p == 0 { p = n } else { p *= n } } // Calculate the geometric mean return math.Pow(p, 1/float64(l)), nil }
[ "func", "GeometricMean", "(", "input", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "l", ":=", "input", ".", "Len", "(", ")", "\n", "if", "l", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Get the product of all the numbers", "var", "p", "float64", "\n", "for", "_", ",", "n", ":=", "range", "input", "{", "if", "p", "==", "0", "{", "p", "=", "n", "\n", "}", "else", "{", "p", "*=", "n", "\n", "}", "\n", "}", "\n\n", "// Calculate the geometric mean", "return", "math", ".", "Pow", "(", "p", ",", "1", "/", "float64", "(", "l", ")", ")", ",", "nil", "\n", "}" ]
// GeometricMean gets the geometric mean for a slice of numbers
[ "GeometricMean", "gets", "the", "geometric", "mean", "for", "a", "slice", "of", "numbers" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/mean.go#L18-L37
7,658
montanaflynn/stats
mean.go
HarmonicMean
func HarmonicMean(input Float64Data) (float64, error) { l := input.Len() if l == 0 { return math.NaN(), EmptyInputErr } // Get the sum of all the numbers reciprocals and return an // error for values that cannot be included in harmonic mean var p float64 for _, n := range input { if n < 0 { return math.NaN(), NegativeErr } else if n == 0 { return math.NaN(), ZeroErr } p += (1 / n) } return float64(l) / p, nil }
go
func HarmonicMean(input Float64Data) (float64, error) { l := input.Len() if l == 0 { return math.NaN(), EmptyInputErr } // Get the sum of all the numbers reciprocals and return an // error for values that cannot be included in harmonic mean var p float64 for _, n := range input { if n < 0 { return math.NaN(), NegativeErr } else if n == 0 { return math.NaN(), ZeroErr } p += (1 / n) } return float64(l) / p, nil }
[ "func", "HarmonicMean", "(", "input", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "l", ":=", "input", ".", "Len", "(", ")", "\n", "if", "l", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Get the sum of all the numbers reciprocals and return an", "// error for values that cannot be included in harmonic mean", "var", "p", "float64", "\n", "for", "_", ",", "n", ":=", "range", "input", "{", "if", "n", "<", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "NegativeErr", "\n", "}", "else", "if", "n", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "ZeroErr", "\n", "}", "\n", "p", "+=", "(", "1", "/", "n", ")", "\n", "}", "\n\n", "return", "float64", "(", "l", ")", "/", "p", ",", "nil", "\n", "}" ]
// HarmonicMean gets the harmonic mean for a slice of numbers
[ "HarmonicMean", "gets", "the", "harmonic", "mean", "for", "a", "slice", "of", "numbers" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/mean.go#L40-L60
7,659
montanaflynn/stats
sum.go
Sum
func Sum(input Float64Data) (sum float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Add em up for _, n := range input { sum += n } return sum, nil }
go
func Sum(input Float64Data) (sum float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Add em up for _, n := range input { sum += n } return sum, nil }
[ "func", "Sum", "(", "input", "Float64Data", ")", "(", "sum", "float64", ",", "err", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Add em up", "for", "_", ",", "n", ":=", "range", "input", "{", "sum", "+=", "n", "\n", "}", "\n\n", "return", "sum", ",", "nil", "\n", "}" ]
// Sum adds all the numbers of a slice together
[ "Sum", "adds", "all", "the", "numbers", "of", "a", "slice", "together" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/sum.go#L6-L18
7,660
montanaflynn/stats
regression.go
LinearRegression
func LinearRegression(s Series) (regressions Series, err error) { if len(s) == 0 { return nil, EmptyInputErr } // Placeholder for the math to be done var sum [5]float64 // Loop over data keeping index in place i := 0 for ; i < len(s); i++ { sum[0] += s[i].X sum[1] += s[i].Y sum[2] += s[i].X * s[i].X sum[3] += s[i].X * s[i].Y sum[4] += s[i].Y * s[i].Y } // Find gradient and intercept f := float64(i) gradient := (f*sum[3] - sum[0]*sum[1]) / (f*sum[2] - sum[0]*sum[0]) intercept := (sum[1] / f) - (gradient * sum[0] / f) // Create the new regression series for j := 0; j < len(s); j++ { regressions = append(regressions, Coordinate{ X: s[j].X, Y: s[j].X*gradient + intercept, }) } return regressions, nil }
go
func LinearRegression(s Series) (regressions Series, err error) { if len(s) == 0 { return nil, EmptyInputErr } // Placeholder for the math to be done var sum [5]float64 // Loop over data keeping index in place i := 0 for ; i < len(s); i++ { sum[0] += s[i].X sum[1] += s[i].Y sum[2] += s[i].X * s[i].X sum[3] += s[i].X * s[i].Y sum[4] += s[i].Y * s[i].Y } // Find gradient and intercept f := float64(i) gradient := (f*sum[3] - sum[0]*sum[1]) / (f*sum[2] - sum[0]*sum[0]) intercept := (sum[1] / f) - (gradient * sum[0] / f) // Create the new regression series for j := 0; j < len(s); j++ { regressions = append(regressions, Coordinate{ X: s[j].X, Y: s[j].X*gradient + intercept, }) } return regressions, nil }
[ "func", "LinearRegression", "(", "s", "Series", ")", "(", "regressions", "Series", ",", "err", "error", ")", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "nil", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Placeholder for the math to be done", "var", "sum", "[", "5", "]", "float64", "\n\n", "// Loop over data keeping index in place", "i", ":=", "0", "\n", "for", ";", "i", "<", "len", "(", "s", ")", ";", "i", "++", "{", "sum", "[", "0", "]", "+=", "s", "[", "i", "]", ".", "X", "\n", "sum", "[", "1", "]", "+=", "s", "[", "i", "]", ".", "Y", "\n", "sum", "[", "2", "]", "+=", "s", "[", "i", "]", ".", "X", "*", "s", "[", "i", "]", ".", "X", "\n", "sum", "[", "3", "]", "+=", "s", "[", "i", "]", ".", "X", "*", "s", "[", "i", "]", ".", "Y", "\n", "sum", "[", "4", "]", "+=", "s", "[", "i", "]", ".", "Y", "*", "s", "[", "i", "]", ".", "Y", "\n", "}", "\n\n", "// Find gradient and intercept", "f", ":=", "float64", "(", "i", ")", "\n", "gradient", ":=", "(", "f", "*", "sum", "[", "3", "]", "-", "sum", "[", "0", "]", "*", "sum", "[", "1", "]", ")", "/", "(", "f", "*", "sum", "[", "2", "]", "-", "sum", "[", "0", "]", "*", "sum", "[", "0", "]", ")", "\n", "intercept", ":=", "(", "sum", "[", "1", "]", "/", "f", ")", "-", "(", "gradient", "*", "sum", "[", "0", "]", "/", "f", ")", "\n\n", "// Create the new regression series", "for", "j", ":=", "0", ";", "j", "<", "len", "(", "s", ")", ";", "j", "++", "{", "regressions", "=", "append", "(", "regressions", ",", "Coordinate", "{", "X", ":", "s", "[", "j", "]", ".", "X", ",", "Y", ":", "s", "[", "j", "]", ".", "X", "*", "gradient", "+", "intercept", ",", "}", ")", "\n", "}", "\n\n", "return", "regressions", ",", "nil", "\n", "}" ]
// LinearRegression finds the least squares linear regression on data series
[ "LinearRegression", "finds", "the", "least", "squares", "linear", "regression", "on", "data", "series" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/regression.go#L14-L47
7,661
montanaflynn/stats
regression.go
ExponentialRegression
func ExponentialRegression(s Series) (regressions Series, err error) { if len(s) == 0 { return nil, EmptyInputErr } var sum [6]float64 for i := 0; i < len(s); i++ { if s[i].Y < 0 { return nil, YCoordErr } sum[0] += s[i].X sum[1] += s[i].Y sum[2] += s[i].X * s[i].X * s[i].Y sum[3] += s[i].Y * math.Log(s[i].Y) sum[4] += s[i].X * s[i].Y * math.Log(s[i].Y) sum[5] += s[i].X * s[i].Y } denominator := (sum[1]*sum[2] - sum[5]*sum[5]) a := math.Pow(math.E, (sum[2]*sum[3]-sum[5]*sum[4])/denominator) b := (sum[1]*sum[4] - sum[5]*sum[3]) / denominator for j := 0; j < len(s); j++ { regressions = append(regressions, Coordinate{ X: s[j].X, Y: a * math.Exp(b*s[j].X), }) } return regressions, nil }
go
func ExponentialRegression(s Series) (regressions Series, err error) { if len(s) == 0 { return nil, EmptyInputErr } var sum [6]float64 for i := 0; i < len(s); i++ { if s[i].Y < 0 { return nil, YCoordErr } sum[0] += s[i].X sum[1] += s[i].Y sum[2] += s[i].X * s[i].X * s[i].Y sum[3] += s[i].Y * math.Log(s[i].Y) sum[4] += s[i].X * s[i].Y * math.Log(s[i].Y) sum[5] += s[i].X * s[i].Y } denominator := (sum[1]*sum[2] - sum[5]*sum[5]) a := math.Pow(math.E, (sum[2]*sum[3]-sum[5]*sum[4])/denominator) b := (sum[1]*sum[4] - sum[5]*sum[3]) / denominator for j := 0; j < len(s); j++ { regressions = append(regressions, Coordinate{ X: s[j].X, Y: a * math.Exp(b*s[j].X), }) } return regressions, nil }
[ "func", "ExponentialRegression", "(", "s", "Series", ")", "(", "regressions", "Series", ",", "err", "error", ")", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "nil", ",", "EmptyInputErr", "\n", "}", "\n\n", "var", "sum", "[", "6", "]", "float64", "\n\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "s", ")", ";", "i", "++", "{", "if", "s", "[", "i", "]", ".", "Y", "<", "0", "{", "return", "nil", ",", "YCoordErr", "\n", "}", "\n", "sum", "[", "0", "]", "+=", "s", "[", "i", "]", ".", "X", "\n", "sum", "[", "1", "]", "+=", "s", "[", "i", "]", ".", "Y", "\n", "sum", "[", "2", "]", "+=", "s", "[", "i", "]", ".", "X", "*", "s", "[", "i", "]", ".", "X", "*", "s", "[", "i", "]", ".", "Y", "\n", "sum", "[", "3", "]", "+=", "s", "[", "i", "]", ".", "Y", "*", "math", ".", "Log", "(", "s", "[", "i", "]", ".", "Y", ")", "\n", "sum", "[", "4", "]", "+=", "s", "[", "i", "]", ".", "X", "*", "s", "[", "i", "]", ".", "Y", "*", "math", ".", "Log", "(", "s", "[", "i", "]", ".", "Y", ")", "\n", "sum", "[", "5", "]", "+=", "s", "[", "i", "]", ".", "X", "*", "s", "[", "i", "]", ".", "Y", "\n", "}", "\n\n", "denominator", ":=", "(", "sum", "[", "1", "]", "*", "sum", "[", "2", "]", "-", "sum", "[", "5", "]", "*", "sum", "[", "5", "]", ")", "\n", "a", ":=", "math", ".", "Pow", "(", "math", ".", "E", ",", "(", "sum", "[", "2", "]", "*", "sum", "[", "3", "]", "-", "sum", "[", "5", "]", "*", "sum", "[", "4", "]", ")", "/", "denominator", ")", "\n", "b", ":=", "(", "sum", "[", "1", "]", "*", "sum", "[", "4", "]", "-", "sum", "[", "5", "]", "*", "sum", "[", "3", "]", ")", "/", "denominator", "\n\n", "for", "j", ":=", "0", ";", "j", "<", "len", "(", "s", ")", ";", "j", "++", "{", "regressions", "=", "append", "(", "regressions", ",", "Coordinate", "{", "X", ":", "s", "[", "j", "]", ".", "X", ",", "Y", ":", "a", "*", "math", ".", "Exp", "(", "b", "*", "s", "[", "j", "]", ".", "X", ")", ",", "}", ")", "\n", "}", "\n\n", "return", "regressions", ",", "nil", "\n", "}" ]
// ExponentialRegression returns an exponential regression on data series
[ "ExponentialRegression", "returns", "an", "exponential", "regression", "on", "data", "series" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/regression.go#L50-L82
7,662
montanaflynn/stats
regression.go
LogarithmicRegression
func LogarithmicRegression(s Series) (regressions Series, err error) { if len(s) == 0 { return nil, EmptyInputErr } var sum [4]float64 i := 0 for ; i < len(s); i++ { sum[0] += math.Log(s[i].X) sum[1] += s[i].Y * math.Log(s[i].X) sum[2] += s[i].Y sum[3] += math.Pow(math.Log(s[i].X), 2) } f := float64(i) a := (f*sum[1] - sum[2]*sum[0]) / (f*sum[3] - sum[0]*sum[0]) b := (sum[2] - a*sum[0]) / f for j := 0; j < len(s); j++ { regressions = append(regressions, Coordinate{ X: s[j].X, Y: b + a*math.Log(s[j].X), }) } return regressions, nil }
go
func LogarithmicRegression(s Series) (regressions Series, err error) { if len(s) == 0 { return nil, EmptyInputErr } var sum [4]float64 i := 0 for ; i < len(s); i++ { sum[0] += math.Log(s[i].X) sum[1] += s[i].Y * math.Log(s[i].X) sum[2] += s[i].Y sum[3] += math.Pow(math.Log(s[i].X), 2) } f := float64(i) a := (f*sum[1] - sum[2]*sum[0]) / (f*sum[3] - sum[0]*sum[0]) b := (sum[2] - a*sum[0]) / f for j := 0; j < len(s); j++ { regressions = append(regressions, Coordinate{ X: s[j].X, Y: b + a*math.Log(s[j].X), }) } return regressions, nil }
[ "func", "LogarithmicRegression", "(", "s", "Series", ")", "(", "regressions", "Series", ",", "err", "error", ")", "{", "if", "len", "(", "s", ")", "==", "0", "{", "return", "nil", ",", "EmptyInputErr", "\n", "}", "\n\n", "var", "sum", "[", "4", "]", "float64", "\n\n", "i", ":=", "0", "\n", "for", ";", "i", "<", "len", "(", "s", ")", ";", "i", "++", "{", "sum", "[", "0", "]", "+=", "math", ".", "Log", "(", "s", "[", "i", "]", ".", "X", ")", "\n", "sum", "[", "1", "]", "+=", "s", "[", "i", "]", ".", "Y", "*", "math", ".", "Log", "(", "s", "[", "i", "]", ".", "X", ")", "\n", "sum", "[", "2", "]", "+=", "s", "[", "i", "]", ".", "Y", "\n", "sum", "[", "3", "]", "+=", "math", ".", "Pow", "(", "math", ".", "Log", "(", "s", "[", "i", "]", ".", "X", ")", ",", "2", ")", "\n", "}", "\n\n", "f", ":=", "float64", "(", "i", ")", "\n", "a", ":=", "(", "f", "*", "sum", "[", "1", "]", "-", "sum", "[", "2", "]", "*", "sum", "[", "0", "]", ")", "/", "(", "f", "*", "sum", "[", "3", "]", "-", "sum", "[", "0", "]", "*", "sum", "[", "0", "]", ")", "\n", "b", ":=", "(", "sum", "[", "2", "]", "-", "a", "*", "sum", "[", "0", "]", ")", "/", "f", "\n\n", "for", "j", ":=", "0", ";", "j", "<", "len", "(", "s", ")", ";", "j", "++", "{", "regressions", "=", "append", "(", "regressions", ",", "Coordinate", "{", "X", ":", "s", "[", "j", "]", ".", "X", ",", "Y", ":", "b", "+", "a", "*", "math", ".", "Log", "(", "s", "[", "j", "]", ".", "X", ")", ",", "}", ")", "\n", "}", "\n\n", "return", "regressions", ",", "nil", "\n", "}" ]
// LogarithmicRegression returns an logarithmic regression on data series
[ "LogarithmicRegression", "returns", "an", "logarithmic", "regression", "on", "data", "series" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/regression.go#L85-L113
7,663
montanaflynn/stats
median.go
Median
func Median(input Float64Data) (median float64, err error) { // Start by sorting a copy of the slice c := sortedCopy(input) // No math is needed if there are no numbers // For even numbers we add the two middle numbers // and divide by two using the mean function above // For odd numbers we just use the middle number l := len(c) if l == 0 { return math.NaN(), EmptyInputErr } else if l%2 == 0 { median, _ = Mean(c[l/2-1 : l/2+1]) } else { median = c[l/2] } return median, nil }
go
func Median(input Float64Data) (median float64, err error) { // Start by sorting a copy of the slice c := sortedCopy(input) // No math is needed if there are no numbers // For even numbers we add the two middle numbers // and divide by two using the mean function above // For odd numbers we just use the middle number l := len(c) if l == 0 { return math.NaN(), EmptyInputErr } else if l%2 == 0 { median, _ = Mean(c[l/2-1 : l/2+1]) } else { median = c[l/2] } return median, nil }
[ "func", "Median", "(", "input", "Float64Data", ")", "(", "median", "float64", ",", "err", "error", ")", "{", "// Start by sorting a copy of the slice", "c", ":=", "sortedCopy", "(", "input", ")", "\n\n", "// No math is needed if there are no numbers", "// For even numbers we add the two middle numbers", "// and divide by two using the mean function above", "// For odd numbers we just use the middle number", "l", ":=", "len", "(", "c", ")", "\n", "if", "l", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "else", "if", "l", "%", "2", "==", "0", "{", "median", ",", "_", "=", "Mean", "(", "c", "[", "l", "/", "2", "-", "1", ":", "l", "/", "2", "+", "1", "]", ")", "\n", "}", "else", "{", "median", "=", "c", "[", "l", "/", "2", "]", "\n", "}", "\n\n", "return", "median", ",", "nil", "\n", "}" ]
// Median gets the median number in a slice of numbers
[ "Median", "gets", "the", "median", "number", "in", "a", "slice", "of", "numbers" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/median.go#L6-L25
7,664
montanaflynn/stats
variance.go
_variance
func _variance(input Float64Data, sample int) (variance float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Sum the square of the mean subtracted from each number m, _ := Mean(input) for _, n := range input { variance += (n - m) * (n - m) } // When getting the mean of the squared differences // "sample" will allow us to know if it's a sample // or population and wether to subtract by one or not return variance / float64((input.Len() - (1 * sample))), nil }
go
func _variance(input Float64Data, sample int) (variance float64, err error) { if input.Len() == 0 { return math.NaN(), EmptyInputErr } // Sum the square of the mean subtracted from each number m, _ := Mean(input) for _, n := range input { variance += (n - m) * (n - m) } // When getting the mean of the squared differences // "sample" will allow us to know if it's a sample // or population and wether to subtract by one or not return variance / float64((input.Len() - (1 * sample))), nil }
[ "func", "_variance", "(", "input", "Float64Data", ",", "sample", "int", ")", "(", "variance", "float64", ",", "err", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "math", ".", "NaN", "(", ")", ",", "EmptyInputErr", "\n", "}", "\n\n", "// Sum the square of the mean subtracted from each number", "m", ",", "_", ":=", "Mean", "(", "input", ")", "\n\n", "for", "_", ",", "n", ":=", "range", "input", "{", "variance", "+=", "(", "n", "-", "m", ")", "*", "(", "n", "-", "m", ")", "\n", "}", "\n\n", "// When getting the mean of the squared differences", "// \"sample\" will allow us to know if it's a sample", "// or population and wether to subtract by one or not", "return", "variance", "/", "float64", "(", "(", "input", ".", "Len", "(", ")", "-", "(", "1", "*", "sample", ")", ")", ")", ",", "nil", "\n", "}" ]
// _variance finds the variance for both population and sample data
[ "_variance", "finds", "the", "variance", "for", "both", "population", "and", "sample", "data" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/variance.go#L6-L23
7,665
montanaflynn/stats
variance.go
PopulationVariance
func PopulationVariance(input Float64Data) (pvar float64, err error) { v, err := _variance(input, 0) if err != nil { return math.NaN(), err } return v, nil }
go
func PopulationVariance(input Float64Data) (pvar float64, err error) { v, err := _variance(input, 0) if err != nil { return math.NaN(), err } return v, nil }
[ "func", "PopulationVariance", "(", "input", "Float64Data", ")", "(", "pvar", "float64", ",", "err", "error", ")", "{", "v", ",", "err", ":=", "_variance", "(", "input", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "return", "math", ".", "NaN", "(", ")", ",", "err", "\n", "}", "\n\n", "return", "v", ",", "nil", "\n", "}" ]
// PopulationVariance finds the amount of variance within a population
[ "PopulationVariance", "finds", "the", "amount", "of", "variance", "within", "a", "population" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/variance.go#L31-L39
7,666
montanaflynn/stats
variance.go
SampleVariance
func SampleVariance(input Float64Data) (svar float64, err error) { v, err := _variance(input, 1) if err != nil { return math.NaN(), err } return v, nil }
go
func SampleVariance(input Float64Data) (svar float64, err error) { v, err := _variance(input, 1) if err != nil { return math.NaN(), err } return v, nil }
[ "func", "SampleVariance", "(", "input", "Float64Data", ")", "(", "svar", "float64", ",", "err", "error", ")", "{", "v", ",", "err", ":=", "_variance", "(", "input", ",", "1", ")", "\n", "if", "err", "!=", "nil", "{", "return", "math", ".", "NaN", "(", ")", ",", "err", "\n", "}", "\n\n", "return", "v", ",", "nil", "\n", "}" ]
// SampleVariance finds the amount of variance within a sample
[ "SampleVariance", "finds", "the", "amount", "of", "variance", "within", "a", "sample" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/variance.go#L42-L50
7,667
montanaflynn/stats
sigmoid.go
Sigmoid
func Sigmoid(input Float64Data) ([]float64, error) { if input.Len() == 0 { return Float64Data{}, EmptyInput } s := make([]float64, len(input)) for i, v := range input { s[i] = 1 / (1 + math.Exp(-v)) } return s, nil }
go
func Sigmoid(input Float64Data) ([]float64, error) { if input.Len() == 0 { return Float64Data{}, EmptyInput } s := make([]float64, len(input)) for i, v := range input { s[i] = 1 / (1 + math.Exp(-v)) } return s, nil }
[ "func", "Sigmoid", "(", "input", "Float64Data", ")", "(", "[", "]", "float64", ",", "error", ")", "{", "if", "input", ".", "Len", "(", ")", "==", "0", "{", "return", "Float64Data", "{", "}", ",", "EmptyInput", "\n", "}", "\n", "s", ":=", "make", "(", "[", "]", "float64", ",", "len", "(", "input", ")", ")", "\n", "for", "i", ",", "v", ":=", "range", "input", "{", "s", "[", "i", "]", "=", "1", "/", "(", "1", "+", "math", ".", "Exp", "(", "-", "v", ")", ")", "\n", "}", "\n", "return", "s", ",", "nil", "\n", "}" ]
// Sigmoid returns the input values in the range of -1 to 1 // along the sigmoid or s-shaped curve, commonly used in // machine learning while training neural networks as an // activation function.
[ "Sigmoid", "returns", "the", "input", "values", "in", "the", "range", "of", "-", "1", "to", "1", "along", "the", "sigmoid", "or", "s", "-", "shaped", "curve", "commonly", "used", "in", "machine", "learning", "while", "training", "neural", "networks", "as", "an", "activation", "function", "." ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/sigmoid.go#L9-L18
7,668
montanaflynn/stats
util.go
float64ToInt
func float64ToInt(input float64) (output int) { r, _ := Round(input, 0) return int(r) }
go
func float64ToInt(input float64) (output int) { r, _ := Round(input, 0) return int(r) }
[ "func", "float64ToInt", "(", "input", "float64", ")", "(", "output", "int", ")", "{", "r", ",", "_", ":=", "Round", "(", "input", ",", "0", ")", "\n", "return", "int", "(", "r", ")", "\n", "}" ]
// float64ToInt rounds a float64 to an int
[ "float64ToInt", "rounds", "a", "float64", "to", "an", "int" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/util.go#L9-L12
7,669
montanaflynn/stats
util.go
copyslice
func copyslice(input Float64Data) Float64Data { s := make(Float64Data, input.Len()) copy(s, input) return s }
go
func copyslice(input Float64Data) Float64Data { s := make(Float64Data, input.Len()) copy(s, input) return s }
[ "func", "copyslice", "(", "input", "Float64Data", ")", "Float64Data", "{", "s", ":=", "make", "(", "Float64Data", ",", "input", ".", "Len", "(", ")", ")", "\n", "copy", "(", "s", ",", "input", ")", "\n", "return", "s", "\n", "}" ]
// copyslice copies a slice of float64s
[ "copyslice", "copies", "a", "slice", "of", "float64s" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/util.go#L20-L24
7,670
montanaflynn/stats
util.go
sortedCopyDif
func sortedCopyDif(input Float64Data) (copy Float64Data) { if sort.Float64sAreSorted(input) { return input } copy = copyslice(input) sort.Float64s(copy) return }
go
func sortedCopyDif(input Float64Data) (copy Float64Data) { if sort.Float64sAreSorted(input) { return input } copy = copyslice(input) sort.Float64s(copy) return }
[ "func", "sortedCopyDif", "(", "input", "Float64Data", ")", "(", "copy", "Float64Data", ")", "{", "if", "sort", ".", "Float64sAreSorted", "(", "input", ")", "{", "return", "input", "\n", "}", "\n", "copy", "=", "copyslice", "(", "input", ")", "\n", "sort", ".", "Float64s", "(", "copy", ")", "\n", "return", "\n", "}" ]
// sortedCopyDif returns a sorted copy of float64s // only if the original data isn't sorted. // Only use this if returned slice won't be manipulated!
[ "sortedCopyDif", "returns", "a", "sorted", "copy", "of", "float64s", "only", "if", "the", "original", "data", "isn", "t", "sorted", ".", "Only", "use", "this", "if", "returned", "slice", "won", "t", "be", "manipulated!" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/util.go#L36-L43
7,671
montanaflynn/stats
data.go
PercentileNearestRank
func (f Float64Data) PercentileNearestRank(p float64) (float64, error) { return PercentileNearestRank(f, p) }
go
func (f Float64Data) PercentileNearestRank(p float64) (float64, error) { return PercentileNearestRank(f, p) }
[ "func", "(", "f", "Float64Data", ")", "PercentileNearestRank", "(", "p", "float64", ")", "(", "float64", ",", "error", ")", "{", "return", "PercentileNearestRank", "(", "f", ",", "p", ")", "\n", "}" ]
// PercentileNearestRank finds the relative standing using the Nearest Rank method
[ "PercentileNearestRank", "finds", "the", "relative", "standing", "using", "the", "Nearest", "Rank", "method" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/data.go#L81-L83
7,672
montanaflynn/stats
data.go
Pearson
func (f Float64Data) Pearson(d Float64Data) (float64, error) { return Pearson(f, d) }
go
func (f Float64Data) Pearson(d Float64Data) (float64, error) { return Pearson(f, d) }
[ "func", "(", "f", "Float64Data", ")", "Pearson", "(", "d", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "return", "Pearson", "(", "f", ",", "d", ")", "\n", "}" ]
// Pearson calculates the Pearson product-moment correlation coefficient between two variables.
[ "Pearson", "calculates", "the", "Pearson", "product", "-", "moment", "correlation", "coefficient", "between", "two", "variables", "." ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/data.go#L96-L98
7,673
montanaflynn/stats
data.go
CovariancePopulation
func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error) { return CovariancePopulation(f, d) }
go
func (f Float64Data) CovariancePopulation(d Float64Data) (float64, error) { return CovariancePopulation(f, d) }
[ "func", "(", "f", "Float64Data", ")", "CovariancePopulation", "(", "d", "Float64Data", ")", "(", "float64", ",", "error", ")", "{", "return", "CovariancePopulation", "(", "f", ",", "d", ")", "\n", "}" ]
// CovariancePopulation computes covariance for entire population between two variables
[ "CovariancePopulation", "computes", "covariance", "for", "entire", "population", "between", "two", "variables" ]
38304a2645bb6bd10153d518e10a9b69190ff730
https://github.com/montanaflynn/stats/blob/38304a2645bb6bd10153d518e10a9b69190ff730/data.go#L146-L148
7,674
hashicorp/logutils
level.go
Check
func (f *LevelFilter) Check(line []byte) bool { f.once.Do(f.init) // Check for a log level var level LogLevel x := bytes.IndexByte(line, '[') if x >= 0 { y := bytes.IndexByte(line[x:], ']') if y >= 0 { level = LogLevel(line[x+1 : x+y]) } } _, ok := f.badLevels[level] return !ok }
go
func (f *LevelFilter) Check(line []byte) bool { f.once.Do(f.init) // Check for a log level var level LogLevel x := bytes.IndexByte(line, '[') if x >= 0 { y := bytes.IndexByte(line[x:], ']') if y >= 0 { level = LogLevel(line[x+1 : x+y]) } } _, ok := f.badLevels[level] return !ok }
[ "func", "(", "f", "*", "LevelFilter", ")", "Check", "(", "line", "[", "]", "byte", ")", "bool", "{", "f", ".", "once", ".", "Do", "(", "f", ".", "init", ")", "\n\n", "// Check for a log level", "var", "level", "LogLevel", "\n", "x", ":=", "bytes", ".", "IndexByte", "(", "line", ",", "'['", ")", "\n", "if", "x", ">=", "0", "{", "y", ":=", "bytes", ".", "IndexByte", "(", "line", "[", "x", ":", "]", ",", "']'", ")", "\n", "if", "y", ">=", "0", "{", "level", "=", "LogLevel", "(", "line", "[", "x", "+", "1", ":", "x", "+", "y", "]", ")", "\n", "}", "\n", "}", "\n\n", "_", ",", "ok", ":=", "f", ".", "badLevels", "[", "level", "]", "\n", "return", "!", "ok", "\n", "}" ]
// Check will check a given line if it would be included in the level // filter.
[ "Check", "will", "check", "a", "given", "line", "if", "it", "would", "be", "included", "in", "the", "level", "filter", "." ]
a335183dfd075f638afcc820c90591ca3c97eba6
https://github.com/hashicorp/logutils/blob/a335183dfd075f638afcc820c90591ca3c97eba6/level.go#L35-L50
7,675
hashicorp/logutils
level.go
SetMinLevel
func (f *LevelFilter) SetMinLevel(min LogLevel) { f.MinLevel = min f.init() }
go
func (f *LevelFilter) SetMinLevel(min LogLevel) { f.MinLevel = min f.init() }
[ "func", "(", "f", "*", "LevelFilter", ")", "SetMinLevel", "(", "min", "LogLevel", ")", "{", "f", ".", "MinLevel", "=", "min", "\n", "f", ".", "init", "(", ")", "\n", "}" ]
// SetMinLevel is used to update the minimum log level
[ "SetMinLevel", "is", "used", "to", "update", "the", "minimum", "log", "level" ]
a335183dfd075f638afcc820c90591ca3c97eba6
https://github.com/hashicorp/logutils/blob/a335183dfd075f638afcc820c90591ca3c97eba6/level.go#L67-L70
7,676
cortesi/modd
varcmd/varcmd.go
mkArgs
func mkArgs(paths []string) string { escaped := make([]string, len(paths)) for i, s := range paths { escaped[i] = quotePath(realRel(s)) } return strings.Join(escaped, " ") }
go
func mkArgs(paths []string) string { escaped := make([]string, len(paths)) for i, s := range paths { escaped[i] = quotePath(realRel(s)) } return strings.Join(escaped, " ") }
[ "func", "mkArgs", "(", "paths", "[", "]", "string", ")", "string", "{", "escaped", ":=", "make", "(", "[", "]", "string", ",", "len", "(", "paths", ")", ")", "\n", "for", "i", ",", "s", ":=", "range", "paths", "{", "escaped", "[", "i", "]", "=", "quotePath", "(", "realRel", "(", "s", ")", ")", "\n", "}", "\n", "return", "strings", ".", "Join", "(", "escaped", ",", "\"", "\"", ")", "\n", "}" ]
// mkArgs prepares a list of paths for the command line
[ "mkArgs", "prepares", "a", "list", "of", "paths", "for", "the", "command", "line" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/varcmd/varcmd.go#L52-L58
7,677
cortesi/modd
varcmd/varcmd.go
get
func (v *VarCmd) get(name string) (string, error) { if val, ok := v.Vars[name]; ok { return val, nil } if (name == "@mods" || name == "@dirmods") && v.Block != nil { var modified []string if v.Modified == nil { var err error modified, err = moddwatch.List(".", v.Block.Include, v.Block.Exclude) if err != nil { return "", err } } else { modified = v.Modified } v.Vars["@mods"] = mkArgs(modified) v.Vars["@dirmods"] = mkArgs(getDirs(modified)) return v.Vars[name], nil } return "", fmt.Errorf("No such variable: %s", name) }
go
func (v *VarCmd) get(name string) (string, error) { if val, ok := v.Vars[name]; ok { return val, nil } if (name == "@mods" || name == "@dirmods") && v.Block != nil { var modified []string if v.Modified == nil { var err error modified, err = moddwatch.List(".", v.Block.Include, v.Block.Exclude) if err != nil { return "", err } } else { modified = v.Modified } v.Vars["@mods"] = mkArgs(modified) v.Vars["@dirmods"] = mkArgs(getDirs(modified)) return v.Vars[name], nil } return "", fmt.Errorf("No such variable: %s", name) }
[ "func", "(", "v", "*", "VarCmd", ")", "get", "(", "name", "string", ")", "(", "string", ",", "error", ")", "{", "if", "val", ",", "ok", ":=", "v", ".", "Vars", "[", "name", "]", ";", "ok", "{", "return", "val", ",", "nil", "\n", "}", "\n", "if", "(", "name", "==", "\"", "\"", "||", "name", "==", "\"", "\"", ")", "&&", "v", ".", "Block", "!=", "nil", "{", "var", "modified", "[", "]", "string", "\n", "if", "v", ".", "Modified", "==", "nil", "{", "var", "err", "error", "\n", "modified", ",", "err", "=", "moddwatch", ".", "List", "(", "\"", "\"", ",", "v", ".", "Block", ".", "Include", ",", "v", ".", "Block", ".", "Exclude", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "}", "else", "{", "modified", "=", "v", ".", "Modified", "\n", "}", "\n", "v", ".", "Vars", "[", "\"", "\"", "]", "=", "mkArgs", "(", "modified", ")", "\n", "v", ".", "Vars", "[", "\"", "\"", "]", "=", "mkArgs", "(", "getDirs", "(", "modified", ")", ")", "\n", "return", "v", ".", "Vars", "[", "name", "]", ",", "nil", "\n", "}", "\n", "return", "\"", "\"", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "name", ")", "\n", "}" ]
// Get a variable by name
[ "Get", "a", "variable", "by", "name" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/varcmd/varcmd.go#L69-L89
7,678
cortesi/modd
varcmd/varcmd.go
Render
func (v *VarCmd) Render(cmd string) (string, error) { var err error cmd = string( name.ReplaceAllFunc( []byte(cmd), func(key []byte) []byte { cnt := 0 for _, c := range key { if c != esc { break } cnt++ } ks := strings.TrimLeft(string(key), string(esc)) if cnt%2 != 0 { return []byte(strings.Repeat(string(esc), (cnt-1)/2) + ks) } val, errv := v.get(ks) if errv != nil { err = fmt.Errorf("No such variable: %s", ks) return nil } val = strings.Repeat(string(esc), cnt/2) + val return []byte(val) }, ), ) if err != nil { return "", err } return cmd, nil }
go
func (v *VarCmd) Render(cmd string) (string, error) { var err error cmd = string( name.ReplaceAllFunc( []byte(cmd), func(key []byte) []byte { cnt := 0 for _, c := range key { if c != esc { break } cnt++ } ks := strings.TrimLeft(string(key), string(esc)) if cnt%2 != 0 { return []byte(strings.Repeat(string(esc), (cnt-1)/2) + ks) } val, errv := v.get(ks) if errv != nil { err = fmt.Errorf("No such variable: %s", ks) return nil } val = strings.Repeat(string(esc), cnt/2) + val return []byte(val) }, ), ) if err != nil { return "", err } return cmd, nil }
[ "func", "(", "v", "*", "VarCmd", ")", "Render", "(", "cmd", "string", ")", "(", "string", ",", "error", ")", "{", "var", "err", "error", "\n", "cmd", "=", "string", "(", "name", ".", "ReplaceAllFunc", "(", "[", "]", "byte", "(", "cmd", ")", ",", "func", "(", "key", "[", "]", "byte", ")", "[", "]", "byte", "{", "cnt", ":=", "0", "\n", "for", "_", ",", "c", ":=", "range", "key", "{", "if", "c", "!=", "esc", "{", "break", "\n", "}", "\n", "cnt", "++", "\n", "}", "\n", "ks", ":=", "strings", ".", "TrimLeft", "(", "string", "(", "key", ")", ",", "string", "(", "esc", ")", ")", "\n", "if", "cnt", "%", "2", "!=", "0", "{", "return", "[", "]", "byte", "(", "strings", ".", "Repeat", "(", "string", "(", "esc", ")", ",", "(", "cnt", "-", "1", ")", "/", "2", ")", "+", "ks", ")", "\n", "}", "\n", "val", ",", "errv", ":=", "v", ".", "get", "(", "ks", ")", "\n", "if", "errv", "!=", "nil", "{", "err", "=", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "ks", ")", "\n", "return", "nil", "\n", "}", "\n", "val", "=", "strings", ".", "Repeat", "(", "string", "(", "esc", ")", ",", "cnt", "/", "2", ")", "+", "val", "\n", "return", "[", "]", "byte", "(", "val", ")", "\n", "}", ",", ")", ",", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", ",", "err", "\n", "}", "\n", "return", "cmd", ",", "nil", "\n", "}" ]
// Render renders the command with a map of variables
[ "Render", "renders", "the", "command", "with", "a", "map", "of", "variables" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/varcmd/varcmd.go#L94-L125
7,679
cortesi/modd
notify/notify.go
Push
func (GrowlNotifier) Push(title string, text string, iconPath string) { cmd := exec.Command( "growlnotify", "-n", prog, "-d", prog, "-m", text, prog, ) go cmd.Run() }
go
func (GrowlNotifier) Push(title string, text string, iconPath string) { cmd := exec.Command( "growlnotify", "-n", prog, "-d", prog, "-m", text, prog, ) go cmd.Run() }
[ "func", "(", "GrowlNotifier", ")", "Push", "(", "title", "string", ",", "text", "string", ",", "iconPath", "string", ")", "{", "cmd", ":=", "exec", ".", "Command", "(", "\"", "\"", ",", "\"", "\"", ",", "prog", ",", "\"", "\"", ",", "prog", ",", "\"", "\"", ",", "text", ",", "prog", ",", ")", "\n", "go", "cmd", ".", "Run", "(", ")", "\n", "}" ]
// Push implements Notifier
[ "Push", "implements", "Notifier" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/notify/notify.go#L36-L41
7,680
cortesi/modd
prep.go
RunProc
func RunProc(cmd string, shellMethod string, dir string, log termlog.Stream) error { log.Header() ex, err := shell.NewExecutor(shellMethod, cmd, dir) if err != nil { return err } start := time.Now() err, estate := ex.Run(log, true) if err != nil { return err } else if estate.Error != nil { log.Shout("%s", estate.Error) return ProcError{estate.Error.Error(), estate.ErrOutput} } log.Notice(">> done (%s)", time.Since(start)) return nil }
go
func RunProc(cmd string, shellMethod string, dir string, log termlog.Stream) error { log.Header() ex, err := shell.NewExecutor(shellMethod, cmd, dir) if err != nil { return err } start := time.Now() err, estate := ex.Run(log, true) if err != nil { return err } else if estate.Error != nil { log.Shout("%s", estate.Error) return ProcError{estate.Error.Error(), estate.ErrOutput} } log.Notice(">> done (%s)", time.Since(start)) return nil }
[ "func", "RunProc", "(", "cmd", "string", ",", "shellMethod", "string", ",", "dir", "string", ",", "log", "termlog", ".", "Stream", ")", "error", "{", "log", ".", "Header", "(", ")", "\n", "ex", ",", "err", ":=", "shell", ".", "NewExecutor", "(", "shellMethod", ",", "cmd", ",", "dir", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "start", ":=", "time", ".", "Now", "(", ")", "\n", "err", ",", "estate", ":=", "ex", ".", "Run", "(", "log", ",", "true", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "else", "if", "estate", ".", "Error", "!=", "nil", "{", "log", ".", "Shout", "(", "\"", "\"", ",", "estate", ".", "Error", ")", "\n", "return", "ProcError", "{", "estate", ".", "Error", ".", "Error", "(", ")", ",", "estate", ".", "ErrOutput", "}", "\n", "}", "\n", "log", ".", "Notice", "(", "\"", "\"", ",", "time", ".", "Since", "(", "start", ")", ")", "\n", "return", "nil", "\n", "}" ]
// RunProc runs a process to completion, sending output to log
[ "RunProc", "runs", "a", "process", "to", "completion", "sending", "output", "to", "log" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/prep.go#L25-L41
7,681
cortesi/modd
prep.go
RunPreps
func RunPreps( b conf.Block, vars map[string]string, mod *moddwatch.Mod, log termlog.TermLog, notifiers []notify.Notifier, initial bool, ) error { sh, err := shell.GetShellName(vars[shellVarName]) if err != nil { return err } var modified []string if mod != nil { modified = mod.All() } vcmd := varcmd.VarCmd{Block: &b, Modified: modified, Vars: vars} for _, p := range b.Preps { cmd, err := vcmd.Render(p.Command) if initial && p.Onchange { log.Say(niceHeader("skipping prep: ", cmd)) continue } if err != nil { return err } err = RunProc(cmd, sh, b.InDir, log.Stream(niceHeader("prep: ", cmd))) if err != nil { if pe, ok := err.(ProcError); ok { for _, n := range notifiers { n.Push("modd error", pe.Output, "") } } return err } } return nil }
go
func RunPreps( b conf.Block, vars map[string]string, mod *moddwatch.Mod, log termlog.TermLog, notifiers []notify.Notifier, initial bool, ) error { sh, err := shell.GetShellName(vars[shellVarName]) if err != nil { return err } var modified []string if mod != nil { modified = mod.All() } vcmd := varcmd.VarCmd{Block: &b, Modified: modified, Vars: vars} for _, p := range b.Preps { cmd, err := vcmd.Render(p.Command) if initial && p.Onchange { log.Say(niceHeader("skipping prep: ", cmd)) continue } if err != nil { return err } err = RunProc(cmd, sh, b.InDir, log.Stream(niceHeader("prep: ", cmd))) if err != nil { if pe, ok := err.(ProcError); ok { for _, n := range notifiers { n.Push("modd error", pe.Output, "") } } return err } } return nil }
[ "func", "RunPreps", "(", "b", "conf", ".", "Block", ",", "vars", "map", "[", "string", "]", "string", ",", "mod", "*", "moddwatch", ".", "Mod", ",", "log", "termlog", ".", "TermLog", ",", "notifiers", "[", "]", "notify", ".", "Notifier", ",", "initial", "bool", ",", ")", "error", "{", "sh", ",", "err", ":=", "shell", ".", "GetShellName", "(", "vars", "[", "shellVarName", "]", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "var", "modified", "[", "]", "string", "\n", "if", "mod", "!=", "nil", "{", "modified", "=", "mod", ".", "All", "(", ")", "\n", "}", "\n", "vcmd", ":=", "varcmd", ".", "VarCmd", "{", "Block", ":", "&", "b", ",", "Modified", ":", "modified", ",", "Vars", ":", "vars", "}", "\n", "for", "_", ",", "p", ":=", "range", "b", ".", "Preps", "{", "cmd", ",", "err", ":=", "vcmd", ".", "Render", "(", "p", ".", "Command", ")", "\n", "if", "initial", "&&", "p", ".", "Onchange", "{", "log", ".", "Say", "(", "niceHeader", "(", "\"", "\"", ",", "cmd", ")", ")", "\n", "continue", "\n", "}", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "err", "=", "RunProc", "(", "cmd", ",", "sh", ",", "b", ".", "InDir", ",", "log", ".", "Stream", "(", "niceHeader", "(", "\"", "\"", ",", "cmd", ")", ")", ")", "\n", "if", "err", "!=", "nil", "{", "if", "pe", ",", "ok", ":=", "err", ".", "(", "ProcError", ")", ";", "ok", "{", "for", "_", ",", "n", ":=", "range", "notifiers", "{", "n", ".", "Push", "(", "\"", "\"", ",", "pe", ".", "Output", ",", "\"", "\"", ")", "\n", "}", "\n", "}", "\n", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// RunPreps runs all commands in sequence. Stops if any command returns an error.
[ "RunPreps", "runs", "all", "commands", "in", "sequence", ".", "Stops", "if", "any", "command", "returns", "an", "error", "." ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/prep.go#L44-L82
7,682
cortesi/modd
conf/lex.go
acceptFunc
func (l *lexer) acceptFunc(match func(rune) bool) { for match(l.peek()) { l.next() } }
go
func (l *lexer) acceptFunc(match func(rune) bool) { for match(l.peek()) { l.next() } }
[ "func", "(", "l", "*", "lexer", ")", "acceptFunc", "(", "match", "func", "(", "rune", ")", "bool", ")", "{", "for", "match", "(", "l", ".", "peek", "(", ")", ")", "{", "l", ".", "next", "(", ")", "\n", "}", "\n", "}" ]
// acceptFunc accepts a run of characters based on a match function
[ "acceptFunc", "accepts", "a", "run", "of", "characters", "based", "on", "a", "match", "function" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L162-L166
7,683
cortesi/modd
conf/lex.go
maybeSpace
func (l *lexer) maybeSpace() rune { for { n := l.next() if any(n, whitespace) { l.acceptRun(whitespace) l.emit(itemSpace) } else { return n } } }
go
func (l *lexer) maybeSpace() rune { for { n := l.next() if any(n, whitespace) { l.acceptRun(whitespace) l.emit(itemSpace) } else { return n } } }
[ "func", "(", "l", "*", "lexer", ")", "maybeSpace", "(", ")", "rune", "{", "for", "{", "n", ":=", "l", ".", "next", "(", ")", "\n", "if", "any", "(", "n", ",", "whitespace", ")", "{", "l", ".", "acceptRun", "(", "whitespace", ")", "\n", "l", ".", "emit", "(", "itemSpace", ")", "\n", "}", "else", "{", "return", "n", "\n", "}", "\n", "}", "\n", "}" ]
// Eats and emits a run of whitespace, if any, and returns the next sigificant // rune
[ "Eats", "and", "emits", "a", "run", "of", "whitespace", "if", "any", "and", "returns", "the", "next", "sigificant", "rune" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L170-L180
7,684
cortesi/modd
conf/lex.go
eatSpaceAndComments
func (l *lexer) eatSpaceAndComments() rune { for { n := l.next() if n == '#' { l.acceptLine(false) l.emit(itemComment) } else if any(n, whitespace) { l.acceptRun(whitespace) l.emit(itemSpace) } else { return n } } }
go
func (l *lexer) eatSpaceAndComments() rune { for { n := l.next() if n == '#' { l.acceptLine(false) l.emit(itemComment) } else if any(n, whitespace) { l.acceptRun(whitespace) l.emit(itemSpace) } else { return n } } }
[ "func", "(", "l", "*", "lexer", ")", "eatSpaceAndComments", "(", ")", "rune", "{", "for", "{", "n", ":=", "l", ".", "next", "(", ")", "\n", "if", "n", "==", "'#'", "{", "l", ".", "acceptLine", "(", "false", ")", "\n", "l", ".", "emit", "(", "itemComment", ")", "\n", "}", "else", "if", "any", "(", "n", ",", "whitespace", ")", "{", "l", ".", "acceptRun", "(", "whitespace", ")", "\n", "l", ".", "emit", "(", "itemSpace", ")", "\n", "}", "else", "{", "return", "n", "\n", "}", "\n", "}", "\n", "}" ]
// Eats and emits a run of whitespace and comments, and returns the next // sigificant rune
[ "Eats", "and", "emits", "a", "run", "of", "whitespace", "and", "comments", "and", "returns", "the", "next", "sigificant", "rune" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L184-L197
7,685
cortesi/modd
conf/lex.go
nextSignificantItem
func (l *lexer) nextSignificantItem() item { for { item := l.nextItem() switch item.typ { case itemSpace: continue case itemComment: continue default: return item } } }
go
func (l *lexer) nextSignificantItem() item { for { item := l.nextItem() switch item.typ { case itemSpace: continue case itemComment: continue default: return item } } }
[ "func", "(", "l", "*", "lexer", ")", "nextSignificantItem", "(", ")", "item", "{", "for", "{", "item", ":=", "l", ".", "nextItem", "(", ")", "\n", "switch", "item", ".", "typ", "{", "case", "itemSpace", ":", "continue", "\n", "case", "itemComment", ":", "continue", "\n", "default", ":", "return", "item", "\n", "}", "\n", "}", "\n", "}" ]
// nextSignificantItem returns the next significant item from the input, // ignoring comments and spaces.
[ "nextSignificantItem", "returns", "the", "next", "significant", "item", "from", "the", "input", "ignoring", "comments", "and", "spaces", "." ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L222-L234
7,686
cortesi/modd
conf/lex.go
acceptLine
func (l *lexer) acceptLine(permitEscaping bool) { escaped := false for { if !permitEscaping { escaped = false } nxt := l.peek() switch nxt { case '\n': l.next() if !escaped { return } case eof: return case '\\': escaped = true l.next() continue default: l.next() } escaped = false } }
go
func (l *lexer) acceptLine(permitEscaping bool) { escaped := false for { if !permitEscaping { escaped = false } nxt := l.peek() switch nxt { case '\n': l.next() if !escaped { return } case eof: return case '\\': escaped = true l.next() continue default: l.next() } escaped = false } }
[ "func", "(", "l", "*", "lexer", ")", "acceptLine", "(", "permitEscaping", "bool", ")", "{", "escaped", ":=", "false", "\n", "for", "{", "if", "!", "permitEscaping", "{", "escaped", "=", "false", "\n", "}", "\n", "nxt", ":=", "l", ".", "peek", "(", ")", "\n", "switch", "nxt", "{", "case", "'\\n'", ":", "l", ".", "next", "(", ")", "\n", "if", "!", "escaped", "{", "return", "\n", "}", "\n", "case", "eof", ":", "return", "\n", "case", "'\\\\'", ":", "escaped", "=", "true", "\n", "l", ".", "next", "(", ")", "\n", "continue", "\n", "default", ":", "l", ".", "next", "(", ")", "\n", "}", "\n", "escaped", "=", "false", "\n", "}", "\n", "}" ]
// acceptLine accepts the remainder of a line
[ "acceptLine", "accepts", "the", "remainder", "of", "a", "line" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L256-L280
7,687
cortesi/modd
conf/lex.go
acceptBareString
func (l *lexer) acceptBareString() { l.acceptFunc( func(r rune) bool { return !any(r, bareStringDisallowed) && r != eof }, ) }
go
func (l *lexer) acceptBareString() { l.acceptFunc( func(r rune) bool { return !any(r, bareStringDisallowed) && r != eof }, ) }
[ "func", "(", "l", "*", "lexer", ")", "acceptBareString", "(", ")", "{", "l", ".", "acceptFunc", "(", "func", "(", "r", "rune", ")", "bool", "{", "return", "!", "any", "(", "r", ",", "bareStringDisallowed", ")", "&&", "r", "!=", "eof", "\n", "}", ",", ")", "\n", "}" ]
// acceptBareString accepts a bare, unquoted string
[ "acceptBareString", "accepts", "a", "bare", "unquoted", "string" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L283-L289
7,688
cortesi/modd
conf/lex.go
acceptWord
func (l *lexer) acceptWord() { l.acceptFunc( func(r rune) bool { return any(r, wordRunes) }, ) }
go
func (l *lexer) acceptWord() { l.acceptFunc( func(r rune) bool { return any(r, wordRunes) }, ) }
[ "func", "(", "l", "*", "lexer", ")", "acceptWord", "(", ")", "{", "l", ".", "acceptFunc", "(", "func", "(", "r", "rune", ")", "bool", "{", "return", "any", "(", "r", ",", "wordRunes", ")", "\n", "}", ",", ")", "\n", "}" ]
// acceptWord accepts a lowercase word
[ "acceptWord", "accepts", "a", "lowercase", "word" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L292-L298
7,689
cortesi/modd
conf/lex.go
acceptQuotedString
func (l *lexer) acceptQuotedString(quote rune) error { Loop: for { switch l.next() { case '\\': if r := l.next(); r != eof { break } fallthrough case eof: return fmt.Errorf("unterminated quoted string") case quote: break Loop } } return nil }
go
func (l *lexer) acceptQuotedString(quote rune) error { Loop: for { switch l.next() { case '\\': if r := l.next(); r != eof { break } fallthrough case eof: return fmt.Errorf("unterminated quoted string") case quote: break Loop } } return nil }
[ "func", "(", "l", "*", "lexer", ")", "acceptQuotedString", "(", "quote", "rune", ")", "error", "{", "Loop", ":", "for", "{", "switch", "l", ".", "next", "(", ")", "{", "case", "'\\\\'", ":", "if", "r", ":=", "l", ".", "next", "(", ")", ";", "r", "!=", "eof", "{", "break", "\n", "}", "\n", "fallthrough", "\n", "case", "eof", ":", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ")", "\n", "case", "quote", ":", "break", "Loop", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// acceptQuotedString accepts a quoted string
[ "acceptQuotedString", "accepts", "a", "quoted", "string" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L301-L317
7,690
cortesi/modd
conf/lex.go
lexPatterns
func lexPatterns(l *lexer) stateFn { for { n := l.eatSpaceAndComments() if n == eof { l.emit(itemEOF) return nil } else if n == '!' { pk := l.next() if any(pk, quotes) { err := l.acceptQuotedString(pk) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) } else if !any(pk, bareStringDisallowed) { l.acceptBareString() l.emit(itemBareString) } else { l.errorf("! must be followed by a string") return nil } } else if any(n, quotes) { err := l.acceptQuotedString(n) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) } else if !any(n, bareStringDisallowed) { l.acceptBareString() l.emit(itemBareString) } else { l.backup() return lexBlockStart } } }
go
func lexPatterns(l *lexer) stateFn { for { n := l.eatSpaceAndComments() if n == eof { l.emit(itemEOF) return nil } else if n == '!' { pk := l.next() if any(pk, quotes) { err := l.acceptQuotedString(pk) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) } else if !any(pk, bareStringDisallowed) { l.acceptBareString() l.emit(itemBareString) } else { l.errorf("! must be followed by a string") return nil } } else if any(n, quotes) { err := l.acceptQuotedString(n) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) } else if !any(n, bareStringDisallowed) { l.acceptBareString() l.emit(itemBareString) } else { l.backup() return lexBlockStart } } }
[ "func", "lexPatterns", "(", "l", "*", "lexer", ")", "stateFn", "{", "for", "{", "n", ":=", "l", ".", "eatSpaceAndComments", "(", ")", "\n", "if", "n", "==", "eof", "{", "l", ".", "emit", "(", "itemEOF", ")", "\n", "return", "nil", "\n", "}", "else", "if", "n", "==", "'!'", "{", "pk", ":=", "l", ".", "next", "(", ")", "\n", "if", "any", "(", "pk", ",", "quotes", ")", "{", "err", ":=", "l", ".", "acceptQuotedString", "(", "pk", ")", "\n", "if", "err", "!=", "nil", "{", "l", ".", "errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "l", ".", "emit", "(", "itemQuotedString", ")", "\n", "}", "else", "if", "!", "any", "(", "pk", ",", "bareStringDisallowed", ")", "{", "l", ".", "acceptBareString", "(", ")", "\n", "l", ".", "emit", "(", "itemBareString", ")", "\n", "}", "else", "{", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "else", "if", "any", "(", "n", ",", "quotes", ")", "{", "err", ":=", "l", ".", "acceptQuotedString", "(", "n", ")", "\n", "if", "err", "!=", "nil", "{", "l", ".", "errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "l", ".", "emit", "(", "itemQuotedString", ")", "\n", "}", "else", "if", "!", "any", "(", "n", ",", "bareStringDisallowed", ")", "{", "l", ".", "acceptBareString", "(", ")", "\n", "l", ".", "emit", "(", "itemBareString", ")", "\n", "}", "else", "{", "l", ".", "backup", "(", ")", "\n", "return", "lexBlockStart", "\n", "}", "\n", "}", "\n", "}" ]
// stateFns // lexPatterns reads and emits consecutive file patterns. Strings can be // interspersed with comments.
[ "stateFns", "lexPatterns", "reads", "and", "emits", "consecutive", "file", "patterns", ".", "Strings", "can", "be", "interspersed", "with", "comments", "." ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L327-L364
7,691
cortesi/modd
conf/lex.go
lexVariables
func lexVariables(l *lexer) stateFn { for { n := l.eatSpaceAndComments() if n == '@' { l.acceptWord() l.emit(itemVarName) n = l.maybeSpace() if n == '=' { l.emit(itemEquals) } n = l.maybeSpace() if n == eof { l.errorf("unterminated variable assignment") return nil } else if any(n, quotes) { err := l.acceptQuotedString(n) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) } else if !any(n, bareStringDisallowed) { l.acceptLine(true) l.emit(itemBareString) } else { l.errorf("= must be followed by a string") return nil } } else { l.backup() return lexPatterns } } }
go
func lexVariables(l *lexer) stateFn { for { n := l.eatSpaceAndComments() if n == '@' { l.acceptWord() l.emit(itemVarName) n = l.maybeSpace() if n == '=' { l.emit(itemEquals) } n = l.maybeSpace() if n == eof { l.errorf("unterminated variable assignment") return nil } else if any(n, quotes) { err := l.acceptQuotedString(n) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) } else if !any(n, bareStringDisallowed) { l.acceptLine(true) l.emit(itemBareString) } else { l.errorf("= must be followed by a string") return nil } } else { l.backup() return lexPatterns } } }
[ "func", "lexVariables", "(", "l", "*", "lexer", ")", "stateFn", "{", "for", "{", "n", ":=", "l", ".", "eatSpaceAndComments", "(", ")", "\n", "if", "n", "==", "'@'", "{", "l", ".", "acceptWord", "(", ")", "\n", "l", ".", "emit", "(", "itemVarName", ")", "\n", "n", "=", "l", ".", "maybeSpace", "(", ")", "\n", "if", "n", "==", "'='", "{", "l", ".", "emit", "(", "itemEquals", ")", "\n", "}", "\n", "n", "=", "l", ".", "maybeSpace", "(", ")", "\n", "if", "n", "==", "eof", "{", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "else", "if", "any", "(", "n", ",", "quotes", ")", "{", "err", ":=", "l", ".", "acceptQuotedString", "(", "n", ")", "\n", "if", "err", "!=", "nil", "{", "l", ".", "errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "l", ".", "emit", "(", "itemQuotedString", ")", "\n", "}", "else", "if", "!", "any", "(", "n", ",", "bareStringDisallowed", ")", "{", "l", ".", "acceptLine", "(", "true", ")", "\n", "l", ".", "emit", "(", "itemBareString", ")", "\n", "}", "else", "{", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "else", "{", "l", ".", "backup", "(", ")", "\n", "return", "lexPatterns", "\n", "}", "\n", "}", "\n", "}" ]
// lexVariables reads a block of variable declarations.
[ "lexVariables", "reads", "a", "block", "of", "variable", "declarations", "." ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L367-L400
7,692
cortesi/modd
conf/lex.go
lexOptions
func lexOptions(l *lexer) stateFn { for { n := l.next() if any(n, spaces) { l.acceptRun(spaces) l.emit(itemSpace) } else if n == ':' { l.emit(itemColon) return lexCommand } else if n == '+' { l.acceptWord() l.emit(itemBareString) } else { l.errorf("invalid command option") return nil } } }
go
func lexOptions(l *lexer) stateFn { for { n := l.next() if any(n, spaces) { l.acceptRun(spaces) l.emit(itemSpace) } else if n == ':' { l.emit(itemColon) return lexCommand } else if n == '+' { l.acceptWord() l.emit(itemBareString) } else { l.errorf("invalid command option") return nil } } }
[ "func", "lexOptions", "(", "l", "*", "lexer", ")", "stateFn", "{", "for", "{", "n", ":=", "l", ".", "next", "(", ")", "\n", "if", "any", "(", "n", ",", "spaces", ")", "{", "l", ".", "acceptRun", "(", "spaces", ")", "\n", "l", ".", "emit", "(", "itemSpace", ")", "\n", "}", "else", "if", "n", "==", "':'", "{", "l", ".", "emit", "(", "itemColon", ")", "\n", "return", "lexCommand", "\n", "}", "else", "if", "n", "==", "'+'", "{", "l", ".", "acceptWord", "(", ")", "\n", "l", ".", "emit", "(", "itemBareString", ")", "\n", "}", "else", "{", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "\n", "}", "\n", "}" ]
// lexOptions lexes the options that precede a command specification.
[ "lexOptions", "lexes", "the", "options", "that", "precede", "a", "command", "specification", "." ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L446-L463
7,693
cortesi/modd
conf/lex.go
lexCommand
func lexCommand(l *lexer) stateFn { for { n := l.next() if n == '\n' { l.errorf("empty command specification") return nil } else if any(n, quotes) { err := l.acceptQuotedString(n) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) return lexInside } else if any(n, spaces) { l.acceptRun(spaces) l.emit(itemSpace) } else { l.acceptLine(true) l.emit(itemBareString) return lexInside } } }
go
func lexCommand(l *lexer) stateFn { for { n := l.next() if n == '\n' { l.errorf("empty command specification") return nil } else if any(n, quotes) { err := l.acceptQuotedString(n) if err != nil { l.errorf("%s", err) return nil } l.emit(itemQuotedString) return lexInside } else if any(n, spaces) { l.acceptRun(spaces) l.emit(itemSpace) } else { l.acceptLine(true) l.emit(itemBareString) return lexInside } } }
[ "func", "lexCommand", "(", "l", "*", "lexer", ")", "stateFn", "{", "for", "{", "n", ":=", "l", ".", "next", "(", ")", "\n", "if", "n", "==", "'\\n'", "{", "l", ".", "errorf", "(", "\"", "\"", ")", "\n", "return", "nil", "\n", "}", "else", "if", "any", "(", "n", ",", "quotes", ")", "{", "err", ":=", "l", ".", "acceptQuotedString", "(", "n", ")", "\n", "if", "err", "!=", "nil", "{", "l", ".", "errorf", "(", "\"", "\"", ",", "err", ")", "\n", "return", "nil", "\n", "}", "\n", "l", ".", "emit", "(", "itemQuotedString", ")", "\n", "return", "lexInside", "\n", "}", "else", "if", "any", "(", "n", ",", "spaces", ")", "{", "l", ".", "acceptRun", "(", "spaces", ")", "\n", "l", ".", "emit", "(", "itemSpace", ")", "\n", "}", "else", "{", "l", ".", "acceptLine", "(", "true", ")", "\n", "l", ".", "emit", "(", "itemBareString", ")", "\n", "return", "lexInside", "\n", "}", "\n", "}", "\n", "}" ]
// lexCommand lexes a single command. Commands can either be unquoted and on a // single line, or quoted and span multiple lines.
[ "lexCommand", "lexes", "a", "single", "command", ".", "Commands", "can", "either", "be", "unquoted", "and", "on", "a", "single", "line", "or", "quoted", "and", "span", "multiple", "lines", "." ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/conf/lex.go#L467-L490
7,694
cortesi/modd
modd.go
NewModRunner
func NewModRunner(confPath string, log termlog.TermLog, notifiers []notify.Notifier, confreload bool) (*ModRunner, error) { mr := &ModRunner{ Log: log, ConfPath: confPath, ConfReload: confreload, Notifiers: notifiers, } err := mr.ReadConfig() if err != nil { return nil, err } return mr, nil }
go
func NewModRunner(confPath string, log termlog.TermLog, notifiers []notify.Notifier, confreload bool) (*ModRunner, error) { mr := &ModRunner{ Log: log, ConfPath: confPath, ConfReload: confreload, Notifiers: notifiers, } err := mr.ReadConfig() if err != nil { return nil, err } return mr, nil }
[ "func", "NewModRunner", "(", "confPath", "string", ",", "log", "termlog", ".", "TermLog", ",", "notifiers", "[", "]", "notify", ".", "Notifier", ",", "confreload", "bool", ")", "(", "*", "ModRunner", ",", "error", ")", "{", "mr", ":=", "&", "ModRunner", "{", "Log", ":", "log", ",", "ConfPath", ":", "confPath", ",", "ConfReload", ":", "confreload", ",", "Notifiers", ":", "notifiers", ",", "}", "\n", "err", ":=", "mr", ".", "ReadConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "mr", ",", "nil", "\n", "}" ]
// NewModRunner constructs a new ModRunner
[ "NewModRunner", "constructs", "a", "new", "ModRunner" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/modd.go#L64-L76
7,695
cortesi/modd
modd.go
ReadConfig
func (mr *ModRunner) ReadConfig() error { ret, err := ioutil.ReadFile(mr.ConfPath) if err != nil { return fmt.Errorf("Error reading config file %s: %s", mr.ConfPath, err) } newcnf, err := conf.Parse(mr.ConfPath, string(ret)) if err != nil { return fmt.Errorf("Error reading config file %s: %s", mr.ConfPath, err) } if _, err := shell.GetShellName(newcnf.GetVariables()[shellVarName]); err != nil { return err } newcnf.CommonExcludes(CommonExcludes) mr.Config = newcnf return nil }
go
func (mr *ModRunner) ReadConfig() error { ret, err := ioutil.ReadFile(mr.ConfPath) if err != nil { return fmt.Errorf("Error reading config file %s: %s", mr.ConfPath, err) } newcnf, err := conf.Parse(mr.ConfPath, string(ret)) if err != nil { return fmt.Errorf("Error reading config file %s: %s", mr.ConfPath, err) } if _, err := shell.GetShellName(newcnf.GetVariables()[shellVarName]); err != nil { return err } newcnf.CommonExcludes(CommonExcludes) mr.Config = newcnf return nil }
[ "func", "(", "mr", "*", "ModRunner", ")", "ReadConfig", "(", ")", "error", "{", "ret", ",", "err", ":=", "ioutil", ".", "ReadFile", "(", "mr", ".", "ConfPath", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "mr", ".", "ConfPath", ",", "err", ")", "\n", "}", "\n", "newcnf", ",", "err", ":=", "conf", ".", "Parse", "(", "mr", ".", "ConfPath", ",", "string", "(", "ret", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "mr", ".", "ConfPath", ",", "err", ")", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "shell", ".", "GetShellName", "(", "newcnf", ".", "GetVariables", "(", ")", "[", "shellVarName", "]", ")", ";", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n\n", "newcnf", ".", "CommonExcludes", "(", "CommonExcludes", ")", "\n", "mr", ".", "Config", "=", "newcnf", "\n", "return", "nil", "\n", "}" ]
// ReadConfig parses the configuration file in ConfPath
[ "ReadConfig", "parses", "the", "configuration", "file", "in", "ConfPath" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/modd.go#L79-L96
7,696
cortesi/modd
modd.go
PrepOnly
func (mr *ModRunner) PrepOnly(initial bool) error { for _, b := range mr.Config.Blocks { err := RunPreps(b, mr.Config.GetVariables(), nil, mr.Log, mr.Notifiers, initial) if err != nil { return err } } return nil }
go
func (mr *ModRunner) PrepOnly(initial bool) error { for _, b := range mr.Config.Blocks { err := RunPreps(b, mr.Config.GetVariables(), nil, mr.Log, mr.Notifiers, initial) if err != nil { return err } } return nil }
[ "func", "(", "mr", "*", "ModRunner", ")", "PrepOnly", "(", "initial", "bool", ")", "error", "{", "for", "_", ",", "b", ":=", "range", "mr", ".", "Config", ".", "Blocks", "{", "err", ":=", "RunPreps", "(", "b", ",", "mr", ".", "Config", ".", "GetVariables", "(", ")", ",", "nil", ",", "mr", ".", "Log", ",", "mr", ".", "Notifiers", ",", "initial", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// PrepOnly runs all prep functions and exits
[ "PrepOnly", "runs", "all", "prep", "functions", "and", "exits" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/modd.go#L99-L107
7,697
cortesi/modd
modd.go
runOnChan
func (mr *ModRunner) runOnChan(modchan chan *moddwatch.Mod, readyCallback func()) error { dworld, err := NewDaemonWorld(mr.Config, mr.Log) if err != nil { return err } defer dworld.Shutdown(os.Kill) c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill) defer signal.Reset(os.Interrupt, os.Kill) go func() { dworld.Shutdown(<-c) os.Exit(0) }() ipatts := mr.Config.IncludePatterns() if mr.ConfReload { ipatts = append(ipatts, filepath.Dir(mr.ConfPath)) } currentDir, err := os.Getwd() if err != nil { return err } // FIXME: This takes a long time. We could start it in parallel with the // first process run in a goroutine watcher, err := moddwatch.Watch(currentDir, ipatts, []string{}, lullTime, modchan) if err != nil { return fmt.Errorf("Error watching: %s", err) } defer watcher.Stop() mr.trigger(currentDir, nil, dworld) go readyCallback() for mod := range modchan { if mod == nil { break } if mr.ConfReload && mod.Has(mr.ConfPath) { mr.Log.Notice("Reloading config %s", mr.ConfPath) err := mr.ReadConfig() if err != nil { mr.Log.Warn("%s", err) continue } else { return nil } } mr.Log.SayAs("debug", "Delta: \n%s", mod.String()) mr.trigger(currentDir, mod, dworld) } return nil }
go
func (mr *ModRunner) runOnChan(modchan chan *moddwatch.Mod, readyCallback func()) error { dworld, err := NewDaemonWorld(mr.Config, mr.Log) if err != nil { return err } defer dworld.Shutdown(os.Kill) c := make(chan os.Signal, 1) signal.Notify(c, os.Interrupt, os.Kill) defer signal.Reset(os.Interrupt, os.Kill) go func() { dworld.Shutdown(<-c) os.Exit(0) }() ipatts := mr.Config.IncludePatterns() if mr.ConfReload { ipatts = append(ipatts, filepath.Dir(mr.ConfPath)) } currentDir, err := os.Getwd() if err != nil { return err } // FIXME: This takes a long time. We could start it in parallel with the // first process run in a goroutine watcher, err := moddwatch.Watch(currentDir, ipatts, []string{}, lullTime, modchan) if err != nil { return fmt.Errorf("Error watching: %s", err) } defer watcher.Stop() mr.trigger(currentDir, nil, dworld) go readyCallback() for mod := range modchan { if mod == nil { break } if mr.ConfReload && mod.Has(mr.ConfPath) { mr.Log.Notice("Reloading config %s", mr.ConfPath) err := mr.ReadConfig() if err != nil { mr.Log.Warn("%s", err) continue } else { return nil } } mr.Log.SayAs("debug", "Delta: \n%s", mod.String()) mr.trigger(currentDir, mod, dworld) } return nil }
[ "func", "(", "mr", "*", "ModRunner", ")", "runOnChan", "(", "modchan", "chan", "*", "moddwatch", ".", "Mod", ",", "readyCallback", "func", "(", ")", ")", "error", "{", "dworld", ",", "err", ":=", "NewDaemonWorld", "(", "mr", ".", "Config", ",", "mr", ".", "Log", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "defer", "dworld", ".", "Shutdown", "(", "os", ".", "Kill", ")", "\n\n", "c", ":=", "make", "(", "chan", "os", ".", "Signal", ",", "1", ")", "\n", "signal", ".", "Notify", "(", "c", ",", "os", ".", "Interrupt", ",", "os", ".", "Kill", ")", "\n", "defer", "signal", ".", "Reset", "(", "os", ".", "Interrupt", ",", "os", ".", "Kill", ")", "\n", "go", "func", "(", ")", "{", "dworld", ".", "Shutdown", "(", "<-", "c", ")", "\n", "os", ".", "Exit", "(", "0", ")", "\n", "}", "(", ")", "\n\n", "ipatts", ":=", "mr", ".", "Config", ".", "IncludePatterns", "(", ")", "\n", "if", "mr", ".", "ConfReload", "{", "ipatts", "=", "append", "(", "ipatts", ",", "filepath", ".", "Dir", "(", "mr", ".", "ConfPath", ")", ")", "\n", "}", "\n\n", "currentDir", ",", "err", ":=", "os", ".", "Getwd", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "// FIXME: This takes a long time. We could start it in parallel with the", "// first process run in a goroutine", "watcher", ",", "err", ":=", "moddwatch", ".", "Watch", "(", "currentDir", ",", "ipatts", ",", "[", "]", "string", "{", "}", ",", "lullTime", ",", "modchan", ")", "\n\n", "if", "err", "!=", "nil", "{", "return", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "defer", "watcher", ".", "Stop", "(", ")", "\n\n", "mr", ".", "trigger", "(", "currentDir", ",", "nil", ",", "dworld", ")", "\n", "go", "readyCallback", "(", ")", "\n", "for", "mod", ":=", "range", "modchan", "{", "if", "mod", "==", "nil", "{", "break", "\n", "}", "\n", "if", "mr", ".", "ConfReload", "&&", "mod", ".", "Has", "(", "mr", ".", "ConfPath", ")", "{", "mr", ".", "Log", ".", "Notice", "(", "\"", "\"", ",", "mr", ".", "ConfPath", ")", "\n", "err", ":=", "mr", ".", "ReadConfig", "(", ")", "\n", "if", "err", "!=", "nil", "{", "mr", ".", "Log", ".", "Warn", "(", "\"", "\"", ",", "err", ")", "\n", "continue", "\n", "}", "else", "{", "return", "nil", "\n", "}", "\n", "}", "\n", "mr", ".", "Log", ".", "SayAs", "(", "\"", "\"", ",", "\"", "\\n", "\"", ",", "mod", ".", "String", "(", ")", ")", "\n", "mr", ".", "trigger", "(", "currentDir", ",", "mod", ",", "dworld", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// Gives control of chan to caller
[ "Gives", "control", "of", "chan", "to", "caller" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/modd.go#L167-L220
7,698
cortesi/modd
modd.go
Run
func (mr *ModRunner) Run() error { for { modchan := make(chan *moddwatch.Mod, 1024) err := mr.runOnChan(modchan, func() {}) if err != nil { return err } } }
go
func (mr *ModRunner) Run() error { for { modchan := make(chan *moddwatch.Mod, 1024) err := mr.runOnChan(modchan, func() {}) if err != nil { return err } } }
[ "func", "(", "mr", "*", "ModRunner", ")", "Run", "(", ")", "error", "{", "for", "{", "modchan", ":=", "make", "(", "chan", "*", "moddwatch", ".", "Mod", ",", "1024", ")", "\n", "err", ":=", "mr", ".", "runOnChan", "(", "modchan", ",", "func", "(", ")", "{", "}", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "}", "\n", "}" ]
// Run is the top-level runner for modd
[ "Run", "is", "the", "top", "-", "level", "runner", "for", "modd" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/modd.go#L223-L231
7,699
cortesi/modd
daemon.go
Restart
func (d *daemon) Restart() { d.Lock() defer d.Unlock() if d.ex == nil { ex, err := shell.NewExecutor(d.shell, d.conf.Command, d.indir) if err != nil { d.log.Shout("Could not create executor: %s", err) } d.ex = ex go d.Run() } else { d.log.Notice(">> sending signal %s", d.conf.RestartSignal) err := d.ex.Signal(d.conf.RestartSignal) if err != nil { d.log.Warn( "failed to send %s signal to %s: %v", d.conf.RestartSignal, d.conf.Command, err, ) } } }
go
func (d *daemon) Restart() { d.Lock() defer d.Unlock() if d.ex == nil { ex, err := shell.NewExecutor(d.shell, d.conf.Command, d.indir) if err != nil { d.log.Shout("Could not create executor: %s", err) } d.ex = ex go d.Run() } else { d.log.Notice(">> sending signal %s", d.conf.RestartSignal) err := d.ex.Signal(d.conf.RestartSignal) if err != nil { d.log.Warn( "failed to send %s signal to %s: %v", d.conf.RestartSignal, d.conf.Command, err, ) } } }
[ "func", "(", "d", "*", "daemon", ")", "Restart", "(", ")", "{", "d", ".", "Lock", "(", ")", "\n", "defer", "d", ".", "Unlock", "(", ")", "\n", "if", "d", ".", "ex", "==", "nil", "{", "ex", ",", "err", ":=", "shell", ".", "NewExecutor", "(", "d", ".", "shell", ",", "d", ".", "conf", ".", "Command", ",", "d", ".", "indir", ")", "\n", "if", "err", "!=", "nil", "{", "d", ".", "log", ".", "Shout", "(", "\"", "\"", ",", "err", ")", "\n", "}", "\n", "d", ".", "ex", "=", "ex", "\n", "go", "d", ".", "Run", "(", ")", "\n", "}", "else", "{", "d", ".", "log", ".", "Notice", "(", "\"", "\"", ",", "d", ".", "conf", ".", "RestartSignal", ")", "\n", "err", ":=", "d", ".", "ex", ".", "Signal", "(", "d", ".", "conf", ".", "RestartSignal", ")", "\n", "if", "err", "!=", "nil", "{", "d", ".", "log", ".", "Warn", "(", "\"", "\"", ",", "d", ".", "conf", ".", "RestartSignal", ",", "d", ".", "conf", ".", "Command", ",", "err", ",", ")", "\n", "}", "\n", "}", "\n", "}" ]
// Restart the daemon, or start it if it's not yet running
[ "Restart", "the", "daemon", "or", "start", "it", "if", "it", "s", "not", "yet", "running" ]
e30792b1408111a0b23229f18d207a21af1e3bed
https://github.com/cortesi/modd/blob/e30792b1408111a0b23229f18d207a21af1e3bed/daemon.go#L76-L95