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 list | docstring stringlengths 6 2.61k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 85 252 |
|---|---|---|---|---|---|---|---|---|---|---|---|
149,800 | couchbaselabs/cellar | cellar.go | Update | func (c *Cellar) Update(fn func(*Tx) error) error {
t, err := c.Begin(true)
if err != nil {
return fmt.Errorf("cellar Update Begin: %v", err)
}
// Make sure the transaction rolls back in the event of a panic.
defer func() {
if t.cellar != nil {
_ = t.rollback()
}
}()
// Mark as a managed tx so that th... | go | func (c *Cellar) Update(fn func(*Tx) error) error {
t, err := c.Begin(true)
if err != nil {
return fmt.Errorf("cellar Update Begin: %v", err)
}
// Make sure the transaction rolls back in the event of a panic.
defer func() {
if t.cellar != nil {
_ = t.rollback()
}
}()
// Mark as a managed tx so that th... | [
"func",
"(",
"c",
"*",
"Cellar",
")",
"Update",
"(",
"fn",
"func",
"(",
"*",
"Tx",
")",
"error",
")",
"error",
"{",
"t",
",",
"err",
":=",
"c",
".",
"Begin",
"(",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf... | // Update starts a managed transaction for wriring
// the provided function is executed within the transaction
// to abort the transaction the function should return an error
// to commit the transaction the function should return nil | [
"Update",
"starts",
"a",
"managed",
"transaction",
"for",
"wriring",
"the",
"provided",
"function",
"is",
"executed",
"within",
"the",
"transaction",
"to",
"abort",
"the",
"transaction",
"the",
"function",
"should",
"return",
"an",
"error",
"to",
"commit",
"the"... | b5534bba869879532beaf2da5845bdb8cb0f00f4 | https://github.com/couchbaselabs/cellar/blob/b5534bba869879532beaf2da5845bdb8cb0f00f4/cellar.go#L284-L313 |
149,801 | couchbaselabs/cellar | cellar.go | View | func (c *Cellar) View(fn func(*Tx) error) error {
t, err := c.Begin(false)
if err != nil {
return err
}
// Make sure the transaction rolls back in the event of a panic.
defer func() {
if t.cellar != nil {
_ = t.rollback()
}
}()
// Mark as a managed tx so that the inner function cannot manually rollbac... | go | func (c *Cellar) View(fn func(*Tx) error) error {
t, err := c.Begin(false)
if err != nil {
return err
}
// Make sure the transaction rolls back in the event of a panic.
defer func() {
if t.cellar != nil {
_ = t.rollback()
}
}()
// Mark as a managed tx so that the inner function cannot manually rollbac... | [
"func",
"(",
"c",
"*",
"Cellar",
")",
"View",
"(",
"fn",
"func",
"(",
"*",
"Tx",
")",
"error",
")",
"error",
"{",
"t",
",",
"err",
":=",
"c",
".",
"Begin",
"(",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
... | // View starts a managed transaction for reading
// the provided function is executed within the transaction | [
"View",
"starts",
"a",
"managed",
"transaction",
"for",
"reading",
"the",
"provided",
"function",
"is",
"executed",
"within",
"the",
"transaction"
] | b5534bba869879532beaf2da5845bdb8cb0f00f4 | https://github.com/couchbaselabs/cellar/blob/b5534bba869879532beaf2da5845bdb8cb0f00f4/cellar.go#L317-L346 |
149,802 | couchbaselabs/cellar | cellar.go | ForceMerge | func (c *Cellar) ForceMerge() {
root := c.getRoot("cellar forceMerge")
c.mergeManager.ForceMerge(root)
} | go | func (c *Cellar) ForceMerge() {
root := c.getRoot("cellar forceMerge")
c.mergeManager.ForceMerge(root)
} | [
"func",
"(",
"c",
"*",
"Cellar",
")",
"ForceMerge",
"(",
")",
"{",
"root",
":=",
"c",
".",
"getRoot",
"(",
"\"",
"\"",
")",
"\n",
"c",
".",
"mergeManager",
".",
"ForceMerge",
"(",
"root",
")",
"\n",
"}"
] | // ForceMerge will force the cellar to perform a merge operations
// this function does not wait for the merge to finish | [
"ForceMerge",
"will",
"force",
"the",
"cellar",
"to",
"perform",
"a",
"merge",
"operations",
"this",
"function",
"does",
"not",
"wait",
"for",
"the",
"merge",
"to",
"finish"
] | b5534bba869879532beaf2da5845bdb8cb0f00f4 | https://github.com/couchbaselabs/cellar/blob/b5534bba869879532beaf2da5845bdb8cb0f00f4/cellar.go#L533-L536 |
149,803 | couchbaselabs/cellar | cellar.go | Stats | func (c *Cellar) Stats() *Stats {
rv := &Stats{}
rv.mergesCompleted = atomic.LoadUint64(&c.stats.mergesCompleted)
rv.segments = atomic.LoadUint64(&c.stats.segments)
return rv
} | go | func (c *Cellar) Stats() *Stats {
rv := &Stats{}
rv.mergesCompleted = atomic.LoadUint64(&c.stats.mergesCompleted)
rv.segments = atomic.LoadUint64(&c.stats.segments)
return rv
} | [
"func",
"(",
"c",
"*",
"Cellar",
")",
"Stats",
"(",
")",
"*",
"Stats",
"{",
"rv",
":=",
"&",
"Stats",
"{",
"}",
"\n",
"rv",
".",
"mergesCompleted",
"=",
"atomic",
".",
"LoadUint64",
"(",
"&",
"c",
".",
"stats",
".",
"mergesCompleted",
")",
"\n",
... | // Stats returns a structure containing interesting metrics about the cellar | [
"Stats",
"returns",
"a",
"structure",
"containing",
"interesting",
"metrics",
"about",
"the",
"cellar"
] | b5534bba869879532beaf2da5845bdb8cb0f00f4 | https://github.com/couchbaselabs/cellar/blob/b5534bba869879532beaf2da5845bdb8cb0f00f4/cellar.go#L539-L544 |
149,804 | couchbaselabs/cellar | cursor.go | Seek | func (c *Cursor) Seek(seek []byte) (key []byte, value []byte) {
for i, cursor := range c.mutationsCursors {
c.key[i], c.val[i] = cursor.Seek(seek)
}
c.updateCurr()
for c.checkCurrDeleted() {
c.next()
c.updateCurr()
}
return c.key[c.curr], c.val[c.curr]
} | go | func (c *Cursor) Seek(seek []byte) (key []byte, value []byte) {
for i, cursor := range c.mutationsCursors {
c.key[i], c.val[i] = cursor.Seek(seek)
}
c.updateCurr()
for c.checkCurrDeleted() {
c.next()
c.updateCurr()
}
return c.key[c.curr], c.val[c.curr]
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Seek",
"(",
"seek",
"[",
"]",
"byte",
")",
"(",
"key",
"[",
"]",
"byte",
",",
"value",
"[",
"]",
"byte",
")",
"{",
"for",
"i",
",",
"cursor",
":=",
"range",
"c",
".",
"mutationsCursors",
"{",
"c",
".",
"... | // Seek moves the cursor to the specified key | [
"Seek",
"moves",
"the",
"cursor",
"to",
"the",
"specified",
"key"
] | b5534bba869879532beaf2da5845bdb8cb0f00f4 | https://github.com/couchbaselabs/cellar/blob/b5534bba869879532beaf2da5845bdb8cb0f00f4/cursor.go#L55-L65 |
149,805 | couchbaselabs/cellar | cursor.go | Next | func (c *Cursor) Next() (key []byte, value []byte) {
c.next()
c.updateCurr()
for c.checkCurrDeleted() {
c.next()
c.updateCurr()
}
// FIXME end case where nothing else?
return c.key[c.curr], c.val[c.curr]
} | go | func (c *Cursor) Next() (key []byte, value []byte) {
c.next()
c.updateCurr()
for c.checkCurrDeleted() {
c.next()
c.updateCurr()
}
// FIXME end case where nothing else?
return c.key[c.curr], c.val[c.curr]
} | [
"func",
"(",
"c",
"*",
"Cursor",
")",
"Next",
"(",
")",
"(",
"key",
"[",
"]",
"byte",
",",
"value",
"[",
"]",
"byte",
")",
"{",
"c",
".",
"next",
"(",
")",
"\n",
"c",
".",
"updateCurr",
"(",
")",
"\n",
"for",
"c",
".",
"checkCurrDeleted",
"("... | // Next moves the cursor to the next key | [
"Next",
"moves",
"the",
"cursor",
"to",
"the",
"next",
"key"
] | b5534bba869879532beaf2da5845bdb8cb0f00f4 | https://github.com/couchbaselabs/cellar/blob/b5534bba869879532beaf2da5845bdb8cb0f00f4/cursor.go#L79-L88 |
149,806 | uluyol/hdrhist | hist.go | Clone | func (h *Hist) Clone() *Hist {
var h2 Hist
h2 = *h
c := make([]int64, len(h2.b.counts))
copy(c, h2.b.counts)
h2.b.counts = c
return &h2
} | go | func (h *Hist) Clone() *Hist {
var h2 Hist
h2 = *h
c := make([]int64, len(h2.b.counts))
copy(c, h2.b.counts)
h2.b.counts = c
return &h2
} | [
"func",
"(",
"h",
"*",
"Hist",
")",
"Clone",
"(",
")",
"*",
"Hist",
"{",
"var",
"h2",
"Hist",
"\n",
"h2",
"=",
"*",
"h",
"\n",
"c",
":=",
"make",
"(",
"[",
"]",
"int64",
",",
"len",
"(",
"h2",
".",
"b",
".",
"counts",
")",
")",
"\n",
"cop... | // Clone returns a deep copy of the histogram.
// This is useful when combining or taking
// differences of histograms. | [
"Clone",
"returns",
"a",
"deep",
"copy",
"of",
"the",
"histogram",
".",
"This",
"is",
"useful",
"when",
"combining",
"or",
"taking",
"differences",
"of",
"histograms",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/hist.go#L66-L73 |
149,807 | uluyol/hdrhist | hist.go | New | func New(sigfigs int32) *Hist {
return WithConfig(Config{
LowestDiscernible: 1,
HighestTrackable: 2,
SigFigs: sigfigs,
AutoResize: true,
})
} | go | func New(sigfigs int32) *Hist {
return WithConfig(Config{
LowestDiscernible: 1,
HighestTrackable: 2,
SigFigs: sigfigs,
AutoResize: true,
})
} | [
"func",
"New",
"(",
"sigfigs",
"int32",
")",
"*",
"Hist",
"{",
"return",
"WithConfig",
"(",
"Config",
"{",
"LowestDiscernible",
":",
"1",
",",
"HighestTrackable",
":",
"2",
",",
"SigFigs",
":",
"sigfigs",
",",
"AutoResize",
":",
"true",
",",
"}",
")",
... | // New creates a new Hist that auto-resizes
// and has a LowestDiscernible value of 1.
// Valid values for sigfigs are between 0 and 5. | [
"New",
"creates",
"a",
"new",
"Hist",
"that",
"auto",
"-",
"resizes",
"and",
"has",
"a",
"LowestDiscernible",
"value",
"of",
"1",
".",
"Valid",
"values",
"for",
"sigfigs",
"are",
"between",
"0",
"and",
"5",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/hist.go#L85-L92 |
149,808 | uluyol/hdrhist | hist.go | WithConfig | func WithConfig(cfg Config) *Hist {
var h Hist
h.Init(cfg)
return &h
} | go | func WithConfig(cfg Config) *Hist {
var h Hist
h.Init(cfg)
return &h
} | [
"func",
"WithConfig",
"(",
"cfg",
"Config",
")",
"*",
"Hist",
"{",
"var",
"h",
"Hist",
"\n",
"h",
".",
"Init",
"(",
"cfg",
")",
"\n",
"return",
"&",
"h",
"\n",
"}"
] | // WithConfig creates a new Hist with the provided Config. | [
"WithConfig",
"creates",
"a",
"new",
"Hist",
"with",
"the",
"provided",
"Config",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/hist.go#L95-L99 |
149,809 | uluyol/hdrhist | hist.go | Init | func (h *Hist) Init(cfg Config) {
if cfg.LowestDiscernible < 1 {
panic("invalid cfg: LowestDiscernible must be >= 1")
}
if cfg.HighestTrackable < 2*cfg.LowestDiscernible {
if cfg.AutoResize {
cfg.HighestTrackable = 2 * cfg.LowestDiscernible
} else {
panic("invalid cfg: HighestTrackable must be >= 2*Lowes... | go | func (h *Hist) Init(cfg Config) {
if cfg.LowestDiscernible < 1 {
panic("invalid cfg: LowestDiscernible must be >= 1")
}
if cfg.HighestTrackable < 2*cfg.LowestDiscernible {
if cfg.AutoResize {
cfg.HighestTrackable = 2 * cfg.LowestDiscernible
} else {
panic("invalid cfg: HighestTrackable must be >= 2*Lowes... | [
"func",
"(",
"h",
"*",
"Hist",
")",
"Init",
"(",
"cfg",
"Config",
")",
"{",
"if",
"cfg",
".",
"LowestDiscernible",
"<",
"1",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"if",
"cfg",
".",
"HighestTrackable",
"<",
"2",
"*",
"cfg",
".",
"... | // Init initializes the Hist with the given Config. | [
"Init",
"initializes",
"the",
"Hist",
"with",
"the",
"given",
"Config",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/hist.go#L102-L139 |
149,810 | uluyol/hdrhist | hist.go | EstMemSize | func (h *Hist) EstMemSize() int {
return histSize + 2*timeSize + cap(h.b.counts)*8
} | go | func (h *Hist) EstMemSize() int {
return histSize + 2*timeSize + cap(h.b.counts)*8
} | [
"func",
"(",
"h",
"*",
"Hist",
")",
"EstMemSize",
"(",
")",
"int",
"{",
"return",
"histSize",
"+",
"2",
"*",
"timeSize",
"+",
"cap",
"(",
"h",
".",
"b",
".",
"counts",
")",
"*",
"8",
"\n",
"}"
] | // EstMemSize estimates the number of bytes being consumed by the histogram.
// The resulting size should not be assumed to be exact.
// The return value is in bytes. | [
"EstMemSize",
"estimates",
"the",
"number",
"of",
"bytes",
"being",
"consumed",
"by",
"the",
"histogram",
".",
"The",
"resulting",
"size",
"should",
"not",
"be",
"assumed",
"to",
"be",
"exact",
".",
"The",
"return",
"value",
"is",
"in",
"bytes",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/hist.go#L331-L333 |
149,811 | uluyol/hdrhist | hist.go | Clear | func (h *Hist) Clear() {
for i := range h.b.counts {
h.b.counts[i] = 0
}
h.totalCount = 0
h.startTime = nil
h.endTime = nil
} | go | func (h *Hist) Clear() {
for i := range h.b.counts {
h.b.counts[i] = 0
}
h.totalCount = 0
h.startTime = nil
h.endTime = nil
} | [
"func",
"(",
"h",
"*",
"Hist",
")",
"Clear",
"(",
")",
"{",
"for",
"i",
":=",
"range",
"h",
".",
"b",
".",
"counts",
"{",
"h",
".",
"b",
".",
"counts",
"[",
"i",
"]",
"=",
"0",
"\n",
"}",
"\n",
"h",
".",
"totalCount",
"=",
"0",
"\n",
"h",... | // Clear deletes all recorded values as well as the start and end times. | [
"Clear",
"deletes",
"all",
"recorded",
"values",
"as",
"well",
"as",
"the",
"start",
"and",
"end",
"times",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/hist.go#L441-L448 |
149,812 | uluyol/hdrhist | internal/bits/bits.go | TrailingZeros | func TrailingZeros(x uint) int {
if UintSize == 32 {
return TrailingZeros32(uint32(x))
}
return TrailingZeros64(uint64(x))
} | go | func TrailingZeros(x uint) int {
if UintSize == 32 {
return TrailingZeros32(uint32(x))
}
return TrailingZeros64(uint64(x))
} | [
"func",
"TrailingZeros",
"(",
"x",
"uint",
")",
"int",
"{",
"if",
"UintSize",
"==",
"32",
"{",
"return",
"TrailingZeros32",
"(",
"uint32",
"(",
"x",
")",
")",
"\n",
"}",
"\n",
"return",
"TrailingZeros64",
"(",
"uint64",
"(",
"x",
")",
")",
"\n",
"}"
... | // TrailingZeros returns the number of trailing zero bits in x; the result is UintSize for x == 0. | [
"TrailingZeros",
"returns",
"the",
"number",
"of",
"trailing",
"zero",
"bits",
"in",
"x",
";",
"the",
"result",
"is",
"UintSize",
"for",
"x",
"==",
"0",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L53-L58 |
149,813 | uluyol/hdrhist | internal/bits/bits.go | TrailingZeros16 | func TrailingZeros16(x uint16) (n int) {
if x == 0 {
return 16
}
// see comment in TrailingZeros64
return int(deBruijn32tab[uint32(x&-x)*deBruijn32>>(32-5)])
} | go | func TrailingZeros16(x uint16) (n int) {
if x == 0 {
return 16
}
// see comment in TrailingZeros64
return int(deBruijn32tab[uint32(x&-x)*deBruijn32>>(32-5)])
} | [
"func",
"TrailingZeros16",
"(",
"x",
"uint16",
")",
"(",
"n",
"int",
")",
"{",
"if",
"x",
"==",
"0",
"{",
"return",
"16",
"\n",
"}",
"\n",
"// see comment in TrailingZeros64",
"return",
"int",
"(",
"deBruijn32tab",
"[",
"uint32",
"(",
"x",
"&",
"-",
"x... | // TrailingZeros16 returns the number of trailing zero bits in x; the result is 16 for x == 0. | [
"TrailingZeros16",
"returns",
"the",
"number",
"of",
"trailing",
"zero",
"bits",
"in",
"x",
";",
"the",
"result",
"is",
"16",
"for",
"x",
"==",
"0",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L66-L72 |
149,814 | uluyol/hdrhist | internal/bits/bits.go | TrailingZeros32 | func TrailingZeros32(x uint32) int {
if x == 0 {
return 32
}
// see comment in TrailingZeros64
return int(deBruijn32tab[(x&-x)*deBruijn32>>(32-5)])
} | go | func TrailingZeros32(x uint32) int {
if x == 0 {
return 32
}
// see comment in TrailingZeros64
return int(deBruijn32tab[(x&-x)*deBruijn32>>(32-5)])
} | [
"func",
"TrailingZeros32",
"(",
"x",
"uint32",
")",
"int",
"{",
"if",
"x",
"==",
"0",
"{",
"return",
"32",
"\n",
"}",
"\n",
"// see comment in TrailingZeros64",
"return",
"int",
"(",
"deBruijn32tab",
"[",
"(",
"x",
"&",
"-",
"x",
")",
"*",
"deBruijn32",
... | // TrailingZeros32 returns the number of trailing zero bits in x; the result is 32 for x == 0. | [
"TrailingZeros32",
"returns",
"the",
"number",
"of",
"trailing",
"zero",
"bits",
"in",
"x",
";",
"the",
"result",
"is",
"32",
"for",
"x",
"==",
"0",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L75-L81 |
149,815 | uluyol/hdrhist | internal/bits/bits.go | TrailingZeros64 | func TrailingZeros64(x uint64) int {
if x == 0 {
return 64
}
// If popcount is fast, replace code below with return popcount(^x & (x - 1)).
//
// x & -x leaves only the right-most bit set in the word. Let k be the
// index of that bit. Since only a single bit is set, the value is two
// to the power of k. Mult... | go | func TrailingZeros64(x uint64) int {
if x == 0 {
return 64
}
// If popcount is fast, replace code below with return popcount(^x & (x - 1)).
//
// x & -x leaves only the right-most bit set in the word. Let k be the
// index of that bit. Since only a single bit is set, the value is two
// to the power of k. Mult... | [
"func",
"TrailingZeros64",
"(",
"x",
"uint64",
")",
"int",
"{",
"if",
"x",
"==",
"0",
"{",
"return",
"64",
"\n",
"}",
"\n",
"// If popcount is fast, replace code below with return popcount(^x & (x - 1)).",
"//",
"// x & -x leaves only the right-most bit set in the word. Let k... | // TrailingZeros64 returns the number of trailing zero bits in x; the result is 64 for x == 0. | [
"TrailingZeros64",
"returns",
"the",
"number",
"of",
"trailing",
"zero",
"bits",
"in",
"x",
";",
"the",
"result",
"is",
"64",
"for",
"x",
"==",
"0",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L84-L100 |
149,816 | uluyol/hdrhist | internal/bits/bits.go | RotateLeft64 | func RotateLeft64(x uint64, k int) uint64 {
if k < 0 {
panic("negative rotation count")
}
const n = 64
s := uint(k) & (n - 1)
return x<<s | x>>(n-s)
} | go | func RotateLeft64(x uint64, k int) uint64 {
if k < 0 {
panic("negative rotation count")
}
const n = 64
s := uint(k) & (n - 1)
return x<<s | x>>(n-s)
} | [
"func",
"RotateLeft64",
"(",
"x",
"uint64",
",",
"k",
"int",
")",
"uint64",
"{",
"if",
"k",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"const",
"n",
"=",
"64",
"\n",
"s",
":=",
"uint",
"(",
"k",
")",
"&",
"(",
"n",
"-",
... | // RotateLeft64 returns the value of x rotated left by k bits; k must not be negative. | [
"RotateLeft64",
"returns",
"the",
"value",
"of",
"x",
"rotated",
"left",
"by",
"k",
"bits",
";",
"k",
"must",
"not",
"be",
"negative",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L205-L212 |
149,817 | uluyol/hdrhist | internal/bits/bits.go | RotateRight8 | func RotateRight8(x uint8, k int) uint8 {
if k < 0 {
panic("negative rotation count")
}
const n = 8
s := uint(k) & (n - 1)
return x<<(n-s) | x>>s
} | go | func RotateRight8(x uint8, k int) uint8 {
if k < 0 {
panic("negative rotation count")
}
const n = 8
s := uint(k) & (n - 1)
return x<<(n-s) | x>>s
} | [
"func",
"RotateRight8",
"(",
"x",
"uint8",
",",
"k",
"int",
")",
"uint8",
"{",
"if",
"k",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"const",
"n",
"=",
"8",
"\n",
"s",
":=",
"uint",
"(",
"k",
")",
"&",
"(",
"n",
"-",
"... | // RotateRight8 returns the value of x rotated left by k bits; k must not be negative. | [
"RotateRight8",
"returns",
"the",
"value",
"of",
"x",
"rotated",
"left",
"by",
"k",
"bits",
";",
"k",
"must",
"not",
"be",
"negative",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L225-L232 |
149,818 | uluyol/hdrhist | internal/bits/bits.go | RotateRight16 | func RotateRight16(x uint16, k int) uint16 {
if k < 0 {
panic("negative rotation count")
}
const n = 16
s := uint(k) & (n - 1)
return x<<(n-s) | x>>s
} | go | func RotateRight16(x uint16, k int) uint16 {
if k < 0 {
panic("negative rotation count")
}
const n = 16
s := uint(k) & (n - 1)
return x<<(n-s) | x>>s
} | [
"func",
"RotateRight16",
"(",
"x",
"uint16",
",",
"k",
"int",
")",
"uint16",
"{",
"if",
"k",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"const",
"n",
"=",
"16",
"\n",
"s",
":=",
"uint",
"(",
"k",
")",
"&",
"(",
"n",
"-",... | // RotateRight16 returns the value of x rotated left by k bits; k must not be negative. | [
"RotateRight16",
"returns",
"the",
"value",
"of",
"x",
"rotated",
"left",
"by",
"k",
"bits",
";",
"k",
"must",
"not",
"be",
"negative",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L235-L242 |
149,819 | uluyol/hdrhist | internal/bits/bits.go | RotateRight32 | func RotateRight32(x uint32, k int) uint32 {
if k < 0 {
panic("negative rotation count")
}
const n = 32
s := uint(k) & (n - 1)
return x<<(n-s) | x>>s
} | go | func RotateRight32(x uint32, k int) uint32 {
if k < 0 {
panic("negative rotation count")
}
const n = 32
s := uint(k) & (n - 1)
return x<<(n-s) | x>>s
} | [
"func",
"RotateRight32",
"(",
"x",
"uint32",
",",
"k",
"int",
")",
"uint32",
"{",
"if",
"k",
"<",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"const",
"n",
"=",
"32",
"\n",
"s",
":=",
"uint",
"(",
"k",
")",
"&",
"(",
"n",
"-",... | // RotateRight32 returns the value of x rotated left by k bits; k must not be negative. | [
"RotateRight32",
"returns",
"the",
"value",
"of",
"x",
"rotated",
"left",
"by",
"k",
"bits",
";",
"k",
"must",
"not",
"be",
"negative",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L245-L252 |
149,820 | uluyol/hdrhist | internal/bits/bits.go | Reverse16 | func Reverse16(x uint16) uint16 {
return uint16(rev8tab[x>>8]) | uint16(rev8tab[x&0xff])<<8
} | go | func Reverse16(x uint16) uint16 {
return uint16(rev8tab[x>>8]) | uint16(rev8tab[x&0xff])<<8
} | [
"func",
"Reverse16",
"(",
"x",
"uint16",
")",
"uint16",
"{",
"return",
"uint16",
"(",
"rev8tab",
"[",
"x",
">>",
"8",
"]",
")",
"|",
"uint16",
"(",
"rev8tab",
"[",
"x",
"&",
"0xff",
"]",
")",
"<<",
"8",
"\n",
"}"
] | // Reverse16 returns the value of x with its bits in reversed order. | [
"Reverse16",
"returns",
"the",
"value",
"of",
"x",
"with",
"its",
"bits",
"in",
"reversed",
"order",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L280-L282 |
149,821 | uluyol/hdrhist | internal/bits/bits.go | Reverse32 | func Reverse32(x uint32) uint32 {
const m = 1<<32 - 1
x = x>>1&(m0&m) | x&(m0&m)<<1
x = x>>2&(m1&m) | x&(m1&m)<<2
x = x>>4&(m2&m) | x&(m2&m)<<4
x = x>>8&(m3&m) | x&(m3&m)<<8
return x>>16 | x<<16
} | go | func Reverse32(x uint32) uint32 {
const m = 1<<32 - 1
x = x>>1&(m0&m) | x&(m0&m)<<1
x = x>>2&(m1&m) | x&(m1&m)<<2
x = x>>4&(m2&m) | x&(m2&m)<<4
x = x>>8&(m3&m) | x&(m3&m)<<8
return x>>16 | x<<16
} | [
"func",
"Reverse32",
"(",
"x",
"uint32",
")",
"uint32",
"{",
"const",
"m",
"=",
"1",
"<<",
"32",
"-",
"1",
"\n",
"x",
"=",
"x",
">>",
"1",
"&",
"(",
"m0",
"&",
"m",
")",
"|",
"x",
"&",
"(",
"m0",
"&",
"m",
")",
"<<",
"1",
"\n",
"x",
"="... | // Reverse32 returns the value of x with its bits in reversed order. | [
"Reverse32",
"returns",
"the",
"value",
"of",
"x",
"with",
"its",
"bits",
"in",
"reversed",
"order",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L285-L292 |
149,822 | uluyol/hdrhist | internal/bits/bits.go | Reverse64 | func Reverse64(x uint64) uint64 {
const m = 1<<64 - 1
x = x>>1&(m0&m) | x&(m0&m)<<1
x = x>>2&(m1&m) | x&(m1&m)<<2
x = x>>4&(m2&m) | x&(m2&m)<<4
x = x>>8&(m3&m) | x&(m3&m)<<8
x = x>>16&(m4&m) | x&(m4&m)<<16
return x>>32 | x<<32
} | go | func Reverse64(x uint64) uint64 {
const m = 1<<64 - 1
x = x>>1&(m0&m) | x&(m0&m)<<1
x = x>>2&(m1&m) | x&(m1&m)<<2
x = x>>4&(m2&m) | x&(m2&m)<<4
x = x>>8&(m3&m) | x&(m3&m)<<8
x = x>>16&(m4&m) | x&(m4&m)<<16
return x>>32 | x<<32
} | [
"func",
"Reverse64",
"(",
"x",
"uint64",
")",
"uint64",
"{",
"const",
"m",
"=",
"1",
"<<",
"64",
"-",
"1",
"\n",
"x",
"=",
"x",
">>",
"1",
"&",
"(",
"m0",
"&",
"m",
")",
"|",
"x",
"&",
"(",
"m0",
"&",
"m",
")",
"<<",
"1",
"\n",
"x",
"="... | // Reverse64 returns the value of x with its bits in reversed order. | [
"Reverse64",
"returns",
"the",
"value",
"of",
"x",
"with",
"its",
"bits",
"in",
"reversed",
"order",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L295-L303 |
149,823 | uluyol/hdrhist | internal/bits/bits.go | ReverseBytes32 | func ReverseBytes32(x uint32) uint32 {
const m = 1<<32 - 1
x = x>>8&(m3&m) | x&(m3&m)<<8
return x>>16 | x<<16
} | go | func ReverseBytes32(x uint32) uint32 {
const m = 1<<32 - 1
x = x>>8&(m3&m) | x&(m3&m)<<8
return x>>16 | x<<16
} | [
"func",
"ReverseBytes32",
"(",
"x",
"uint32",
")",
"uint32",
"{",
"const",
"m",
"=",
"1",
"<<",
"32",
"-",
"1",
"\n",
"x",
"=",
"x",
">>",
"8",
"&",
"(",
"m3",
"&",
"m",
")",
"|",
"x",
"&",
"(",
"m3",
"&",
"m",
")",
"<<",
"8",
"\n",
"retu... | // ReverseBytes32 returns the value of x with its bytes in reversed order. | [
"ReverseBytes32",
"returns",
"the",
"value",
"of",
"x",
"with",
"its",
"bytes",
"in",
"reversed",
"order",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L321-L325 |
149,824 | uluyol/hdrhist | internal/bits/bits.go | ReverseBytes64 | func ReverseBytes64(x uint64) uint64 {
const m = 1<<64 - 1
x = x>>8&(m3&m) | x&(m3&m)<<8
x = x>>16&(m4&m) | x&(m4&m)<<16
return x>>32 | x<<32
} | go | func ReverseBytes64(x uint64) uint64 {
const m = 1<<64 - 1
x = x>>8&(m3&m) | x&(m3&m)<<8
x = x>>16&(m4&m) | x&(m4&m)<<16
return x>>32 | x<<32
} | [
"func",
"ReverseBytes64",
"(",
"x",
"uint64",
")",
"uint64",
"{",
"const",
"m",
"=",
"1",
"<<",
"64",
"-",
"1",
"\n",
"x",
"=",
"x",
">>",
"8",
"&",
"(",
"m3",
"&",
"m",
")",
"|",
"x",
"&",
"(",
"m3",
"&",
"m",
")",
"<<",
"8",
"\n",
"x",
... | // ReverseBytes64 returns the value of x with its bytes in reversed order. | [
"ReverseBytes64",
"returns",
"the",
"value",
"of",
"x",
"with",
"its",
"bytes",
"in",
"reversed",
"order",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L328-L333 |
149,825 | uluyol/hdrhist | internal/bits/bits.go | Len16 | func Len16(x uint16) (n int) {
if x >= 1<<8 {
x >>= 8
n = 8
}
return n + int(len8tab[x])
} | go | func Len16(x uint16) (n int) {
if x >= 1<<8 {
x >>= 8
n = 8
}
return n + int(len8tab[x])
} | [
"func",
"Len16",
"(",
"x",
"uint16",
")",
"(",
"n",
"int",
")",
"{",
"if",
"x",
">=",
"1",
"<<",
"8",
"{",
"x",
">>=",
"8",
"\n",
"n",
"=",
"8",
"\n",
"}",
"\n",
"return",
"n",
"+",
"int",
"(",
"len8tab",
"[",
"x",
"]",
")",
"\n",
"}"
] | // Len16 returns the minimum number of bits required to represent x; the result is 0 for x == 0. | [
"Len16",
"returns",
"the",
"minimum",
"number",
"of",
"bits",
"required",
"to",
"represent",
"x",
";",
"the",
"result",
"is",
"0",
"for",
"x",
"==",
"0",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L351-L357 |
149,826 | uluyol/hdrhist | internal/bits/bits.go | Len32 | func Len32(x uint32) (n int) {
if x >= 1<<16 {
x >>= 16
n = 16
}
if x >= 1<<8 {
x >>= 8
n += 8
}
return n + int(len8tab[x])
} | go | func Len32(x uint32) (n int) {
if x >= 1<<16 {
x >>= 16
n = 16
}
if x >= 1<<8 {
x >>= 8
n += 8
}
return n + int(len8tab[x])
} | [
"func",
"Len32",
"(",
"x",
"uint32",
")",
"(",
"n",
"int",
")",
"{",
"if",
"x",
">=",
"1",
"<<",
"16",
"{",
"x",
">>=",
"16",
"\n",
"n",
"=",
"16",
"\n",
"}",
"\n",
"if",
"x",
">=",
"1",
"<<",
"8",
"{",
"x",
">>=",
"8",
"\n",
"n",
"+=",... | // Len32 returns the minimum number of bits required to represent x; the result is 0 for x == 0. | [
"Len32",
"returns",
"the",
"minimum",
"number",
"of",
"bits",
"required",
"to",
"represent",
"x",
";",
"the",
"result",
"is",
"0",
"for",
"x",
"==",
"0",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L360-L370 |
149,827 | uluyol/hdrhist | internal/bits/bits.go | Len64 | func Len64(x uint64) (n int) {
if x >= 1<<32 {
x >>= 32
n = 32
}
if x >= 1<<16 {
x >>= 16
n += 16
}
if x >= 1<<8 {
x >>= 8
n += 8
}
return n + int(len8tab[x])
} | go | func Len64(x uint64) (n int) {
if x >= 1<<32 {
x >>= 32
n = 32
}
if x >= 1<<16 {
x >>= 16
n += 16
}
if x >= 1<<8 {
x >>= 8
n += 8
}
return n + int(len8tab[x])
} | [
"func",
"Len64",
"(",
"x",
"uint64",
")",
"(",
"n",
"int",
")",
"{",
"if",
"x",
">=",
"1",
"<<",
"32",
"{",
"x",
">>=",
"32",
"\n",
"n",
"=",
"32",
"\n",
"}",
"\n",
"if",
"x",
">=",
"1",
"<<",
"16",
"{",
"x",
">>=",
"16",
"\n",
"n",
"+=... | // Len64 returns the minimum number of bits required to represent x; the result is 0 for x == 0. | [
"Len64",
"returns",
"the",
"minimum",
"number",
"of",
"bits",
"required",
"to",
"represent",
"x",
";",
"the",
"result",
"is",
"0",
"for",
"x",
"==",
"0",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/internal/bits/bits.go#L373-L387 |
149,828 | ellcrys/go-libp2p-crypto | key.go | GenerateKeyPairWithReader | func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error) {
switch typ {
case RSA:
priv, err := rsa.GenerateKey(src, bits)
if err != nil {
return nil, nil, err
}
pk := &priv.PublicKey
return &RsaPrivateKey{sk: priv}, &RsaPublicKey{pk}, nil
case Ed25519:
return GenerateEd255... | go | func GenerateKeyPairWithReader(typ, bits int, src io.Reader) (PrivKey, PubKey, error) {
switch typ {
case RSA:
priv, err := rsa.GenerateKey(src, bits)
if err != nil {
return nil, nil, err
}
pk := &priv.PublicKey
return &RsaPrivateKey{sk: priv}, &RsaPublicKey{pk}, nil
case Ed25519:
return GenerateEd255... | [
"func",
"GenerateKeyPairWithReader",
"(",
"typ",
",",
"bits",
"int",
",",
"src",
"io",
".",
"Reader",
")",
"(",
"PrivKey",
",",
"PubKey",
",",
"error",
")",
"{",
"switch",
"typ",
"{",
"case",
"RSA",
":",
"priv",
",",
"err",
":=",
"rsa",
".",
"Generat... | // Generates a keypair of the given type and bitsize | [
"Generates",
"a",
"keypair",
"of",
"the",
"given",
"type",
"and",
"bitsize"
] | 08bc4ca6778916abbeb103712423416289bb4c8d | https://github.com/ellcrys/go-libp2p-crypto/blob/08bc4ca6778916abbeb103712423416289bb4c8d/key.go#L95-L111 |
149,829 | ellcrys/go-libp2p-crypto | key.go | MarshalPrivateKey | func MarshalPrivateKey(k PrivKey) ([]byte, error) {
switch k.(type) {
case *Ed25519PrivateKey:
return k.Bytes()
case *RsaPrivateKey:
return k.Bytes()
case *Secp256k1PrivateKey:
return k.Bytes()
default:
return nil, ErrBadKeyType
}
} | go | func MarshalPrivateKey(k PrivKey) ([]byte, error) {
switch k.(type) {
case *Ed25519PrivateKey:
return k.Bytes()
case *RsaPrivateKey:
return k.Bytes()
case *Secp256k1PrivateKey:
return k.Bytes()
default:
return nil, ErrBadKeyType
}
} | [
"func",
"MarshalPrivateKey",
"(",
"k",
"PrivKey",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"switch",
"k",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Ed25519PrivateKey",
":",
"return",
"k",
".",
"Bytes",
"(",
")",
"\n",
"case",
"*",
"RsaPr... | // MarshalPrivateKey converts a key object into its protobuf serialized form. | [
"MarshalPrivateKey",
"converts",
"a",
"key",
"object",
"into",
"its",
"protobuf",
"serialized",
"form",
"."
] | 08bc4ca6778916abbeb103712423416289bb4c8d | https://github.com/ellcrys/go-libp2p-crypto/blob/08bc4ca6778916abbeb103712423416289bb4c8d/key.go#L285-L297 |
149,830 | uluyol/hdrhist | decode.go | decodeIntSize | func decodeIntSize(buf []byte, size int) (int64, error) {
if size < 0 || 8 < size {
return 0, errors.New("invalid size")
}
if len(buf) < size {
return 0, errors.Errorf("got %d bytes, need %d", len(buf), size)
}
switch size {
case 2:
return int64(buf[0])<<8 | int64(buf[1]), nil
case 4:
return int64(buf[0]... | go | func decodeIntSize(buf []byte, size int) (int64, error) {
if size < 0 || 8 < size {
return 0, errors.New("invalid size")
}
if len(buf) < size {
return 0, errors.Errorf("got %d bytes, need %d", len(buf), size)
}
switch size {
case 2:
return int64(buf[0])<<8 | int64(buf[1]), nil
case 4:
return int64(buf[0]... | [
"func",
"decodeIntSize",
"(",
"buf",
"[",
"]",
"byte",
",",
"size",
"int",
")",
"(",
"int64",
",",
"error",
")",
"{",
"if",
"size",
"<",
"0",
"||",
"8",
"<",
"size",
"{",
"return",
"0",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"... | // decodeIntSize decodes the integer of the provided size
// as a big-endian number and returns it. | [
"decodeIntSize",
"decodes",
"the",
"integer",
"of",
"the",
"provided",
"size",
"as",
"a",
"big",
"-",
"endian",
"number",
"and",
"returns",
"it",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/decode.go#L182-L208 |
149,831 | flike/golog | log.go | New | func New(handler Handler, flag int) *Logger {
var l = new(Logger)
l.level = LevelInfo
l.handler = handler
l.flag = flag
l.quit = make(chan struct{})
l.closed = false
l.msg = make(chan []byte, 1024)
l.bufs = make([][]byte, 0, 16)
l.wg.Add(1)
go l.run()
return l
} | go | func New(handler Handler, flag int) *Logger {
var l = new(Logger)
l.level = LevelInfo
l.handler = handler
l.flag = flag
l.quit = make(chan struct{})
l.closed = false
l.msg = make(chan []byte, 1024)
l.bufs = make([][]byte, 0, 16)
l.wg.Add(1)
go l.run()
return l
} | [
"func",
"New",
"(",
"handler",
"Handler",
",",
"flag",
"int",
")",
"*",
"Logger",
"{",
"var",
"l",
"=",
"new",
"(",
"Logger",
")",
"\n\n",
"l",
".",
"level",
"=",
"LevelInfo",
"\n",
"l",
".",
"handler",
"=",
"handler",
"\n\n",
"l",
".",
"flag",
"... | //new a logger with specified handler and flag | [
"new",
"a",
"logger",
"with",
"specified",
"handler",
"and",
"flag"
] | d59ac6dad9f09769d00642a7431b8f32823fb9f6 | https://github.com/flike/golog/blob/d59ac6dad9f09769d00642a7431b8f32823fb9f6/log.go#L54-L73 |
149,832 | dmcgowan/go-tar | strconv.go | parsePAXTime | func parsePAXTime(s string) (time.Time, error) {
const maxNanoSecondDigits = 9
// Split string into seconds and sub-seconds parts.
ss, sn := s, ""
if pos := strings.IndexByte(s, '.'); pos >= 0 {
ss, sn = s[:pos], s[pos+1:]
}
// Parse the seconds.
secs, err := strconv.ParseInt(ss, 10, 64)
if err != nil {
r... | go | func parsePAXTime(s string) (time.Time, error) {
const maxNanoSecondDigits = 9
// Split string into seconds and sub-seconds parts.
ss, sn := s, ""
if pos := strings.IndexByte(s, '.'); pos >= 0 {
ss, sn = s[:pos], s[pos+1:]
}
// Parse the seconds.
secs, err := strconv.ParseInt(ss, 10, 64)
if err != nil {
r... | [
"func",
"parsePAXTime",
"(",
"s",
"string",
")",
"(",
"time",
".",
"Time",
",",
"error",
")",
"{",
"const",
"maxNanoSecondDigits",
"=",
"9",
"\n\n",
"// Split string into seconds and sub-seconds parts.",
"ss",
",",
"sn",
":=",
"s",
",",
"\"",
"\"",
"\n",
"if... | // parsePAXTime takes a string of the form %d.%d as described in the PAX
// specification. Note that this implementation allows for negative timestamps,
// which is allowed for by the PAX specification, but not always portable. | [
"parsePAXTime",
"takes",
"a",
"string",
"of",
"the",
"form",
"%d",
".",
"%d",
"as",
"described",
"in",
"the",
"PAX",
"specification",
".",
"Note",
"that",
"this",
"implementation",
"allows",
"for",
"negative",
"timestamps",
"which",
"is",
"allowed",
"for",
"... | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/strconv.go#L169-L201 |
149,833 | jacobsa/timeutil | time_near.go | TimeNear | func TimeNear(t time.Time, d time.Duration) oglematchers.Matcher {
return oglematchers.NewMatcher(
func(c interface{}) error { return timeNear(t, d, c) },
fmt.Sprintf("within %v of %v", d, t))
} | go | func TimeNear(t time.Time, d time.Duration) oglematchers.Matcher {
return oglematchers.NewMatcher(
func(c interface{}) error { return timeNear(t, d, c) },
fmt.Sprintf("within %v of %v", d, t))
} | [
"func",
"TimeNear",
"(",
"t",
"time",
".",
"Time",
",",
"d",
"time",
".",
"Duration",
")",
"oglematchers",
".",
"Matcher",
"{",
"return",
"oglematchers",
".",
"NewMatcher",
"(",
"func",
"(",
"c",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"tim... | // Return a matcher for times whose absolute distance from t is less than d. | [
"Return",
"a",
"matcher",
"for",
"times",
"whose",
"absolute",
"distance",
"from",
"t",
"is",
"less",
"than",
"d",
"."
] | 577e5acbbcf60f68c80c6f5edfeefe50e477c853 | https://github.com/jacobsa/timeutil/blob/577e5acbbcf60f68c80c6f5edfeefe50e477c853/time_near.go#L41-L45 |
149,834 | viniciuschiele-archive/tarx | tarx.go | Compress | func Compress(fileName, srcPath string, options *CompressOptions) error {
if options == nil {
options = &CompressOptions{}
}
srcInfo, err := os.Lstat(srcPath)
if err != nil {
return err
}
writer, err := newWriter(fileName, options)
if err != nil {
return err
}
// Removes the last slash to avoid differ... | go | func Compress(fileName, srcPath string, options *CompressOptions) error {
if options == nil {
options = &CompressOptions{}
}
srcInfo, err := os.Lstat(srcPath)
if err != nil {
return err
}
writer, err := newWriter(fileName, options)
if err != nil {
return err
}
// Removes the last slash to avoid differ... | [
"func",
"Compress",
"(",
"fileName",
",",
"srcPath",
"string",
",",
"options",
"*",
"CompressOptions",
")",
"error",
"{",
"if",
"options",
"==",
"nil",
"{",
"options",
"=",
"&",
"CompressOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"srcInfo",
",",
"err",
":=",... | // Compress compress a source path into a tar file.
// All files will be relative to the tar file. | [
"Compress",
"compress",
"a",
"source",
"path",
"into",
"a",
"tar",
"file",
".",
"All",
"files",
"will",
"be",
"relative",
"to",
"the",
"tar",
"file",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L71-L133 |
149,835 | viniciuschiele-archive/tarx | tarx.go | Extract | func Extract(fileName, targetDir string, options *ExtractOptions) error {
if options == nil {
options = &ExtractOptions{}
}
reader, err := newReader(fileName)
if err != nil {
return err
}
defer reader.Close()
if err := os.MkdirAll(targetDir, os.ModePerm); err != nil {
return err
}
// To improve perfo... | go | func Extract(fileName, targetDir string, options *ExtractOptions) error {
if options == nil {
options = &ExtractOptions{}
}
reader, err := newReader(fileName)
if err != nil {
return err
}
defer reader.Close()
if err := os.MkdirAll(targetDir, os.ModePerm); err != nil {
return err
}
// To improve perfo... | [
"func",
"Extract",
"(",
"fileName",
",",
"targetDir",
"string",
",",
"options",
"*",
"ExtractOptions",
")",
"error",
"{",
"if",
"options",
"==",
"nil",
"{",
"options",
"=",
"&",
"ExtractOptions",
"{",
"}",
"\n",
"}",
"\n\n",
"reader",
",",
"err",
":=",
... | // Extract extracts the files from a tar file into a target directory. | [
"Extract",
"extracts",
"the",
"files",
"from",
"a",
"tar",
"file",
"into",
"a",
"target",
"directory",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L136-L189 |
149,836 | viniciuschiele-archive/tarx | tarx.go | Find | func Find(fileName, targetFileName string) (*tar.Header, io.ReadCloser, error) {
reader, err := newReader(fileName)
if err != nil {
return nil, nil, err
}
targetFileName = path.Clean(targetFileName)
for {
header, err := reader.reader.Next()
if err == io.EOF {
reader.Close()
return nil, nil, os.ErrNot... | go | func Find(fileName, targetFileName string) (*tar.Header, io.ReadCloser, error) {
reader, err := newReader(fileName)
if err != nil {
return nil, nil, err
}
targetFileName = path.Clean(targetFileName)
for {
header, err := reader.reader.Next()
if err == io.EOF {
reader.Close()
return nil, nil, os.ErrNot... | [
"func",
"Find",
"(",
"fileName",
",",
"targetFileName",
"string",
")",
"(",
"*",
"tar",
".",
"Header",
",",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"reader",
",",
"err",
":=",
"newReader",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil"... | // Find returns the header and ReadCloser for the entry in the tarfile
// that matches the filename. If nothing matches, an `os.ErrNotExists`
// error is returned.
// If the `targetFileName` is not a regular file it returns a reader `nil`. | [
"Find",
"returns",
"the",
"header",
"and",
"ReadCloser",
"for",
"the",
"entry",
"in",
"the",
"tarfile",
"that",
"matches",
"the",
"filename",
".",
"If",
"nothing",
"matches",
"an",
"os",
".",
"ErrNotExists",
"error",
"is",
"returned",
".",
"If",
"the",
"ta... | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L195-L223 |
149,837 | viniciuschiele-archive/tarx | tarx.go | List | func List(fileName string) ([]*tar.Header, error) {
reader, err := newReader(fileName)
if err != nil {
return nil, err
}
defer reader.Close()
headers := []*tar.Header{}
for {
err := reader.Next()
if err == io.EOF {
return headers, nil
}
if err != nil {
return nil, err
}
headers = append(he... | go | func List(fileName string) ([]*tar.Header, error) {
reader, err := newReader(fileName)
if err != nil {
return nil, err
}
defer reader.Close()
headers := []*tar.Header{}
for {
err := reader.Next()
if err == io.EOF {
return headers, nil
}
if err != nil {
return nil, err
}
headers = append(he... | [
"func",
"List",
"(",
"fileName",
"string",
")",
"(",
"[",
"]",
"*",
"tar",
".",
"Header",
",",
"error",
")",
"{",
"reader",
",",
"err",
":=",
"newReader",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n... | // List lists all entries from a tar file. | [
"List",
"lists",
"all",
"entries",
"from",
"a",
"tar",
"file",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L226-L247 |
149,838 | viniciuschiele-archive/tarx | tarx.go | newReader | func newReader(fileName string) (*tarReader, error) {
file, err := os.OpenFile(fileName, os.O_RDONLY, os.ModePerm)
if err != nil {
return nil, err
}
// Reads the header from the file to see which compression
// this file has been using.
compression, err := detectCompression(file)
if err != nil {
return nil,... | go | func newReader(fileName string) (*tarReader, error) {
file, err := os.OpenFile(fileName, os.O_RDONLY, os.ModePerm)
if err != nil {
return nil, err
}
// Reads the header from the file to see which compression
// this file has been using.
compression, err := detectCompression(file)
if err != nil {
return nil,... | [
"func",
"newReader",
"(",
"fileName",
"string",
")",
"(",
"*",
"tarReader",
",",
"error",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"OpenFile",
"(",
"fileName",
",",
"os",
".",
"O_RDONLY",
",",
"os",
".",
"ModePerm",
")",
"\n",
"if",
"err",
"!... | // newReader opens a tar file as readonly | [
"newReader",
"opens",
"a",
"tar",
"file",
"as",
"readonly"
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L250-L289 |
149,839 | viniciuschiele-archive/tarx | tarx.go | newWriter | func newWriter(fileName string, options *CompressOptions) (*tarWriter, error) {
var file *os.File
var err error
if options.Append {
file, err = os.OpenFile(fileName, os.O_RDWR, os.ModePerm)
} else {
file, err = os.Create(fileName)
}
if err != nil {
return nil, err
}
// In case of error we close and rem... | go | func newWriter(fileName string, options *CompressOptions) (*tarWriter, error) {
var file *os.File
var err error
if options.Append {
file, err = os.OpenFile(fileName, os.O_RDWR, os.ModePerm)
} else {
file, err = os.Create(fileName)
}
if err != nil {
return nil, err
}
// In case of error we close and rem... | [
"func",
"newWriter",
"(",
"fileName",
"string",
",",
"options",
"*",
"CompressOptions",
")",
"(",
"*",
"tarWriter",
",",
"error",
")",
"{",
"var",
"file",
"*",
"os",
".",
"File",
"\n",
"var",
"err",
"error",
"\n\n",
"if",
"options",
".",
"Append",
"{",... | // newReader creates a new tar file on disk if `append=false` otherwise
// it opens the tar file. | [
"newReader",
"creates",
"a",
"new",
"tar",
"file",
"on",
"disk",
"if",
"append",
"=",
"false",
"otherwise",
"it",
"opens",
"the",
"tar",
"file",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L293-L366 |
149,840 | viniciuschiele-archive/tarx | tarx.go | detectCompression | func detectCompression(file *os.File) (Compression, error) {
source := make([]byte, 3)
if _, err := file.ReadAt(source, 0); err != nil {
return Uncompressed, err
}
for compression, m := range map[Compression][]byte{
Bzip2: {0x42, 0x5A, 0x68},
Gzip: {0x1F, 0x8B, 0x08},
} {
if len(source) < len(m) {
co... | go | func detectCompression(file *os.File) (Compression, error) {
source := make([]byte, 3)
if _, err := file.ReadAt(source, 0); err != nil {
return Uncompressed, err
}
for compression, m := range map[Compression][]byte{
Bzip2: {0x42, 0x5A, 0x68},
Gzip: {0x1F, 0x8B, 0x08},
} {
if len(source) < len(m) {
co... | [
"func",
"detectCompression",
"(",
"file",
"*",
"os",
".",
"File",
")",
"(",
"Compression",
",",
"error",
")",
"{",
"source",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"3",
")",
"\n\n",
"if",
"_",
",",
"err",
":=",
"file",
".",
"ReadAt",
"(",
"sou... | // detectCompression detects which comperssion the tar file has been using. | [
"detectCompression",
"detects",
"which",
"comperssion",
"the",
"tar",
"file",
"has",
"been",
"using",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L369-L388 |
149,841 | viniciuschiele-archive/tarx | tarx.go | Extract | func (r *tarReader) Extract(fileName string, noOverride bool) error {
fileInfo, err := os.Lstat(fileName)
if err != nil && !os.IsNotExist(err) {
return err
}
// If the `fileName` already exists on disk and it is a file
// we try to delete it in order to create a new one unless
// `noOverride` is set to true
i... | go | func (r *tarReader) Extract(fileName string, noOverride bool) error {
fileInfo, err := os.Lstat(fileName)
if err != nil && !os.IsNotExist(err) {
return err
}
// If the `fileName` already exists on disk and it is a file
// we try to delete it in order to create a new one unless
// `noOverride` is set to true
i... | [
"func",
"(",
"r",
"*",
"tarReader",
")",
"Extract",
"(",
"fileName",
"string",
",",
"noOverride",
"bool",
")",
"error",
"{",
"fileInfo",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"&&",
"!",
"os",
".... | // Extract extracts a tar file into disk | [
"Extract",
"extracts",
"a",
"tar",
"file",
"into",
"disk"
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L391-L432 |
149,842 | viniciuschiele-archive/tarx | tarx.go | Next | func (r *tarReader) Next() error {
header, err := r.reader.Next()
r.header = header
return err
} | go | func (r *tarReader) Next() error {
header, err := r.reader.Next()
r.header = header
return err
} | [
"func",
"(",
"r",
"*",
"tarReader",
")",
"Next",
"(",
")",
"error",
"{",
"header",
",",
"err",
":=",
"r",
".",
"reader",
".",
"Next",
"(",
")",
"\n",
"r",
".",
"header",
"=",
"header",
"\n",
"return",
"err",
"\n",
"}"
] | // Next is just a wrapper aroung tar.Reader.Next | [
"Next",
"is",
"just",
"a",
"wrapper",
"aroung",
"tar",
".",
"Reader",
".",
"Next"
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L435-L439 |
149,843 | viniciuschiele-archive/tarx | tarx.go | Read | func (r *tarReader) Read(p []byte) (n int, err error) {
return r.reader.Read(p)
} | go | func (r *tarReader) Read(p []byte) (n int, err error) {
return r.reader.Read(p)
} | [
"func",
"(",
"r",
"*",
"tarReader",
")",
"Read",
"(",
"p",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"return",
"r",
".",
"reader",
".",
"Read",
"(",
"p",
")",
"\n",
"}"
] | // Next is just a wrapper aroung tar.Reader.Read | [
"Next",
"is",
"just",
"a",
"wrapper",
"aroung",
"tar",
".",
"Reader",
".",
"Read"
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L442-L444 |
149,844 | viniciuschiele-archive/tarx | tarx.go | Close | func (r *tarReader) Close() error {
if r.compressReader != nil {
if err := r.compressReader.Close(); err != nil {
return err
}
}
if err := r.file.Close(); err != nil {
return err
}
return nil
} | go | func (r *tarReader) Close() error {
if r.compressReader != nil {
if err := r.compressReader.Close(); err != nil {
return err
}
}
if err := r.file.Close(); err != nil {
return err
}
return nil
} | [
"func",
"(",
"r",
"*",
"tarReader",
")",
"Close",
"(",
")",
"error",
"{",
"if",
"r",
".",
"compressReader",
"!=",
"nil",
"{",
"if",
"err",
":=",
"r",
".",
"compressReader",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\... | // Close closes the tar file. | [
"Close",
"closes",
"the",
"tar",
"file",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L447-L459 |
149,845 | viniciuschiele-archive/tarx | tarx.go | Close | func (w *tarWriter) Close(remove bool) error {
if w.writer != nil {
if err := w.writer.Close(); err != nil {
return err
}
}
if w.compressWriter != nil {
if err := w.compressWriter.Close(); err != nil {
return err
}
}
if err := w.file.Close(); err != nil {
return err
}
if remove {
return os.R... | go | func (w *tarWriter) Close(remove bool) error {
if w.writer != nil {
if err := w.writer.Close(); err != nil {
return err
}
}
if w.compressWriter != nil {
if err := w.compressWriter.Close(); err != nil {
return err
}
}
if err := w.file.Close(); err != nil {
return err
}
if remove {
return os.R... | [
"func",
"(",
"w",
"*",
"tarWriter",
")",
"Close",
"(",
"remove",
"bool",
")",
"error",
"{",
"if",
"w",
".",
"writer",
"!=",
"nil",
"{",
"if",
"err",
":=",
"w",
".",
"writer",
".",
"Close",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err"... | // Close closes the tar file, we usually use remove=true when the tar file
// is created but the compression fails, in this case
// we have to delete the tar file. | [
"Close",
"closes",
"the",
"tar",
"file",
"we",
"usually",
"use",
"remove",
"=",
"true",
"when",
"the",
"tar",
"file",
"is",
"created",
"but",
"the",
"compression",
"fails",
"in",
"this",
"case",
"we",
"have",
"to",
"delete",
"the",
"tar",
"file",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L464-L486 |
149,846 | viniciuschiele-archive/tarx | tarx.go | Write | func (w *tarWriter) Write(fileName, name string) error {
fileInfo, err := os.Lstat(fileName)
if err != nil {
return err
}
link := ""
if fileInfo.Mode()&os.ModeSymlink != 0 {
if link, err = os.Readlink(fileName); err != nil {
return err
}
}
header, err := tar.FileInfoHeader(fileInfo, link)
if err != n... | go | func (w *tarWriter) Write(fileName, name string) error {
fileInfo, err := os.Lstat(fileName)
if err != nil {
return err
}
link := ""
if fileInfo.Mode()&os.ModeSymlink != 0 {
if link, err = os.Readlink(fileName); err != nil {
return err
}
}
header, err := tar.FileInfoHeader(fileInfo, link)
if err != n... | [
"func",
"(",
"w",
"*",
"tarWriter",
")",
"Write",
"(",
"fileName",
",",
"name",
"string",
")",
"error",
"{",
"fileInfo",
",",
"err",
":=",
"os",
".",
"Lstat",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
... | // Write writes a file from disk into a tar file. | [
"Write",
"writes",
"a",
"file",
"from",
"disk",
"into",
"a",
"tar",
"file",
"."
] | 6e3da540444d5fdf37d385434447dcbc51e7d0cb | https://github.com/viniciuschiele-archive/tarx/blob/6e3da540444d5fdf37d385434447dcbc51e7d0cb/tarx.go#L489-L526 |
149,847 | dmcgowan/go-tar | writer.go | writePAXHeader | func (tw *Writer) writePAXHeader(hdr *Header, paxHeaders map[string]string) error {
// Prepare extended header
ext := new(Header)
ext.Typeflag = TypeXHeader
// Setting ModTime is required for reader parsing to
// succeed, and seems harmless enough.
ext.ModTime = hdr.ModTime
// The spec asks that we namespace our... | go | func (tw *Writer) writePAXHeader(hdr *Header, paxHeaders map[string]string) error {
// Prepare extended header
ext := new(Header)
ext.Typeflag = TypeXHeader
// Setting ModTime is required for reader parsing to
// succeed, and seems harmless enough.
ext.ModTime = hdr.ModTime
// The spec asks that we namespace our... | [
"func",
"(",
"tw",
"*",
"Writer",
")",
"writePAXHeader",
"(",
"hdr",
"*",
"Header",
",",
"paxHeaders",
"map",
"[",
"string",
"]",
"string",
")",
"error",
"{",
"// Prepare extended header",
"ext",
":=",
"new",
"(",
"Header",
")",
"\n",
"ext",
".",
"Typefl... | // writePaxHeader writes an extended pax header to the
// archive. | [
"writePaxHeader",
"writes",
"an",
"extended",
"pax",
"header",
"to",
"the",
"archive",
"."
] | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/writer.go#L275-L319 |
149,848 | dmcgowan/go-tar | reader.go | checkForGNUSparsePAXHeaders | func (tr *Reader) checkForGNUSparsePAXHeaders(hdr *Header, headers map[string]string) ([]sparseEntry, error) {
var sparseFormat string
// Check for sparse format indicators
major, majorOk := headers[paxGNUSparseMajor]
minor, minorOk := headers[paxGNUSparseMinor]
sparseName, sparseNameOk := headers[paxGNUSparseNam... | go | func (tr *Reader) checkForGNUSparsePAXHeaders(hdr *Header, headers map[string]string) ([]sparseEntry, error) {
var sparseFormat string
// Check for sparse format indicators
major, majorOk := headers[paxGNUSparseMajor]
minor, minorOk := headers[paxGNUSparseMinor]
sparseName, sparseNameOk := headers[paxGNUSparseNam... | [
"func",
"(",
"tr",
"*",
"Reader",
")",
"checkForGNUSparsePAXHeaders",
"(",
"hdr",
"*",
"Header",
",",
"headers",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"[",
"]",
"sparseEntry",
",",
"error",
")",
"{",
"var",
"sparseFormat",
"string",
"\n\n",
"// ... | // checkForGNUSparsePAXHeaders checks the PAX headers for GNU sparse headers. If they are found, then
// this function reads the sparse map and returns it. Unknown sparse formats are ignored, causing the file to
// be treated as a regular file. | [
"checkForGNUSparsePAXHeaders",
"checks",
"the",
"PAX",
"headers",
"for",
"GNU",
"sparse",
"headers",
".",
"If",
"they",
"are",
"found",
"then",
"this",
"function",
"reads",
"the",
"sparse",
"map",
"and",
"returns",
"it",
".",
"Unknown",
"sparse",
"formats",
"a... | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/reader.go#L233-L289 |
149,849 | dmcgowan/go-tar | reader.go | skipUnread | func (tr *Reader) skipUnread() error {
dataSkip := tr.numBytes() // Number of data bytes to skip
totalSkip := dataSkip + tr.pad // Total number of bytes to skip
tr.curr, tr.pad = nil, 0
// If possible, Seek to the last byte before the end of the data section.
// Do this because Seek is often lazy about repor... | go | func (tr *Reader) skipUnread() error {
dataSkip := tr.numBytes() // Number of data bytes to skip
totalSkip := dataSkip + tr.pad // Total number of bytes to skip
tr.curr, tr.pad = nil, 0
// If possible, Seek to the last byte before the end of the data section.
// Do this because Seek is often lazy about repor... | [
"func",
"(",
"tr",
"*",
"Reader",
")",
"skipUnread",
"(",
")",
"error",
"{",
"dataSkip",
":=",
"tr",
".",
"numBytes",
"(",
")",
"// Number of data bytes to skip",
"\n",
"totalSkip",
":=",
"dataSkip",
"+",
"tr",
".",
"pad",
"// Total number of bytes to skip",
"... | // skipUnread skips any unread bytes in the existing file entry, as well as any
// alignment padding. It returns io.ErrUnexpectedEOF if any io.EOF is
// encountered in the data portion; it is okay to hit io.EOF in the padding.
//
// Note that this function still works properly even when sparse files are being
// used s... | [
"skipUnread",
"skips",
"any",
"unread",
"bytes",
"in",
"the",
"existing",
"file",
"entry",
"as",
"well",
"as",
"any",
"alignment",
"padding",
".",
"It",
"returns",
"io",
".",
"ErrUnexpectedEOF",
"if",
"any",
"io",
".",
"EOF",
"is",
"encountered",
"in",
"th... | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/reader.go#L390-L421 |
149,850 | dmcgowan/go-tar | reader.go | numBytes | func (tr *Reader) numBytes() int64 {
if tr.curr == nil {
// No current file, so no bytes
return 0
}
return tr.curr.numBytes()
} | go | func (tr *Reader) numBytes() int64 {
if tr.curr == nil {
// No current file, so no bytes
return 0
}
return tr.curr.numBytes()
} | [
"func",
"(",
"tr",
"*",
"Reader",
")",
"numBytes",
"(",
")",
"int64",
"{",
"if",
"tr",
".",
"curr",
"==",
"nil",
"{",
"// No current file, so no bytes",
"return",
"0",
"\n",
"}",
"\n",
"return",
"tr",
".",
"curr",
".",
"numBytes",
"(",
")",
"\n",
"}"... | // numBytes returns the number of bytes left to read in the current file's entry
// in the tar archive, or 0 if there is no current file. | [
"numBytes",
"returns",
"the",
"number",
"of",
"bytes",
"left",
"to",
"read",
"in",
"the",
"current",
"file",
"s",
"entry",
"in",
"the",
"tar",
"archive",
"or",
"0",
"if",
"there",
"is",
"no",
"current",
"file",
"."
] | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/reader.go#L658-L664 |
149,851 | dmcgowan/go-tar | reader.go | newSparseFileReader | func newSparseFileReader(rfr numBytesReader, sp []sparseEntry, total int64) (*sparseFileReader, error) {
if total < 0 {
return nil, ErrHeader // Total size cannot be negative
}
// Validate all sparse entries. These are the same checks as performed by
// the BSD tar utility.
for i, s := range sp {
switch {
c... | go | func newSparseFileReader(rfr numBytesReader, sp []sparseEntry, total int64) (*sparseFileReader, error) {
if total < 0 {
return nil, ErrHeader // Total size cannot be negative
}
// Validate all sparse entries. These are the same checks as performed by
// the BSD tar utility.
for i, s := range sp {
switch {
c... | [
"func",
"newSparseFileReader",
"(",
"rfr",
"numBytesReader",
",",
"sp",
"[",
"]",
"sparseEntry",
",",
"total",
"int64",
")",
"(",
"*",
"sparseFileReader",
",",
"error",
")",
"{",
"if",
"total",
"<",
"0",
"{",
"return",
"nil",
",",
"ErrHeader",
"// Total si... | // newSparseFileReader creates a new sparseFileReader, but validates all of the
// sparse entries before doing so. | [
"newSparseFileReader",
"creates",
"a",
"new",
"sparseFileReader",
"but",
"validates",
"all",
"of",
"the",
"sparse",
"entries",
"before",
"doing",
"so",
"."
] | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/reader.go#L712-L732 |
149,852 | dmcgowan/go-tar | reader.go | readHole | func (sfr *sparseFileReader) readHole(b []byte, endOffset int64) int {
n64 := endOffset - sfr.pos
if n64 > int64(len(b)) {
n64 = int64(len(b))
}
n := int(n64)
for i := 0; i < n; i++ {
b[i] = 0
}
sfr.pos += n64
return n
} | go | func (sfr *sparseFileReader) readHole(b []byte, endOffset int64) int {
n64 := endOffset - sfr.pos
if n64 > int64(len(b)) {
n64 = int64(len(b))
}
n := int(n64)
for i := 0; i < n; i++ {
b[i] = 0
}
sfr.pos += n64
return n
} | [
"func",
"(",
"sfr",
"*",
"sparseFileReader",
")",
"readHole",
"(",
"b",
"[",
"]",
"byte",
",",
"endOffset",
"int64",
")",
"int",
"{",
"n64",
":=",
"endOffset",
"-",
"sfr",
".",
"pos",
"\n",
"if",
"n64",
">",
"int64",
"(",
"len",
"(",
"b",
")",
")... | // readHole reads a sparse hole ending at endOffset. | [
"readHole",
"reads",
"a",
"sparse",
"hole",
"ending",
"at",
"endOffset",
"."
] | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/reader.go#L735-L746 |
149,853 | dmcgowan/go-tar | reader.go | Read | func (sfr *sparseFileReader) Read(b []byte) (n int, err error) {
// Skip past all empty fragments.
for len(sfr.sp) > 0 && sfr.sp[0].numBytes == 0 {
sfr.sp = sfr.sp[1:]
}
// If there are no more fragments, then it is possible that there
// is one last sparse hole.
if len(sfr.sp) == 0 {
// This behavior matche... | go | func (sfr *sparseFileReader) Read(b []byte) (n int, err error) {
// Skip past all empty fragments.
for len(sfr.sp) > 0 && sfr.sp[0].numBytes == 0 {
sfr.sp = sfr.sp[1:]
}
// If there are no more fragments, then it is possible that there
// is one last sparse hole.
if len(sfr.sp) == 0 {
// This behavior matche... | [
"func",
"(",
"sfr",
"*",
"sparseFileReader",
")",
"Read",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"n",
"int",
",",
"err",
"error",
")",
"{",
"// Skip past all empty fragments.",
"for",
"len",
"(",
"sfr",
".",
"sp",
")",
">",
"0",
"&&",
"sfr",
".",
"s... | // Read reads the sparse file data in expanded form. | [
"Read",
"reads",
"the",
"sparse",
"file",
"data",
"in",
"expanded",
"form",
"."
] | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/reader.go#L749-L794 |
149,854 | ellcrys/go-libp2p-crypto | ed25519.go | Ed25519PrivateKeyFromPrivKey | func Ed25519PrivateKeyFromPrivKey(sk [64]byte) *Ed25519PrivateKey {
var pk [32]byte
copy(pk[:], sk[32:])
return &Ed25519PrivateKey{
sk: &sk,
pk: &pk,
}
} | go | func Ed25519PrivateKeyFromPrivKey(sk [64]byte) *Ed25519PrivateKey {
var pk [32]byte
copy(pk[:], sk[32:])
return &Ed25519PrivateKey{
sk: &sk,
pk: &pk,
}
} | [
"func",
"Ed25519PrivateKeyFromPrivKey",
"(",
"sk",
"[",
"64",
"]",
"byte",
")",
"*",
"Ed25519PrivateKey",
"{",
"var",
"pk",
"[",
"32",
"]",
"byte",
"\n\n",
"copy",
"(",
"pk",
"[",
":",
"]",
",",
"sk",
"[",
"32",
":",
"]",
")",
"\n",
"return",
"&",
... | // Ed25519PrivateKeyFromPrivKey creates an Ed25519PrivateKey from a 64 bytes private key | [
"Ed25519PrivateKeyFromPrivKey",
"creates",
"an",
"Ed25519PrivateKey",
"from",
"a",
"64",
"bytes",
"private",
"key"
] | 08bc4ca6778916abbeb103712423416289bb4c8d | https://github.com/ellcrys/go-libp2p-crypto/blob/08bc4ca6778916abbeb103712423416289bb4c8d/ed25519.go#L24-L32 |
149,855 | dmcgowan/go-tar | format.go | GetFormat | func (b *block) GetFormat() (format int) {
// Verify checksum.
var p parser
value := p.parseOctal(b.V7().Chksum())
chksum1, chksum2 := b.ComputeChecksum()
if p.err != nil || (value != chksum1 && value != chksum2) {
return formatUnknown
}
// Guess the magic values.
magic := string(b.USTAR().Magic())
version ... | go | func (b *block) GetFormat() (format int) {
// Verify checksum.
var p parser
value := p.parseOctal(b.V7().Chksum())
chksum1, chksum2 := b.ComputeChecksum()
if p.err != nil || (value != chksum1 && value != chksum2) {
return formatUnknown
}
// Guess the magic values.
magic := string(b.USTAR().Magic())
version ... | [
"func",
"(",
"b",
"*",
"block",
")",
"GetFormat",
"(",
")",
"(",
"format",
"int",
")",
"{",
"// Verify checksum.",
"var",
"p",
"parser",
"\n",
"value",
":=",
"p",
".",
"parseOctal",
"(",
"b",
".",
"V7",
"(",
")",
".",
"Chksum",
"(",
")",
")",
"\n... | // GetFormat checks that the block is a valid tar header based on the checksum.
// It then attempts to guess the specific format based on magic values.
// If the checksum fails, then formatUnknown is returned. | [
"GetFormat",
"checks",
"that",
"the",
"block",
"is",
"a",
"valid",
"tar",
"header",
"based",
"on",
"the",
"checksum",
".",
"It",
"then",
"attempts",
"to",
"guess",
"the",
"specific",
"format",
"based",
"on",
"magic",
"values",
".",
"If",
"the",
"checksum",... | 2e2c51242e8993c50445dab7c03c8e7febddd0cf | https://github.com/dmcgowan/go-tar/blob/2e2c51242e8993c50445dab7c03c8e7febddd0cf/format.go#L67-L90 |
149,856 | jacobsa/timeutil | clock.go | SetTime | func (sc *SimulatedClock) SetTime(t time.Time) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.t = t
} | go | func (sc *SimulatedClock) SetTime(t time.Time) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.t = t
} | [
"func",
"(",
"sc",
"*",
"SimulatedClock",
")",
"SetTime",
"(",
"t",
"time",
".",
"Time",
")",
"{",
"sc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"sc",
".",
"t",
"=",
"t",
"\n",
"}"
] | // Set the current time according to the clock. | [
"Set",
"the",
"current",
"time",
"according",
"to",
"the",
"clock",
"."
] | 577e5acbbcf60f68c80c6f5edfeefe50e477c853 | https://github.com/jacobsa/timeutil/blob/577e5acbbcf60f68c80c6f5edfeefe50e477c853/clock.go#L63-L68 |
149,857 | jacobsa/timeutil | clock.go | AdvanceTime | func (sc *SimulatedClock) AdvanceTime(d time.Duration) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.t = sc.t.Add(d)
} | go | func (sc *SimulatedClock) AdvanceTime(d time.Duration) {
sc.mu.Lock()
defer sc.mu.Unlock()
sc.t = sc.t.Add(d)
} | [
"func",
"(",
"sc",
"*",
"SimulatedClock",
")",
"AdvanceTime",
"(",
"d",
"time",
".",
"Duration",
")",
"{",
"sc",
".",
"mu",
".",
"Lock",
"(",
")",
"\n",
"defer",
"sc",
".",
"mu",
".",
"Unlock",
"(",
")",
"\n\n",
"sc",
".",
"t",
"=",
"sc",
".",
... | // Advance the current time according to the clock by the supplied duration. | [
"Advance",
"the",
"current",
"time",
"according",
"to",
"the",
"clock",
"by",
"the",
"supplied",
"duration",
"."
] | 577e5acbbcf60f68c80c6f5edfeefe50e477c853 | https://github.com/jacobsa/timeutil/blob/577e5acbbcf60f68c80c6f5edfeefe50e477c853/clock.go#L71-L76 |
149,858 | uluyol/hdrhist | zigzag.go | decodeZigZag | func decodeZigZag(b []byte) (v int64, vlen int, err error) {
defer func() {
if e := recover(); e != nil {
err = errors.New("got incomplete data")
}
}()
v, vlen = decodeZigZagUnsafe(b)
return v, vlen, nil
} | go | func decodeZigZag(b []byte) (v int64, vlen int, err error) {
defer func() {
if e := recover(); e != nil {
err = errors.New("got incomplete data")
}
}()
v, vlen = decodeZigZagUnsafe(b)
return v, vlen, nil
} | [
"func",
"decodeZigZag",
"(",
"b",
"[",
"]",
"byte",
")",
"(",
"v",
"int64",
",",
"vlen",
"int",
",",
"err",
"error",
")",
"{",
"defer",
"func",
"(",
")",
"{",
"if",
"e",
":=",
"recover",
"(",
")",
";",
"e",
"!=",
"nil",
"{",
"err",
"=",
"erro... | // decodeZigZag safely catch bounds errors due to
// missing data. | [
"decodeZigZag",
"safely",
"catch",
"bounds",
"errors",
"due",
"to",
"missing",
"data",
"."
] | dce39abb184532191bde663c52c6b13dda06c7a4 | https://github.com/uluyol/hdrhist/blob/dce39abb184532191bde663c52c6b13dda06c7a4/zigzag.go#L122-L131 |
149,859 | ethanfrey/ledger | wrapper.go | WrapCommandAPDU | func WrapCommandAPDU(channel uint16, command []byte, packetSize int, ble bool) []byte {
if packetSize < 3 {
panic("packet size must be at least 3")
}
var sequenceIdx uint16
var offset, extraHeaderSize, blockSize int
var result = make([]byte, 64)
var buf = result
if !ble {
codec.PutUint16(buf, channel)
ex... | go | func WrapCommandAPDU(channel uint16, command []byte, packetSize int, ble bool) []byte {
if packetSize < 3 {
panic("packet size must be at least 3")
}
var sequenceIdx uint16
var offset, extraHeaderSize, blockSize int
var result = make([]byte, 64)
var buf = result
if !ble {
codec.PutUint16(buf, channel)
ex... | [
"func",
"WrapCommandAPDU",
"(",
"channel",
"uint16",
",",
"command",
"[",
"]",
"byte",
",",
"packetSize",
"int",
",",
"ble",
"bool",
")",
"[",
"]",
"byte",
"{",
"if",
"packetSize",
"<",
"3",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"v... | // WrapCommandAPDU turns the command into a sequence of 64 byte packets | [
"WrapCommandAPDU",
"turns",
"the",
"command",
"into",
"a",
"sequence",
"of",
"64",
"byte",
"packets"
] | f7f2f056357db77db845a79aa1abdadc3ae66369 | https://github.com/ethanfrey/ledger/blob/f7f2f056357db77db845a79aa1abdadc3ae66369/wrapper.go#L11-L57 |
149,860 | ethanfrey/ledger | wrapper.go | UnwrapResponseAPDU | func UnwrapResponseAPDU(channel uint16, dev <-chan []byte, packetSize int, ble bool) ([]byte, error) {
var err error
var sequenceIdx uint16
var extraHeaderSize int
if !ble {
extraHeaderSize = 2
}
buf := <-dev
if len(buf) < 5+extraHeaderSize+5 {
return nil, errTooShort
}
buf, err = validatePrefix(buf, chan... | go | func UnwrapResponseAPDU(channel uint16, dev <-chan []byte, packetSize int, ble bool) ([]byte, error) {
var err error
var sequenceIdx uint16
var extraHeaderSize int
if !ble {
extraHeaderSize = 2
}
buf := <-dev
if len(buf) < 5+extraHeaderSize+5 {
return nil, errTooShort
}
buf, err = validatePrefix(buf, chan... | [
"func",
"UnwrapResponseAPDU",
"(",
"channel",
"uint16",
",",
"dev",
"<-",
"chan",
"[",
"]",
"byte",
",",
"packetSize",
"int",
",",
"ble",
"bool",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"sequenceIdx",
"... | // UnwrapResponseAPDU parses a response of 64 byte packets into the real data | [
"UnwrapResponseAPDU",
"parses",
"a",
"response",
"of",
"64",
"byte",
"packets",
"into",
"the",
"real",
"data"
] | f7f2f056357db77db845a79aa1abdadc3ae66369 | https://github.com/ethanfrey/ledger/blob/f7f2f056357db77db845a79aa1abdadc3ae66369/wrapper.go#L84-L130 |
149,861 | mcuadros/go-crxmake | crxmake.go | BuildZip | func (b *Builder) BuildZip(folder string) error {
w := zip.NewWriter(b.Content)
defer w.Close()
if err := b.generateKeyIfNeeded(); err != nil {
return err
}
keyFile, err := w.Create(keyFilename)
if err != nil {
return err
}
size, err := b.saveKeyFile(keyFile)
if err != nil {
return err
}
fmt.Printf... | go | func (b *Builder) BuildZip(folder string) error {
w := zip.NewWriter(b.Content)
defer w.Close()
if err := b.generateKeyIfNeeded(); err != nil {
return err
}
keyFile, err := w.Create(keyFilename)
if err != nil {
return err
}
size, err := b.saveKeyFile(keyFile)
if err != nil {
return err
}
fmt.Printf... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"BuildZip",
"(",
"folder",
"string",
")",
"error",
"{",
"w",
":=",
"zip",
".",
"NewWriter",
"(",
"b",
".",
"Content",
")",
"\n",
"defer",
"w",
".",
"Close",
"(",
")",
"\n\n",
"if",
"err",
":=",
"b",
".",
"... | // BuildZip loades the given folder and include all the files on the zip. | [
"BuildZip",
"loades",
"the",
"given",
"folder",
"and",
"include",
"all",
"the",
"files",
"on",
"the",
"zip",
"."
] | 424fb388cc708a948fce697aaf80fa62055cdb54 | https://github.com/mcuadros/go-crxmake/blob/424fb388cc708a948fce697aaf80fa62055cdb54/crxmake.go#L63-L117 |
149,862 | mcuadros/go-crxmake | crxmake.go | WriteToFile | func (b *Builder) WriteToFile(w io.Writer) error {
if _, err := w.Write(header); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, version); err != nil {
return err
}
key, signature, err := b.signContent()
if err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian... | go | func (b *Builder) WriteToFile(w io.Writer) error {
if _, err := w.Write(header); err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian, version); err != nil {
return err
}
key, signature, err := b.signContent()
if err != nil {
return err
}
if err := binary.Write(w, binary.LittleEndian... | [
"func",
"(",
"b",
"*",
"Builder",
")",
"WriteToFile",
"(",
"w",
"io",
".",
"Writer",
")",
"error",
"{",
"if",
"_",
",",
"err",
":=",
"w",
".",
"Write",
"(",
"header",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
... | // WriteToFile writes the generated CRX file. | [
"WriteToFile",
"writes",
"the",
"generated",
"CRX",
"file",
"."
] | 424fb388cc708a948fce697aaf80fa62055cdb54 | https://github.com/mcuadros/go-crxmake/blob/424fb388cc708a948fce697aaf80fa62055cdb54/crxmake.go#L141-L176 |
149,863 | deiwin/interact | confirm.go | Confirm | func (a Actor) Confirm(message string, def ConfirmDefault) (confirmed bool, err error) {
for {
confirmed, err := a.confirmOnce(message, def)
if err == errNoOptionSelected {
fmt.Fprintln(a.w, err)
continue
}
return confirmed, err
}
} | go | func (a Actor) Confirm(message string, def ConfirmDefault) (confirmed bool, err error) {
for {
confirmed, err := a.confirmOnce(message, def)
if err == errNoOptionSelected {
fmt.Fprintln(a.w, err)
continue
}
return confirmed, err
}
} | [
"func",
"(",
"a",
"Actor",
")",
"Confirm",
"(",
"message",
"string",
",",
"def",
"ConfirmDefault",
")",
"(",
"confirmed",
"bool",
",",
"err",
"error",
")",
"{",
"for",
"{",
"confirmed",
",",
"err",
":=",
"a",
".",
"confirmOnce",
"(",
"message",
",",
... | // Confirm provides the message to the user and asks yes or no. If the user
// doesn't select either of the possible answers they will be prompted to answer
// again until they do | [
"Confirm",
"provides",
"the",
"message",
"to",
"the",
"user",
"and",
"asks",
"yes",
"or",
"no",
".",
"If",
"the",
"user",
"doesn",
"t",
"select",
"either",
"of",
"the",
"possible",
"answers",
"they",
"will",
"be",
"prompted",
"to",
"answer",
"again",
"un... | 720596b65af849cd820b6f6acaaf94cfe65516e4 | https://github.com/deiwin/interact/blob/720596b65af849cd820b6f6acaaf94cfe65516e4/confirm.go#L27-L36 |
149,864 | deiwin/interact | input.go | PromptAndRetry | func (a Actor) PromptAndRetry(message string, checks ...InputCheck) (string, error) {
for {
input, err := a.Prompt(message, checks...)
if err != nil {
if err = a.confirmRetry(err); err != nil {
return "", err
}
continue
}
return input, nil
}
} | go | func (a Actor) PromptAndRetry(message string, checks ...InputCheck) (string, error) {
for {
input, err := a.Prompt(message, checks...)
if err != nil {
if err = a.confirmRetry(err); err != nil {
return "", err
}
continue
}
return input, nil
}
} | [
"func",
"(",
"a",
"Actor",
")",
"PromptAndRetry",
"(",
"message",
"string",
",",
"checks",
"...",
"InputCheck",
")",
"(",
"string",
",",
"error",
")",
"{",
"for",
"{",
"input",
",",
"err",
":=",
"a",
".",
"Prompt",
"(",
"message",
",",
"checks",
"...... | // PromptAndRetry asks the user for input and performs the list of added checks
// on the provided input. If any of the checks fail to pass the error will be
// displayed to the user and they will then be asked if they want to try again.
// If the user does not want to retry the program will return an error. | [
"PromptAndRetry",
"asks",
"the",
"user",
"for",
"input",
"and",
"performs",
"the",
"list",
"of",
"added",
"checks",
"on",
"the",
"provided",
"input",
".",
"If",
"any",
"of",
"the",
"checks",
"fail",
"to",
"pass",
"the",
"error",
"will",
"be",
"displayed",
... | 720596b65af849cd820b6f6acaaf94cfe65516e4 | https://github.com/deiwin/interact/blob/720596b65af849cd820b6f6acaaf94cfe65516e4/input.go#L20-L31 |
149,865 | deiwin/interact | input.go | PromptOptionalAndRetry | func (a Actor) PromptOptionalAndRetry(message, defaultOption string, checks ...InputCheck) (string, error) {
for {
input, err := a.PromptOptional(message, defaultOption, checks...)
if err != nil {
if err = a.confirmRetry(err); err != nil {
return "", err
}
continue
}
return input, nil
}
} | go | func (a Actor) PromptOptionalAndRetry(message, defaultOption string, checks ...InputCheck) (string, error) {
for {
input, err := a.PromptOptional(message, defaultOption, checks...)
if err != nil {
if err = a.confirmRetry(err); err != nil {
return "", err
}
continue
}
return input, nil
}
} | [
"func",
"(",
"a",
"Actor",
")",
"PromptOptionalAndRetry",
"(",
"message",
",",
"defaultOption",
"string",
",",
"checks",
"...",
"InputCheck",
")",
"(",
"string",
",",
"error",
")",
"{",
"for",
"{",
"input",
",",
"err",
":=",
"a",
".",
"PromptOptional",
"... | // PromptOptionalAndRetry works exactly like GetInputAndRetry, but also has
// a default option which will be used instead if the user simply presses enter. | [
"PromptOptionalAndRetry",
"works",
"exactly",
"like",
"GetInputAndRetry",
"but",
"also",
"has",
"a",
"default",
"option",
"which",
"will",
"be",
"used",
"instead",
"if",
"the",
"user",
"simply",
"presses",
"enter",
"."
] | 720596b65af849cd820b6f6acaaf94cfe65516e4 | https://github.com/deiwin/interact/blob/720596b65af849cd820b6f6acaaf94cfe65516e4/input.go#L35-L46 |
149,866 | deiwin/interact | input.go | Prompt | func (a Actor) Prompt(message string, checks ...InputCheck) (string, error) {
input, err := a.prompt(message + ": ")
if err != nil {
return "", err
}
err = runChecks(input, checks...)
if err != nil {
return "", err
}
return input, nil
} | go | func (a Actor) Prompt(message string, checks ...InputCheck) (string, error) {
input, err := a.prompt(message + ": ")
if err != nil {
return "", err
}
err = runChecks(input, checks...)
if err != nil {
return "", err
}
return input, nil
} | [
"func",
"(",
"a",
"Actor",
")",
"Prompt",
"(",
"message",
"string",
",",
"checks",
"...",
"InputCheck",
")",
"(",
"string",
",",
"error",
")",
"{",
"input",
",",
"err",
":=",
"a",
".",
"prompt",
"(",
"message",
"+",
"\"",
"\"",
")",
"\n",
"if",
"... | // Prompt asks the user for input and performs the list of added checks on the
// provided input. If any of the checks fail, the error will be returned. | [
"Prompt",
"asks",
"the",
"user",
"for",
"input",
"and",
"performs",
"the",
"list",
"of",
"added",
"checks",
"on",
"the",
"provided",
"input",
".",
"If",
"any",
"of",
"the",
"checks",
"fail",
"the",
"error",
"will",
"be",
"returned",
"."
] | 720596b65af849cd820b6f6acaaf94cfe65516e4 | https://github.com/deiwin/interact/blob/720596b65af849cd820b6f6acaaf94cfe65516e4/input.go#L50-L60 |
149,867 | deiwin/interact | input.go | PromptOptional | func (a Actor) PromptOptional(message, defaultOption string, checks ...InputCheck) (string, error) {
input, err := a.prompt(fmt.Sprintf("%s: (%s) ", message, defaultOption))
if err != nil {
return "", err
}
if input == "" {
return defaultOption, nil
}
err = runChecks(input, checks...)
if err != nil {
retur... | go | func (a Actor) PromptOptional(message, defaultOption string, checks ...InputCheck) (string, error) {
input, err := a.prompt(fmt.Sprintf("%s: (%s) ", message, defaultOption))
if err != nil {
return "", err
}
if input == "" {
return defaultOption, nil
}
err = runChecks(input, checks...)
if err != nil {
retur... | [
"func",
"(",
"a",
"Actor",
")",
"PromptOptional",
"(",
"message",
",",
"defaultOption",
"string",
",",
"checks",
"...",
"InputCheck",
")",
"(",
"string",
",",
"error",
")",
"{",
"input",
",",
"err",
":=",
"a",
".",
"prompt",
"(",
"fmt",
".",
"Sprintf",... | // PromptOptional works exactly like Prompt, but also has a default option
// which will be used instead if the user simply presses enter. | [
"PromptOptional",
"works",
"exactly",
"like",
"Prompt",
"but",
"also",
"has",
"a",
"default",
"option",
"which",
"will",
"be",
"used",
"instead",
"if",
"the",
"user",
"simply",
"presses",
"enter",
"."
] | 720596b65af849cd820b6f6acaaf94cfe65516e4 | https://github.com/deiwin/interact/blob/720596b65af849cd820b6f6acaaf94cfe65516e4/input.go#L64-L77 |
149,868 | deiwin/interact | actor.go | NewActor | func NewActor(rd io.Reader, w io.Writer) Actor {
return Actor{bufio.NewReader(rd), w}
} | go | func NewActor(rd io.Reader, w io.Writer) Actor {
return Actor{bufio.NewReader(rd), w}
} | [
"func",
"NewActor",
"(",
"rd",
"io",
".",
"Reader",
",",
"w",
"io",
".",
"Writer",
")",
"Actor",
"{",
"return",
"Actor",
"{",
"bufio",
".",
"NewReader",
"(",
"rd",
")",
",",
"w",
"}",
"\n",
"}"
] | // NewActor creates a new Actor instance with the specified io.Reader | [
"NewActor",
"creates",
"a",
"new",
"Actor",
"instance",
"with",
"the",
"specified",
"io",
".",
"Reader"
] | 720596b65af849cd820b6f6acaaf94cfe65516e4 | https://github.com/deiwin/interact/blob/720596b65af849cd820b6f6acaaf94cfe65516e4/actor.go#L16-L18 |
149,869 | natefinch/deputy | deputy.go | Run | func (d Deputy) Run(cmd *exec.Cmd) error {
if err := d.makePipes(cmd); err != nil {
return err
}
errsrc := &bytes.Buffer{}
if d.Errors == FromStderr {
cmd.Stderr = dualWriter(cmd.Stderr, errsrc)
}
if d.Errors == FromStdout {
cmd.Stdout = dualWriter(cmd.Stdout, errsrc)
}
err := d.run(cmd)
if d.Errors =... | go | func (d Deputy) Run(cmd *exec.Cmd) error {
if err := d.makePipes(cmd); err != nil {
return err
}
errsrc := &bytes.Buffer{}
if d.Errors == FromStderr {
cmd.Stderr = dualWriter(cmd.Stderr, errsrc)
}
if d.Errors == FromStdout {
cmd.Stdout = dualWriter(cmd.Stdout, errsrc)
}
err := d.run(cmd)
if d.Errors =... | [
"func",
"(",
"d",
"Deputy",
")",
"Run",
"(",
"cmd",
"*",
"exec",
".",
"Cmd",
")",
"error",
"{",
"if",
"err",
":=",
"d",
".",
"makePipes",
"(",
"cmd",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"errsrc",
":=",
"&",
... | // Run starts the specified command and waits for it to complete. Its behavior
// conforms to the Options passed to it at construction time.
//
// Note that, like cmd.Run, Deputy.Run should not be used with
// StdoutPipe or StderrPipe. | [
"Run",
"starts",
"the",
"specified",
"command",
"and",
"waits",
"for",
"it",
"to",
"complete",
".",
"Its",
"behavior",
"conforms",
"to",
"the",
"Options",
"passed",
"to",
"it",
"at",
"construction",
"time",
".",
"Note",
"that",
"like",
"cmd",
".",
"Run",
... | 5e10e7deaf1c0400371eadef102f28f82e5aaa53 | https://github.com/natefinch/deputy/blob/5e10e7deaf1c0400371eadef102f28f82e5aaa53/deputy.go#L56-L79 |
149,870 | brettbuddin/musictheory | note.go | Dotted | func Dotted(d Duration, dots int) Duration {
return Duration{d.Value, dots, false}
} | go | func Dotted(d Duration, dots int) Duration {
return Duration{d.Value, dots, false}
} | [
"func",
"Dotted",
"(",
"d",
"Duration",
",",
"dots",
"int",
")",
"Duration",
"{",
"return",
"Duration",
"{",
"d",
".",
"Value",
",",
"dots",
",",
"false",
"}",
"\n",
"}"
] | // Dotted makes a dotted duration | [
"Dotted",
"makes",
"a",
"dotted",
"duration"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/note.go#L9-L11 |
149,871 | brettbuddin/musictheory | note.go | Time | func (d Duration) Time(unit Duration, bpm int) time.Duration {
val := (60.0 / float64(bpm)) / (float64(d.Value) / 4.0) / (float64(unit.Value) / 4.0)
for i := 0; i < d.Dots; i++ {
val += val / 2.0
}
if d.Triplet {
val = val / 3.0
}
return time.Duration(val * ns)
} | go | func (d Duration) Time(unit Duration, bpm int) time.Duration {
val := (60.0 / float64(bpm)) / (float64(d.Value) / 4.0) / (float64(unit.Value) / 4.0)
for i := 0; i < d.Dots; i++ {
val += val / 2.0
}
if d.Triplet {
val = val / 3.0
}
return time.Duration(val * ns)
} | [
"func",
"(",
"d",
"Duration",
")",
"Time",
"(",
"unit",
"Duration",
",",
"bpm",
"int",
")",
"time",
".",
"Duration",
"{",
"val",
":=",
"(",
"60.0",
"/",
"float64",
"(",
"bpm",
")",
")",
"/",
"(",
"float64",
"(",
"d",
".",
"Value",
")",
"/",
"4.... | // Time returns the time in nanoseconds the note's duration lasts.
// Calculated based on what unit gets the beat and what the BPM is. | [
"Time",
"returns",
"the",
"time",
"in",
"nanoseconds",
"the",
"note",
"s",
"duration",
"lasts",
".",
"Calculated",
"based",
"on",
"what",
"unit",
"gets",
"the",
"beat",
"and",
"what",
"the",
"BPM",
"is",
"."
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/note.go#L41-L53 |
149,872 | brettbuddin/musictheory | note.go | Transpose | func (n Note) Transpose(i Interval) Note {
return Note{n.Pitch.Transpose(i), n.Duration}
} | go | func (n Note) Transpose(i Interval) Note {
return Note{n.Pitch.Transpose(i), n.Duration}
} | [
"func",
"(",
"n",
"Note",
")",
"Transpose",
"(",
"i",
"Interval",
")",
"Note",
"{",
"return",
"Note",
"{",
"n",
".",
"Pitch",
".",
"Transpose",
"(",
"i",
")",
",",
"n",
".",
"Duration",
"}",
"\n",
"}"
] | // Transpose transposes a note by a given interval | [
"Transpose",
"transposes",
"a",
"note",
"by",
"a",
"given",
"interval"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/note.go#L103-L105 |
149,873 | brettbuddin/musictheory | scale.go | Transpose | func (s Scale) Transpose(i Interval) Scale {
scale := Scale{}
for _, transposer := range s {
scale = append(scale, transposer.Transpose(i))
}
return scale
} | go | func (s Scale) Transpose(i Interval) Scale {
scale := Scale{}
for _, transposer := range s {
scale = append(scale, transposer.Transpose(i))
}
return scale
} | [
"func",
"(",
"s",
"Scale",
")",
"Transpose",
"(",
"i",
"Interval",
")",
"Scale",
"{",
"scale",
":=",
"Scale",
"{",
"}",
"\n",
"for",
"_",
",",
"transposer",
":=",
"range",
"s",
"{",
"scale",
"=",
"append",
"(",
"scale",
",",
"transposer",
".",
"Tra... | // Transpose transposes a scale by the specified Interval | [
"Transpose",
"transposes",
"a",
"scale",
"by",
"the",
"specified",
"Interval"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/scale.go#L7-L13 |
149,874 | brettbuddin/musictheory | scale.go | NewScale | func NewScale(root Pitch, intervals []Interval, octaves int) Scale {
var (
scale = Scale{}
originalRoot = root
descending = (octaves < 0)
)
// Begin at the base of our octave shift
if descending {
root = root.Transpose(Octave(octaves))
}
for i := 0; i < abs(octaves); i++ {
for j, v := range i... | go | func NewScale(root Pitch, intervals []Interval, octaves int) Scale {
var (
scale = Scale{}
originalRoot = root
descending = (octaves < 0)
)
// Begin at the base of our octave shift
if descending {
root = root.Transpose(Octave(octaves))
}
for i := 0; i < abs(octaves); i++ {
for j, v := range i... | [
"func",
"NewScale",
"(",
"root",
"Pitch",
",",
"intervals",
"[",
"]",
"Interval",
",",
"octaves",
"int",
")",
"Scale",
"{",
"var",
"(",
"scale",
"=",
"Scale",
"{",
"}",
"\n",
"originalRoot",
"=",
"root",
"\n",
"descending",
"=",
"(",
"octaves",
"<",
... | // NewScale returns a Scale built using a set of intervals | [
"NewScale",
"returns",
"a",
"Scale",
"built",
"using",
"a",
"set",
"of",
"intervals"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/scale.go#L16-L53 |
149,875 | brettbuddin/musictheory | pitch.go | NewPitch | func NewPitch(diatonic, modifier, octaves int) Pitch {
return Pitch{NewInterval(diatonic, octaves, modifier)}
} | go | func NewPitch(diatonic, modifier, octaves int) Pitch {
return Pitch{NewInterval(diatonic, octaves, modifier)}
} | [
"func",
"NewPitch",
"(",
"diatonic",
",",
"modifier",
",",
"octaves",
"int",
")",
"Pitch",
"{",
"return",
"Pitch",
"{",
"NewInterval",
"(",
"diatonic",
",",
"octaves",
",",
"modifier",
")",
"}",
"\n",
"}"
] | // NewPitch builds a new Pitch | [
"NewPitch",
"builds",
"a",
"new",
"Pitch"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/pitch.go#L50-L52 |
149,876 | brettbuddin/musictheory | pitch.go | Transpose | func (p Pitch) Transpose(i Interval) Pitch {
return Pitch{p.Interval.Transpose(i)}
} | go | func (p Pitch) Transpose(i Interval) Pitch {
return Pitch{p.Interval.Transpose(i)}
} | [
"func",
"(",
"p",
"Pitch",
")",
"Transpose",
"(",
"i",
"Interval",
")",
"Pitch",
"{",
"return",
"Pitch",
"{",
"p",
".",
"Interval",
".",
"Transpose",
"(",
"i",
")",
"}",
"\n",
"}"
] | // Transpose transposes a pitch by a given interval | [
"Transpose",
"transposes",
"a",
"pitch",
"by",
"a",
"given",
"interval"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/pitch.go#L78-L80 |
149,877 | brettbuddin/musictheory | pitch.go | Eq | func (p Pitch) Eq(o Pitch) bool {
return p.Interval.Eq(o.Interval)
} | go | func (p Pitch) Eq(o Pitch) bool {
return p.Interval.Eq(o.Interval)
} | [
"func",
"(",
"p",
"Pitch",
")",
"Eq",
"(",
"o",
"Pitch",
")",
"bool",
"{",
"return",
"p",
".",
"Interval",
".",
"Eq",
"(",
"o",
".",
"Interval",
")",
"\n",
"}"
] | // Eq determines if another pitch is the same | [
"Eq",
"determines",
"if",
"another",
"pitch",
"is",
"the",
"same"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/pitch.go#L83-L85 |
149,878 | brettbuddin/musictheory | pitch.go | Freq | func (p Pitch) Freq() float64 {
return concertFrequency * math.Pow(semitone, float64(p.Semitones()-middleA.Semitones()))
} | go | func (p Pitch) Freq() float64 {
return concertFrequency * math.Pow(semitone, float64(p.Semitones()-middleA.Semitones()))
} | [
"func",
"(",
"p",
"Pitch",
")",
"Freq",
"(",
")",
"float64",
"{",
"return",
"concertFrequency",
"*",
"math",
".",
"Pow",
"(",
"semitone",
",",
"float64",
"(",
"p",
".",
"Semitones",
"(",
")",
"-",
"middleA",
".",
"Semitones",
"(",
")",
")",
")",
"\... | // Freq returns the absolute frequency of a pitch in Hz | [
"Freq",
"returns",
"the",
"absolute",
"frequency",
"of",
"a",
"pitch",
"in",
"Hz"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/pitch.go#L88-L90 |
149,879 | brettbuddin/musictheory | pitch.go | NearestPitch | func NearestPitch(f float64) Pitch {
x := 12 * (math.Log2(f / concertFrequency))
if x < 0 {
x = math.Ceil(x - 0.5)
} else {
x = math.Floor(x + 0.5)
}
if x == 0 {
return middleA
}
return middleA.Transpose(Semitones(int(x)))
} | go | func NearestPitch(f float64) Pitch {
x := 12 * (math.Log2(f / concertFrequency))
if x < 0 {
x = math.Ceil(x - 0.5)
} else {
x = math.Floor(x + 0.5)
}
if x == 0 {
return middleA
}
return middleA.Transpose(Semitones(int(x)))
} | [
"func",
"NearestPitch",
"(",
"f",
"float64",
")",
"Pitch",
"{",
"x",
":=",
"12",
"*",
"(",
"math",
".",
"Log2",
"(",
"f",
"/",
"concertFrequency",
")",
")",
"\n",
"if",
"x",
"<",
"0",
"{",
"x",
"=",
"math",
".",
"Ceil",
"(",
"x",
"-",
"0.5",
... | // NearestPitch returns the closest pitch to an arbitrary frequency | [
"NearestPitch",
"returns",
"the",
"closest",
"pitch",
"to",
"an",
"arbitrary",
"frequency"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/pitch.go#L106-L117 |
149,880 | brettbuddin/musictheory | chord.go | NewChord | func NewChord(root Pitch, intervals []Interval) Chord {
c := Chord{}
for _, v := range intervals {
c = append(c, root.Transpose(v))
}
return c
} | go | func NewChord(root Pitch, intervals []Interval) Chord {
c := Chord{}
for _, v := range intervals {
c = append(c, root.Transpose(v))
}
return c
} | [
"func",
"NewChord",
"(",
"root",
"Pitch",
",",
"intervals",
"[",
"]",
"Interval",
")",
"Chord",
"{",
"c",
":=",
"Chord",
"{",
"}",
"\n",
"for",
"_",
",",
"v",
":=",
"range",
"intervals",
"{",
"c",
"=",
"append",
"(",
"c",
",",
"root",
".",
"Trans... | // NewChord returns a new Chord with a specific set of intervals | [
"NewChord",
"returns",
"a",
"new",
"Chord",
"with",
"a",
"specific",
"set",
"of",
"intervals"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/chord.go#L7-L13 |
149,881 | brettbuddin/musictheory | chord.go | Transpose | func (c Chord) Transpose(i Interval) Chord {
chord := Chord{}
for _, p := range c {
chord = append(chord, p.Transpose(i))
}
return chord
} | go | func (c Chord) Transpose(i Interval) Chord {
chord := Chord{}
for _, p := range c {
chord = append(chord, p.Transpose(i))
}
return chord
} | [
"func",
"(",
"c",
"Chord",
")",
"Transpose",
"(",
"i",
"Interval",
")",
"Chord",
"{",
"chord",
":=",
"Chord",
"{",
"}",
"\n",
"for",
"_",
",",
"p",
":=",
"range",
"c",
"{",
"chord",
"=",
"append",
"(",
"chord",
",",
"p",
".",
"Transpose",
"(",
... | // Transpose transposes the Chord | [
"Transpose",
"transposes",
"the",
"Chord"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/chord.go#L16-L22 |
149,882 | brettbuddin/musictheory | chord.go | Invert | func (c Chord) Invert(degree int) Chord {
octaves := degree / len(c)
pos := degree % len(c)
chord := Chord{}
for _, p := range c[pos:] {
if octaves > 0 {
p = p.Transpose(Octave(octaves))
}
chord = append(chord, p)
}
for _, p := range c[:pos] {
chord = append(chord, p.Transpose(Octave(octaves+1)))
}
... | go | func (c Chord) Invert(degree int) Chord {
octaves := degree / len(c)
pos := degree % len(c)
chord := Chord{}
for _, p := range c[pos:] {
if octaves > 0 {
p = p.Transpose(Octave(octaves))
}
chord = append(chord, p)
}
for _, p := range c[:pos] {
chord = append(chord, p.Transpose(Octave(octaves+1)))
}
... | [
"func",
"(",
"c",
"Chord",
")",
"Invert",
"(",
"degree",
"int",
")",
"Chord",
"{",
"octaves",
":=",
"degree",
"/",
"len",
"(",
"c",
")",
"\n",
"pos",
":=",
"degree",
"%",
"len",
"(",
"c",
")",
"\n\n",
"chord",
":=",
"Chord",
"{",
"}",
"\n",
"fo... | // Invert performs a chord inversion of some degree | [
"Invert",
"performs",
"a",
"chord",
"inversion",
"of",
"some",
"degree"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/chord.go#L25-L40 |
149,883 | brettbuddin/musictheory | interval.go | Semitones | func Semitones(step int) Interval {
normal := normalizeChromatic(step)
return Interval{chromaticOctaves(step), chromaticToDiatonic(normal), normal}
} | go | func Semitones(step int) Interval {
normal := normalizeChromatic(step)
return Interval{chromaticOctaves(step), chromaticToDiatonic(normal), normal}
} | [
"func",
"Semitones",
"(",
"step",
"int",
")",
"Interval",
"{",
"normal",
":=",
"normalizeChromatic",
"(",
"step",
")",
"\n",
"return",
"Interval",
"{",
"chromaticOctaves",
"(",
"step",
")",
",",
"chromaticToDiatonic",
"(",
"normal",
")",
",",
"normal",
"}",
... | // Semitones is an interval using direct semitones | [
"Semitones",
"is",
"an",
"interval",
"using",
"direct",
"semitones"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L61-L64 |
149,884 | brettbuddin/musictheory | interval.go | NewInterval | func NewInterval(step, octaves, offset int) Interval {
diatonic := normalizeDiatonic(step - 1)
chromatic := diatonicToChromatic(diatonic) + offset
return Interval{octaves, diatonic, chromatic}
} | go | func NewInterval(step, octaves, offset int) Interval {
diatonic := normalizeDiatonic(step - 1)
chromatic := diatonicToChromatic(diatonic) + offset
return Interval{octaves, diatonic, chromatic}
} | [
"func",
"NewInterval",
"(",
"step",
",",
"octaves",
",",
"offset",
"int",
")",
"Interval",
"{",
"diatonic",
":=",
"normalizeDiatonic",
"(",
"step",
"-",
"1",
")",
"\n",
"chromatic",
":=",
"diatonicToChromatic",
"(",
"diatonic",
")",
"+",
"offset",
"\n\n",
... | // NewInterval builds a new Interval | [
"NewInterval",
"builds",
"a",
"new",
"Interval"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L82-L87 |
149,885 | brettbuddin/musictheory | interval.go | Quality | func (i Interval) Quality() Quality {
quality := diffQuality(i.Chromatic-diatonicToChromatic(i.Diatonic), canBePerfect(i.Diatonic))
if i.Octaves < 0 {
return quality.Invert()
}
return quality
} | go | func (i Interval) Quality() Quality {
quality := diffQuality(i.Chromatic-diatonicToChromatic(i.Diatonic), canBePerfect(i.Diatonic))
if i.Octaves < 0 {
return quality.Invert()
}
return quality
} | [
"func",
"(",
"i",
"Interval",
")",
"Quality",
"(",
")",
"Quality",
"{",
"quality",
":=",
"diffQuality",
"(",
"i",
".",
"Chromatic",
"-",
"diatonicToChromatic",
"(",
"i",
".",
"Diatonic",
")",
",",
"canBePerfect",
"(",
"i",
".",
"Diatonic",
")",
")",
"\... | // Quality returns the Quality | [
"Quality",
"returns",
"the",
"Quality"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L102-L110 |
149,886 | brettbuddin/musictheory | interval.go | Transpose | func (i Interval) Transpose(o Interval) Interval {
var diatonic int
// TODO: Accomodate weird behavior of sequential minor second transpositions. We don't need to advance the diatonic
// every transposition. We're currently modeling things as integers, but maybe we need to model as floats and
// accumulate over ti... | go | func (i Interval) Transpose(o Interval) Interval {
var diatonic int
// TODO: Accomodate weird behavior of sequential minor second transpositions. We don't need to advance the diatonic
// every transposition. We're currently modeling things as integers, but maybe we need to model as floats and
// accumulate over ti... | [
"func",
"(",
"i",
"Interval",
")",
"Transpose",
"(",
"o",
"Interval",
")",
"Interval",
"{",
"var",
"diatonic",
"int",
"\n\n",
"// TODO: Accomodate weird behavior of sequential minor second transpositions. We don't need to advance the diatonic",
"// every transposition. We're curren... | // Transpose returns a new Interval that has been transposed by the given Interval | [
"Transpose",
"returns",
"a",
"new",
"Interval",
"that",
"has",
"been",
"transposed",
"by",
"the",
"given",
"Interval"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L118-L142 |
149,887 | brettbuddin/musictheory | interval.go | Negate | func (i Interval) Negate() Interval {
if i.Diatonic == 0 && i.Chromatic == 0 {
return Interval{-i.Octaves, i.Diatonic, i.Chromatic}
}
return Interval{-(i.Octaves + 1), inverseDiatonic(i.Diatonic), inverseChromatic(i.Chromatic)}
} | go | func (i Interval) Negate() Interval {
if i.Diatonic == 0 && i.Chromatic == 0 {
return Interval{-i.Octaves, i.Diatonic, i.Chromatic}
}
return Interval{-(i.Octaves + 1), inverseDiatonic(i.Diatonic), inverseChromatic(i.Chromatic)}
} | [
"func",
"(",
"i",
"Interval",
")",
"Negate",
"(",
")",
"Interval",
"{",
"if",
"i",
".",
"Diatonic",
"==",
"0",
"&&",
"i",
".",
"Chromatic",
"==",
"0",
"{",
"return",
"Interval",
"{",
"-",
"i",
".",
"Octaves",
",",
"i",
".",
"Diatonic",
",",
"i",
... | // Negate returns a new, negated Interval | [
"Negate",
"returns",
"a",
"new",
"negated",
"Interval"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L145-L151 |
149,888 | brettbuddin/musictheory | interval.go | Eq | func (i Interval) Eq(o Interval) bool {
return i.Semitones() == o.Semitones()
} | go | func (i Interval) Eq(o Interval) bool {
return i.Semitones() == o.Semitones()
} | [
"func",
"(",
"i",
"Interval",
")",
"Eq",
"(",
"o",
"Interval",
")",
"bool",
"{",
"return",
"i",
".",
"Semitones",
"(",
")",
"==",
"o",
".",
"Semitones",
"(",
")",
"\n",
"}"
] | // Eq determines if another interval is the same | [
"Eq",
"determines",
"if",
"another",
"interval",
"is",
"the",
"same"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L154-L156 |
149,889 | brettbuddin/musictheory | interval.go | Invert | func (q Quality) Invert() Quality {
switch q.Type {
case PerfectType:
return q
case MajorType:
return Quality{MinorType, q.Size}
case MinorType:
return Quality{MajorType, q.Size}
case AugmentedType:
return Quality{DiminishedType, q.Size}
case DiminishedType:
return Quality{AugmentedType, q.Size}
defaul... | go | func (q Quality) Invert() Quality {
switch q.Type {
case PerfectType:
return q
case MajorType:
return Quality{MinorType, q.Size}
case MinorType:
return Quality{MajorType, q.Size}
case AugmentedType:
return Quality{DiminishedType, q.Size}
case DiminishedType:
return Quality{AugmentedType, q.Size}
defaul... | [
"func",
"(",
"q",
"Quality",
")",
"Invert",
"(",
")",
"Quality",
"{",
"switch",
"q",
".",
"Type",
"{",
"case",
"PerfectType",
":",
"return",
"q",
"\n",
"case",
"MajorType",
":",
"return",
"Quality",
"{",
"MinorType",
",",
"q",
".",
"Size",
"}",
"\n",... | // Invert returns a new, inverted Quality | [
"Invert",
"returns",
"a",
"new",
"inverted",
"Quality"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L198-L213 |
149,890 | brettbuddin/musictheory | interval.go | Eq | func (q Quality) Eq(o Quality) bool {
return q.Type == o.Type && q.Size == o.Size
} | go | func (q Quality) Eq(o Quality) bool {
return q.Type == o.Type && q.Size == o.Size
} | [
"func",
"(",
"q",
"Quality",
")",
"Eq",
"(",
"o",
"Quality",
")",
"bool",
"{",
"return",
"q",
".",
"Type",
"==",
"o",
".",
"Type",
"&&",
"q",
".",
"Size",
"==",
"o",
".",
"Size",
"\n",
"}"
] | // Eq checks two Qualities for equality | [
"Eq",
"checks",
"two",
"Qualities",
"for",
"equality"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/interval.go#L216-L218 |
149,891 | brettbuddin/musictheory | parse.go | MustParsePitch | func MustParsePitch(str string) Pitch {
pitch, err := ParsePitch(str)
if err != nil {
panic(err)
}
return pitch
} | go | func MustParsePitch(str string) Pitch {
pitch, err := ParsePitch(str)
if err != nil {
panic(err)
}
return pitch
} | [
"func",
"MustParsePitch",
"(",
"str",
"string",
")",
"Pitch",
"{",
"pitch",
",",
"err",
":=",
"ParsePitch",
"(",
"str",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"pitch",
"\n",
"}"
] | // MustParsePitch parses and returns a Pitch in scientific pitch notation or panics | [
"MustParsePitch",
"parses",
"and",
"returns",
"a",
"Pitch",
"in",
"scientific",
"pitch",
"notation",
"or",
"panics"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/parse.go#L15-L21 |
149,892 | brettbuddin/musictheory | parse.go | ParsePitch | func ParsePitch(str string) (Pitch, error) {
matches := pitch.FindStringSubmatch(str)
if len(matches) < 1 {
return Pitch{}, fmt.Errorf("no matches found")
}
class := matches[1]
modifier := matches[2]
octave, err := strconv.Atoi(matches[3])
if err != nil {
return Pitch{}, err
}
classIndex, err := classNam... | go | func ParsePitch(str string) (Pitch, error) {
matches := pitch.FindStringSubmatch(str)
if len(matches) < 1 {
return Pitch{}, fmt.Errorf("no matches found")
}
class := matches[1]
modifier := matches[2]
octave, err := strconv.Atoi(matches[3])
if err != nil {
return Pitch{}, err
}
classIndex, err := classNam... | [
"func",
"ParsePitch",
"(",
"str",
"string",
")",
"(",
"Pitch",
",",
"error",
")",
"{",
"matches",
":=",
"pitch",
".",
"FindStringSubmatch",
"(",
"str",
")",
"\n",
"if",
"len",
"(",
"matches",
")",
"<",
"1",
"{",
"return",
"Pitch",
"{",
"}",
",",
"f... | // ParsePitch parses and returns a Pitch in scientific pitch notation | [
"ParsePitch",
"parses",
"and",
"returns",
"a",
"Pitch",
"in",
"scientific",
"pitch",
"notation"
] | 3f55f31a3cd98d55dba0dfd787c96098ce2c4d28 | https://github.com/brettbuddin/musictheory/blob/3f55f31a3cd98d55dba0dfd787c96098ce2c4d28/parse.go#L24-L48 |
149,893 | Azure/azure-docker-extension | pkg/vmextension/handlerenv.go | scriptDir | func scriptDir() (string, error) {
p, err := filepath.Abs(os.Args[0])
if err != nil {
return "", err
}
return filepath.Dir(p), nil
} | go | func scriptDir() (string, error) {
p, err := filepath.Abs(os.Args[0])
if err != nil {
return "", err
}
return filepath.Dir(p), nil
} | [
"func",
"scriptDir",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"p",
",",
"err",
":=",
"filepath",
".",
"Abs",
"(",
"os",
".",
"Args",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",... | // scriptDir returns the absolute path of the running process. | [
"scriptDir",
"returns",
"the",
"absolute",
"path",
"of",
"the",
"running",
"process",
"."
] | d1d2547150489b2495a8d09a642e7f515bbf484f | https://github.com/Azure/azure-docker-extension/blob/d1d2547150489b2495a8d09a642e7f515bbf484f/pkg/vmextension/handlerenv.go#L58-L64 |
149,894 | Azure/azure-docker-extension | pkg/vmextension/seqnum.go | FindSeqNum | func FindSeqNum(configFolder string) (int, error) {
g, err := filepath.Glob(configFolder + "/*.settings")
if err != nil {
return 0, err
}
seqs := make([]int, len(g))
for _, v := range g {
f := filepath.Base(v)
i, err := strconv.Atoi(strings.Replace(f, ".settings", "", 1))
if err != nil {
return 0, fmt.E... | go | func FindSeqNum(configFolder string) (int, error) {
g, err := filepath.Glob(configFolder + "/*.settings")
if err != nil {
return 0, err
}
seqs := make([]int, len(g))
for _, v := range g {
f := filepath.Base(v)
i, err := strconv.Atoi(strings.Replace(f, ".settings", "", 1))
if err != nil {
return 0, fmt.E... | [
"func",
"FindSeqNum",
"(",
"configFolder",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"g",
",",
"err",
":=",
"filepath",
".",
"Glob",
"(",
"configFolder",
"+",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"0",
",",
"err",... | // FindSeqnum finds the file with the highest number under configFolder
// named like 0.settings, 1.settings so on. | [
"FindSeqnum",
"finds",
"the",
"file",
"with",
"the",
"highest",
"number",
"under",
"configFolder",
"named",
"like",
"0",
".",
"settings",
"1",
".",
"settings",
"so",
"on",
"."
] | d1d2547150489b2495a8d09a642e7f515bbf484f | https://github.com/Azure/azure-docker-extension/blob/d1d2547150489b2495a8d09a642e7f515bbf484f/pkg/vmextension/seqnum.go#L13-L32 |
149,895 | Azure/azure-docker-extension | pkg/vmextension/handlersettings.go | settingsPath | func settingsPath(configFolder string) (string, error) {
seq, err := FindSeqNum(configFolder)
if err != nil {
return "", fmt.Errorf("Cannot find seqnum: %v", err)
}
return filepath.Join(configFolder, fmt.Sprintf("%d%s", seq, settingsFileSuffix)), nil
} | go | func settingsPath(configFolder string) (string, error) {
seq, err := FindSeqNum(configFolder)
if err != nil {
return "", fmt.Errorf("Cannot find seqnum: %v", err)
}
return filepath.Join(configFolder, fmt.Sprintf("%d%s", seq, settingsFileSuffix)), nil
} | [
"func",
"settingsPath",
"(",
"configFolder",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"seq",
",",
"err",
":=",
"FindSeqNum",
"(",
"configFolder",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
... | // settingsPath returns the full path to the .settings file with the
// highest sequence number found in configFolder. | [
"settingsPath",
"returns",
"the",
"full",
"path",
"to",
"the",
".",
"settings",
"file",
"with",
"the",
"highest",
"sequence",
"number",
"found",
"in",
"configFolder",
"."
] | d1d2547150489b2495a8d09a642e7f515bbf484f | https://github.com/Azure/azure-docker-extension/blob/d1d2547150489b2495a8d09a642e7f515bbf484f/pkg/vmextension/handlersettings.go#L33-L39 |
149,896 | Azure/azure-docker-extension | pkg/vmextension/handlersettings.go | unmarshalProtectedSettings | func unmarshalProtectedSettings(configFolder string, hs handlerSettings, v interface{}) error {
if hs.ProtectedSettingsBase64 == "" {
return nil
}
if hs.SettingsCertThumbprint == "" {
return errors.New("HandlerSettings has protected settings but no cert thumbprint")
}
decoded, err := base64.StdEncoding.Decode... | go | func unmarshalProtectedSettings(configFolder string, hs handlerSettings, v interface{}) error {
if hs.ProtectedSettingsBase64 == "" {
return nil
}
if hs.SettingsCertThumbprint == "" {
return errors.New("HandlerSettings has protected settings but no cert thumbprint")
}
decoded, err := base64.StdEncoding.Decode... | [
"func",
"unmarshalProtectedSettings",
"(",
"configFolder",
"string",
",",
"hs",
"handlerSettings",
",",
"v",
"interface",
"{",
"}",
")",
"error",
"{",
"if",
"hs",
".",
"ProtectedSettingsBase64",
"==",
"\"",
"\"",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"if",
... | // unmarshalProtectedSettings decodes the protected settings from handler
// runtime settings JSON file, decrypts it using the certificates and unmarshals
// into the given struct v. | [
"unmarshalProtectedSettings",
"decodes",
"the",
"protected",
"settings",
"from",
"handler",
"runtime",
"settings",
"JSON",
"file",
"decrypts",
"it",
"using",
"the",
"certificates",
"and",
"unmarshals",
"into",
"the",
"given",
"struct",
"v",
"."
] | d1d2547150489b2495a8d09a642e7f515bbf484f | https://github.com/Azure/azure-docker-extension/blob/d1d2547150489b2495a8d09a642e7f515bbf484f/pkg/vmextension/handlersettings.go#L111-L146 |
149,897 | Azure/azure-docker-extension | pkg/util/util.go | GetAzureUser | func GetAzureUser() (string, error) {
b, err := ioutil.ReadFile(OvfEnvPath)
if err != nil {
return "", err
}
var v struct {
XMLName xml.Name `xml:"Environment"`
UserName string `xml:"ProvisioningSection>LinuxProvisioningConfigurationSet>UserName"`
}
if err := xml.Unmarshal(b, &v); err != nil {
return ... | go | func GetAzureUser() (string, error) {
b, err := ioutil.ReadFile(OvfEnvPath)
if err != nil {
return "", err
}
var v struct {
XMLName xml.Name `xml:"Environment"`
UserName string `xml:"ProvisioningSection>LinuxProvisioningConfigurationSet>UserName"`
}
if err := xml.Unmarshal(b, &v); err != nil {
return ... | [
"func",
"GetAzureUser",
"(",
")",
"(",
"string",
",",
"error",
")",
"{",
"b",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"OvfEnvPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"v... | // GetAzureUser returns the username provided at VM provisioning time to Azure. | [
"GetAzureUser",
"returns",
"the",
"username",
"provided",
"at",
"VM",
"provisioning",
"time",
"to",
"Azure",
"."
] | d1d2547150489b2495a8d09a642e7f515bbf484f | https://github.com/Azure/azure-docker-extension/blob/d1d2547150489b2495a8d09a642e7f515bbf484f/pkg/util/util.go#L39-L53 |
149,898 | Azure/azure-docker-extension | main.go | reportStatus | func reportStatus(t status.Type, op Op, msg string) error {
if !op.reportsStatus {
log.Printf("Status '%s' not reported for operation '%v' (by design)", t, op.name)
return nil
}
dir := handlerEnv.HandlerEnvironment.StatusFolder
m := msg
if m == "" {
m = op.name
if t == status.StatusSuccess {
m += " succ... | go | func reportStatus(t status.Type, op Op, msg string) error {
if !op.reportsStatus {
log.Printf("Status '%s' not reported for operation '%v' (by design)", t, op.name)
return nil
}
dir := handlerEnv.HandlerEnvironment.StatusFolder
m := msg
if m == "" {
m = op.name
if t == status.StatusSuccess {
m += " succ... | [
"func",
"reportStatus",
"(",
"t",
"status",
".",
"Type",
",",
"op",
"Op",
",",
"msg",
"string",
")",
"error",
"{",
"if",
"!",
"op",
".",
"reportsStatus",
"{",
"log",
".",
"Printf",
"(",
"\"",
"\"",
",",
"t",
",",
"op",
".",
"name",
")",
"\n",
"... | // reportStatus saves operation status to the status file for the extension. | [
"reportStatus",
"saves",
"operation",
"status",
"to",
"the",
"status",
"file",
"for",
"the",
"extension",
"."
] | d1d2547150489b2495a8d09a642e7f515bbf484f | https://github.com/Azure/azure-docker-extension/blob/d1d2547150489b2495a8d09a642e7f515bbf484f/main.go#L137-L155 |
149,899 | Azure/azure-docker-extension | main.go | logFail | func logFail(op Op, msg string) {
log.Printf(msg)
if err := reportStatus(status.StatusError, op, msg); err != nil {
log.Printf("Error reporting extension status: %v", err)
}
if err := seqnumfile.Delete(); err != nil {
log.Printf("WARNING: Error deleting seqnumfile: %v", err)
}
log.Println("Cleaned up .seqnum ... | go | func logFail(op Op, msg string) {
log.Printf(msg)
if err := reportStatus(status.StatusError, op, msg); err != nil {
log.Printf("Error reporting extension status: %v", err)
}
if err := seqnumfile.Delete(); err != nil {
log.Printf("WARNING: Error deleting seqnumfile: %v", err)
}
log.Println("Cleaned up .seqnum ... | [
"func",
"logFail",
"(",
"op",
"Op",
",",
"msg",
"string",
")",
"{",
"log",
".",
"Printf",
"(",
"msg",
")",
"\n",
"if",
"err",
":=",
"reportStatus",
"(",
"status",
".",
"StatusError",
",",
"op",
",",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"log"... | // logFail prints the failure, reports failure status and exits | [
"logFail",
"prints",
"the",
"failure",
"reports",
"failure",
"status",
"and",
"exits"
] | d1d2547150489b2495a8d09a642e7f515bbf484f | https://github.com/Azure/azure-docker-extension/blob/d1d2547150489b2495a8d09a642e7f515bbf484f/main.go#L158-L169 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.