id
int32
0
167k
repo
stringlengths
5
54
path
stringlengths
4
155
func_name
stringlengths
1
118
original_string
stringlengths
52
85.5k
language
stringclasses
1 value
code
stringlengths
52
85.5k
code_tokens
listlengths
21
1.41k
docstring
stringlengths
6
2.61k
docstring_tokens
listlengths
3
215
sha
stringlengths
40
40
url
stringlengths
85
252
9,700
dsnet/compress
brotli/bit_reader.go
FeedBits
func (br *bitReader) FeedBits(nb uint) { if br.bufRd != nil { br.discardBits += int(br.fedBits - br.numBits) for { if len(br.bufPeek) == 0 { br.fedBits = br.numBits // Don't discard bits just added br.FlushOffset() var err error cntPeek := 8 // Minimum Peek amount to make progress if br.bufRd.Buffered() > cntPeek { cntPeek = br.bufRd.Buffered() } br.bufPeek, err = br.bufRd.Peek(cntPeek) br.bufPeek = br.bufPeek[int(br.numBits/8):] // Skip buffered bits if len(br.bufPeek) == 0 { if br.numBits >= nb { break } if err == io.EOF { err = io.ErrUnexpectedEOF } errors.Panic(err) } } cnt := int(64-br.numBits) / 8 if cnt > len(br.bufPeek) { cnt = len(br.bufPeek) } for _, c := range br.bufPeek[:cnt] { br.bufBits |= uint64(c) << br.numBits br.numBits += 8 } br.bufPeek = br.bufPeek[cnt:] if br.numBits > 56 { break } } br.fedBits = br.numBits } else { for br.numBits < nb { c, err := br.rd.ReadByte() if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF } errors.Panic(err) } br.bufBits |= uint64(c) << br.numBits br.numBits += 8 br.offset++ } } }
go
func (br *bitReader) FeedBits(nb uint) { if br.bufRd != nil { br.discardBits += int(br.fedBits - br.numBits) for { if len(br.bufPeek) == 0 { br.fedBits = br.numBits // Don't discard bits just added br.FlushOffset() var err error cntPeek := 8 // Minimum Peek amount to make progress if br.bufRd.Buffered() > cntPeek { cntPeek = br.bufRd.Buffered() } br.bufPeek, err = br.bufRd.Peek(cntPeek) br.bufPeek = br.bufPeek[int(br.numBits/8):] // Skip buffered bits if len(br.bufPeek) == 0 { if br.numBits >= nb { break } if err == io.EOF { err = io.ErrUnexpectedEOF } errors.Panic(err) } } cnt := int(64-br.numBits) / 8 if cnt > len(br.bufPeek) { cnt = len(br.bufPeek) } for _, c := range br.bufPeek[:cnt] { br.bufBits |= uint64(c) << br.numBits br.numBits += 8 } br.bufPeek = br.bufPeek[cnt:] if br.numBits > 56 { break } } br.fedBits = br.numBits } else { for br.numBits < nb { c, err := br.rd.ReadByte() if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF } errors.Panic(err) } br.bufBits |= uint64(c) << br.numBits br.numBits += 8 br.offset++ } } }
[ "func", "(", "br", "*", "bitReader", ")", "FeedBits", "(", "nb", "uint", ")", "{", "if", "br", ".", "bufRd", "!=", "nil", "{", "br", ".", "discardBits", "+=", "int", "(", "br", ".", "fedBits", "-", "br", ".", "numBits", ")", "\n", "for", "{", "if", "len", "(", "br", ".", "bufPeek", ")", "==", "0", "{", "br", ".", "fedBits", "=", "br", ".", "numBits", "// Don't discard bits just added", "\n", "br", ".", "FlushOffset", "(", ")", "\n\n", "var", "err", "error", "\n", "cntPeek", ":=", "8", "// Minimum Peek amount to make progress", "\n", "if", "br", ".", "bufRd", ".", "Buffered", "(", ")", ">", "cntPeek", "{", "cntPeek", "=", "br", ".", "bufRd", ".", "Buffered", "(", ")", "\n", "}", "\n", "br", ".", "bufPeek", ",", "err", "=", "br", ".", "bufRd", ".", "Peek", "(", "cntPeek", ")", "\n", "br", ".", "bufPeek", "=", "br", ".", "bufPeek", "[", "int", "(", "br", ".", "numBits", "/", "8", ")", ":", "]", "// Skip buffered bits", "\n", "if", "len", "(", "br", ".", "bufPeek", ")", "==", "0", "{", "if", "br", ".", "numBits", ">=", "nb", "{", "break", "\n", "}", "\n", "if", "err", "==", "io", ".", "EOF", "{", "err", "=", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n", "errors", ".", "Panic", "(", "err", ")", "\n", "}", "\n", "}", "\n", "cnt", ":=", "int", "(", "64", "-", "br", ".", "numBits", ")", "/", "8", "\n", "if", "cnt", ">", "len", "(", "br", ".", "bufPeek", ")", "{", "cnt", "=", "len", "(", "br", ".", "bufPeek", ")", "\n", "}", "\n", "for", "_", ",", "c", ":=", "range", "br", ".", "bufPeek", "[", ":", "cnt", "]", "{", "br", ".", "bufBits", "|=", "uint64", "(", "c", ")", "<<", "br", ".", "numBits", "\n", "br", ".", "numBits", "+=", "8", "\n", "}", "\n", "br", ".", "bufPeek", "=", "br", ".", "bufPeek", "[", "cnt", ":", "]", "\n", "if", "br", ".", "numBits", ">", "56", "{", "break", "\n", "}", "\n", "}", "\n", "br", ".", "fedBits", "=", "br", ".", "numBits", "\n", "}", "else", "{", "for", "br", ".", "numBits", "<", "nb", "{", "c", ",", "err", ":=", "br", ".", "rd", ".", "ReadByte", "(", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "err", "=", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n", "errors", ".", "Panic", "(", "err", ")", "\n", "}", "\n", "br", ".", "bufBits", "|=", "uint64", "(", "c", ")", "<<", "br", ".", "numBits", "\n", "br", ".", "numBits", "+=", "8", "\n", "br", ".", "offset", "++", "\n", "}", "\n", "}", "\n", "}" ]
// FeedBits ensures that at least nb bits exist in the bit buffer. // If the underlying byteReader is a bufio.Reader, then this will fill the // bit buffer with as many bits as possible, relying on Peek and Discard to // properly advance the read offset. Otherwise, it will use ReadByte to fill the // buffer with just the right number of bits.
[ "FeedBits", "ensures", "that", "at", "least", "nb", "bits", "exist", "in", "the", "bit", "buffer", ".", "If", "the", "underlying", "byteReader", "is", "a", "bufio", ".", "Reader", "then", "this", "will", "fill", "the", "bit", "buffer", "with", "as", "many", "bits", "as", "possible", "relying", "on", "Peek", "and", "Discard", "to", "properly", "advance", "the", "read", "offset", ".", "Otherwise", "it", "will", "use", "ReadByte", "to", "fill", "the", "buffer", "with", "just", "the", "right", "number", "of", "bits", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/bit_reader.go#L86-L139
9,701
dsnet/compress
brotli/bit_reader.go
ReadBits
func (br *bitReader) ReadBits(nb uint) uint { br.FeedBits(nb) val := uint(br.bufBits & uint64(1<<nb-1)) br.bufBits >>= nb br.numBits -= nb return val }
go
func (br *bitReader) ReadBits(nb uint) uint { br.FeedBits(nb) val := uint(br.bufBits & uint64(1<<nb-1)) br.bufBits >>= nb br.numBits -= nb return val }
[ "func", "(", "br", "*", "bitReader", ")", "ReadBits", "(", "nb", "uint", ")", "uint", "{", "br", ".", "FeedBits", "(", "nb", ")", "\n", "val", ":=", "uint", "(", "br", ".", "bufBits", "&", "uint64", "(", "1", "<<", "nb", "-", "1", ")", ")", "\n", "br", ".", "bufBits", ">>=", "nb", "\n", "br", ".", "numBits", "-=", "nb", "\n", "return", "val", "\n", "}" ]
// ReadBits reads nb bits in LSB order from the underlying reader.
[ "ReadBits", "reads", "nb", "bits", "in", "LSB", "order", "from", "the", "underlying", "reader", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/bit_reader.go#L175-L181
9,702
dsnet/compress
brotli/bit_reader.go
ReadSymbol
func (br *bitReader) ReadSymbol(pd *prefixDecoder) uint { if len(pd.chunks) == 0 { errors.Panic(errInvalid) // Decode with empty tree } nb := uint(pd.minBits) for { br.FeedBits(nb) chunk := pd.chunks[uint32(br.bufBits)&pd.chunkMask] nb = uint(chunk & prefixCountMask) if nb > uint(pd.chunkBits) { linkIdx := chunk >> prefixCountBits chunk = pd.links[linkIdx][uint32(br.bufBits>>pd.chunkBits)&pd.linkMask] nb = uint(chunk & prefixCountMask) } if nb <= br.numBits { br.bufBits >>= nb br.numBits -= nb return uint(chunk >> prefixCountBits) } } }
go
func (br *bitReader) ReadSymbol(pd *prefixDecoder) uint { if len(pd.chunks) == 0 { errors.Panic(errInvalid) // Decode with empty tree } nb := uint(pd.minBits) for { br.FeedBits(nb) chunk := pd.chunks[uint32(br.bufBits)&pd.chunkMask] nb = uint(chunk & prefixCountMask) if nb > uint(pd.chunkBits) { linkIdx := chunk >> prefixCountBits chunk = pd.links[linkIdx][uint32(br.bufBits>>pd.chunkBits)&pd.linkMask] nb = uint(chunk & prefixCountMask) } if nb <= br.numBits { br.bufBits >>= nb br.numBits -= nb return uint(chunk >> prefixCountBits) } } }
[ "func", "(", "br", "*", "bitReader", ")", "ReadSymbol", "(", "pd", "*", "prefixDecoder", ")", "uint", "{", "if", "len", "(", "pd", ".", "chunks", ")", "==", "0", "{", "errors", ".", "Panic", "(", "errInvalid", ")", "// Decode with empty tree", "\n", "}", "\n\n", "nb", ":=", "uint", "(", "pd", ".", "minBits", ")", "\n", "for", "{", "br", ".", "FeedBits", "(", "nb", ")", "\n", "chunk", ":=", "pd", ".", "chunks", "[", "uint32", "(", "br", ".", "bufBits", ")", "&", "pd", ".", "chunkMask", "]", "\n", "nb", "=", "uint", "(", "chunk", "&", "prefixCountMask", ")", "\n", "if", "nb", ">", "uint", "(", "pd", ".", "chunkBits", ")", "{", "linkIdx", ":=", "chunk", ">>", "prefixCountBits", "\n", "chunk", "=", "pd", ".", "links", "[", "linkIdx", "]", "[", "uint32", "(", "br", ".", "bufBits", ">>", "pd", ".", "chunkBits", ")", "&", "pd", ".", "linkMask", "]", "\n", "nb", "=", "uint", "(", "chunk", "&", "prefixCountMask", ")", "\n", "}", "\n", "if", "nb", "<=", "br", ".", "numBits", "{", "br", ".", "bufBits", ">>=", "nb", "\n", "br", ".", "numBits", "-=", "nb", "\n", "return", "uint", "(", "chunk", ">>", "prefixCountBits", ")", "\n", "}", "\n", "}", "\n", "}" ]
// ReadSymbol reads the next prefix symbol using the provided prefixDecoder.
[ "ReadSymbol", "reads", "the", "next", "prefix", "symbol", "using", "the", "provided", "prefixDecoder", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/bit_reader.go#L211-L232
9,703
dsnet/compress
brotli/bit_reader.go
ReadOffset
func (br *bitReader) ReadOffset(sym uint, rcs []rangeCode) uint { rc := rcs[sym] return uint(rc.base) + br.ReadBits(uint(rc.bits)) }
go
func (br *bitReader) ReadOffset(sym uint, rcs []rangeCode) uint { rc := rcs[sym] return uint(rc.base) + br.ReadBits(uint(rc.bits)) }
[ "func", "(", "br", "*", "bitReader", ")", "ReadOffset", "(", "sym", "uint", ",", "rcs", "[", "]", "rangeCode", ")", "uint", "{", "rc", ":=", "rcs", "[", "sym", "]", "\n", "return", "uint", "(", "rc", ".", "base", ")", "+", "br", ".", "ReadBits", "(", "uint", "(", "rc", ".", "bits", ")", ")", "\n", "}" ]
// ReadOffset reads an offset value using the provided rangesCodes indexed by // the given symbol.
[ "ReadOffset", "reads", "an", "offset", "value", "using", "the", "provided", "rangesCodes", "indexed", "by", "the", "given", "symbol", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/bit_reader.go#L236-L239
9,704
dsnet/compress
brotli/bit_reader.go
ReadPrefixCode
func (br *bitReader) ReadPrefixCode(pd *prefixDecoder, maxSyms uint) { hskip := br.ReadBits(2) if hskip == 1 { br.readSimplePrefixCode(pd, maxSyms) } else { br.readComplexPrefixCode(pd, maxSyms, hskip) } }
go
func (br *bitReader) ReadPrefixCode(pd *prefixDecoder, maxSyms uint) { hskip := br.ReadBits(2) if hskip == 1 { br.readSimplePrefixCode(pd, maxSyms) } else { br.readComplexPrefixCode(pd, maxSyms, hskip) } }
[ "func", "(", "br", "*", "bitReader", ")", "ReadPrefixCode", "(", "pd", "*", "prefixDecoder", ",", "maxSyms", "uint", ")", "{", "hskip", ":=", "br", ".", "ReadBits", "(", "2", ")", "\n", "if", "hskip", "==", "1", "{", "br", ".", "readSimplePrefixCode", "(", "pd", ",", "maxSyms", ")", "\n", "}", "else", "{", "br", ".", "readComplexPrefixCode", "(", "pd", ",", "maxSyms", ",", "hskip", ")", "\n", "}", "\n", "}" ]
// ReadPrefixCode reads the prefix definition from the stream and initializes // the provided prefixDecoder. The value maxSyms is the alphabet size of the // prefix code being generated. The actual number of representable symbols // will be between 1 and maxSyms, inclusively.
[ "ReadPrefixCode", "reads", "the", "prefix", "definition", "from", "the", "stream", "and", "initializes", "the", "provided", "prefixDecoder", ".", "The", "value", "maxSyms", "is", "the", "alphabet", "size", "of", "the", "prefix", "code", "being", "generated", ".", "The", "actual", "number", "of", "representable", "symbols", "will", "be", "between", "1", "and", "maxSyms", "inclusively", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/bit_reader.go#L245-L252
9,705
dsnet/compress
brotli/bit_reader.go
readSimplePrefixCode
func (br *bitReader) readSimplePrefixCode(pd *prefixDecoder, maxSyms uint) { var codes [4]prefixCode nsym := int(br.ReadBits(2)) + 1 clen := neededBits(uint32(maxSyms)) for i := 0; i < nsym; i++ { codes[i].sym = uint32(br.ReadBits(clen)) } copyLens := func(lens []uint) { for i := 0; i < nsym; i++ { codes[i].len = uint32(lens[i]) } } compareSwap := func(i, j int) { if codes[i].sym > codes[j].sym { codes[i], codes[j] = codes[j], codes[i] } } switch nsym { case 1: copyLens(simpleLens1[:]) case 2: copyLens(simpleLens2[:]) compareSwap(0, 1) case 3: copyLens(simpleLens3[:]) compareSwap(0, 1) compareSwap(0, 2) compareSwap(1, 2) case 4: if tsel := br.ReadBits(1) == 1; !tsel { copyLens(simpleLens4a[:]) } else { copyLens(simpleLens4b[:]) } compareSwap(0, 1) compareSwap(2, 3) compareSwap(0, 2) compareSwap(1, 3) compareSwap(1, 2) } if uint(codes[nsym-1].sym) >= maxSyms { errors.Panic(errCorrupted) // Symbol goes beyond range of alphabet } pd.Init(codes[:nsym], true) // Must have 1..4 symbols }
go
func (br *bitReader) readSimplePrefixCode(pd *prefixDecoder, maxSyms uint) { var codes [4]prefixCode nsym := int(br.ReadBits(2)) + 1 clen := neededBits(uint32(maxSyms)) for i := 0; i < nsym; i++ { codes[i].sym = uint32(br.ReadBits(clen)) } copyLens := func(lens []uint) { for i := 0; i < nsym; i++ { codes[i].len = uint32(lens[i]) } } compareSwap := func(i, j int) { if codes[i].sym > codes[j].sym { codes[i], codes[j] = codes[j], codes[i] } } switch nsym { case 1: copyLens(simpleLens1[:]) case 2: copyLens(simpleLens2[:]) compareSwap(0, 1) case 3: copyLens(simpleLens3[:]) compareSwap(0, 1) compareSwap(0, 2) compareSwap(1, 2) case 4: if tsel := br.ReadBits(1) == 1; !tsel { copyLens(simpleLens4a[:]) } else { copyLens(simpleLens4b[:]) } compareSwap(0, 1) compareSwap(2, 3) compareSwap(0, 2) compareSwap(1, 3) compareSwap(1, 2) } if uint(codes[nsym-1].sym) >= maxSyms { errors.Panic(errCorrupted) // Symbol goes beyond range of alphabet } pd.Init(codes[:nsym], true) // Must have 1..4 symbols }
[ "func", "(", "br", "*", "bitReader", ")", "readSimplePrefixCode", "(", "pd", "*", "prefixDecoder", ",", "maxSyms", "uint", ")", "{", "var", "codes", "[", "4", "]", "prefixCode", "\n", "nsym", ":=", "int", "(", "br", ".", "ReadBits", "(", "2", ")", ")", "+", "1", "\n", "clen", ":=", "neededBits", "(", "uint32", "(", "maxSyms", ")", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "nsym", ";", "i", "++", "{", "codes", "[", "i", "]", ".", "sym", "=", "uint32", "(", "br", ".", "ReadBits", "(", "clen", ")", ")", "\n", "}", "\n\n", "copyLens", ":=", "func", "(", "lens", "[", "]", "uint", ")", "{", "for", "i", ":=", "0", ";", "i", "<", "nsym", ";", "i", "++", "{", "codes", "[", "i", "]", ".", "len", "=", "uint32", "(", "lens", "[", "i", "]", ")", "\n", "}", "\n", "}", "\n", "compareSwap", ":=", "func", "(", "i", ",", "j", "int", ")", "{", "if", "codes", "[", "i", "]", ".", "sym", ">", "codes", "[", "j", "]", ".", "sym", "{", "codes", "[", "i", "]", ",", "codes", "[", "j", "]", "=", "codes", "[", "j", "]", ",", "codes", "[", "i", "]", "\n", "}", "\n", "}", "\n\n", "switch", "nsym", "{", "case", "1", ":", "copyLens", "(", "simpleLens1", "[", ":", "]", ")", "\n", "case", "2", ":", "copyLens", "(", "simpleLens2", "[", ":", "]", ")", "\n", "compareSwap", "(", "0", ",", "1", ")", "\n", "case", "3", ":", "copyLens", "(", "simpleLens3", "[", ":", "]", ")", "\n", "compareSwap", "(", "0", ",", "1", ")", "\n", "compareSwap", "(", "0", ",", "2", ")", "\n", "compareSwap", "(", "1", ",", "2", ")", "\n", "case", "4", ":", "if", "tsel", ":=", "br", ".", "ReadBits", "(", "1", ")", "==", "1", ";", "!", "tsel", "{", "copyLens", "(", "simpleLens4a", "[", ":", "]", ")", "\n", "}", "else", "{", "copyLens", "(", "simpleLens4b", "[", ":", "]", ")", "\n", "}", "\n", "compareSwap", "(", "0", ",", "1", ")", "\n", "compareSwap", "(", "2", ",", "3", ")", "\n", "compareSwap", "(", "0", ",", "2", ")", "\n", "compareSwap", "(", "1", ",", "3", ")", "\n", "compareSwap", "(", "1", ",", "2", ")", "\n", "}", "\n", "if", "uint", "(", "codes", "[", "nsym", "-", "1", "]", ".", "sym", ")", ">=", "maxSyms", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "// Symbol goes beyond range of alphabet", "\n", "}", "\n", "pd", ".", "Init", "(", "codes", "[", ":", "nsym", "]", ",", "true", ")", "// Must have 1..4 symbols", "\n", "}" ]
// readSimplePrefixCode reads the prefix code according to RFC section 3.4.
[ "readSimplePrefixCode", "reads", "the", "prefix", "code", "according", "to", "RFC", "section", "3", ".", "4", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/bit_reader.go#L255-L301
9,706
dsnet/compress
brotli/bit_reader.go
readComplexPrefixCode
func (br *bitReader) readComplexPrefixCode(pd *prefixDecoder, maxSyms, hskip uint) { // Read the code-lengths prefix table. var codeCLensArr [len(complexLens)]prefixCode // Sorted, but may have holes sum := 32 for _, sym := range complexLens[hskip:] { clen := br.ReadSymbol(&decCLens) if clen > 0 { codeCLensArr[sym] = prefixCode{sym: uint32(sym), len: uint32(clen)} if sum -= 32 >> clen; sum <= 0 { break } } } codeCLens := codeCLensArr[:0] // Compact the array to have no holes for _, c := range codeCLensArr { if c.len > 0 { codeCLens = append(codeCLens, c) } } if len(codeCLens) < 1 { errors.Panic(errCorrupted) } br.prefix.Init(codeCLens, true) // Must have 1..len(complexLens) symbols // Use code-lengths table to decode rest of prefix table. var codesArr [maxNumAlphabetSyms]prefixCode var sym, repSymLast, repCntLast, clenLast uint = 0, 0, 0, 8 codes := codesArr[:0] for sym, sum = 0, 32768; sym < maxSyms && sum > 0; { clen := br.ReadSymbol(&br.prefix) if clen < 16 { // Literal bit-length symbol used. if clen > 0 { codes = append(codes, prefixCode{sym: uint32(sym), len: uint32(clen)}) clenLast = clen sum -= 32768 >> clen } repSymLast = 0 // Reset last repeater symbol sym++ } else { // Repeater symbol used. // 16: Repeat previous non-zero code-length // 17: Repeat code length of zero repSym := clen // Rename clen for better clarity if repSym != repSymLast { repCntLast = 0 repSymLast = repSym } nb := repSym - 14 // 2..3 bits rep := br.ReadBits(nb) + 3 // 3..6 or 3..10 if repCntLast > 0 { rep += (repCntLast - 2) << nb // Modify previous repeat count } repDiff := rep - repCntLast // Always positive repCntLast = rep if repSym == 16 { clen := clenLast for symEnd := sym + repDiff; sym < symEnd; sym++ { codes = append(codes, prefixCode{sym: uint32(sym), len: uint32(clen)}) } sum -= int(repDiff) * (32768 >> clen) } else { sym += repDiff } } } if len(codes) < 2 || sym > maxSyms { errors.Panic(errCorrupted) } pd.Init(codes, true) // Must have 2..maxSyms symbols }
go
func (br *bitReader) readComplexPrefixCode(pd *prefixDecoder, maxSyms, hskip uint) { // Read the code-lengths prefix table. var codeCLensArr [len(complexLens)]prefixCode // Sorted, but may have holes sum := 32 for _, sym := range complexLens[hskip:] { clen := br.ReadSymbol(&decCLens) if clen > 0 { codeCLensArr[sym] = prefixCode{sym: uint32(sym), len: uint32(clen)} if sum -= 32 >> clen; sum <= 0 { break } } } codeCLens := codeCLensArr[:0] // Compact the array to have no holes for _, c := range codeCLensArr { if c.len > 0 { codeCLens = append(codeCLens, c) } } if len(codeCLens) < 1 { errors.Panic(errCorrupted) } br.prefix.Init(codeCLens, true) // Must have 1..len(complexLens) symbols // Use code-lengths table to decode rest of prefix table. var codesArr [maxNumAlphabetSyms]prefixCode var sym, repSymLast, repCntLast, clenLast uint = 0, 0, 0, 8 codes := codesArr[:0] for sym, sum = 0, 32768; sym < maxSyms && sum > 0; { clen := br.ReadSymbol(&br.prefix) if clen < 16 { // Literal bit-length symbol used. if clen > 0 { codes = append(codes, prefixCode{sym: uint32(sym), len: uint32(clen)}) clenLast = clen sum -= 32768 >> clen } repSymLast = 0 // Reset last repeater symbol sym++ } else { // Repeater symbol used. // 16: Repeat previous non-zero code-length // 17: Repeat code length of zero repSym := clen // Rename clen for better clarity if repSym != repSymLast { repCntLast = 0 repSymLast = repSym } nb := repSym - 14 // 2..3 bits rep := br.ReadBits(nb) + 3 // 3..6 or 3..10 if repCntLast > 0 { rep += (repCntLast - 2) << nb // Modify previous repeat count } repDiff := rep - repCntLast // Always positive repCntLast = rep if repSym == 16 { clen := clenLast for symEnd := sym + repDiff; sym < symEnd; sym++ { codes = append(codes, prefixCode{sym: uint32(sym), len: uint32(clen)}) } sum -= int(repDiff) * (32768 >> clen) } else { sym += repDiff } } } if len(codes) < 2 || sym > maxSyms { errors.Panic(errCorrupted) } pd.Init(codes, true) // Must have 2..maxSyms symbols }
[ "func", "(", "br", "*", "bitReader", ")", "readComplexPrefixCode", "(", "pd", "*", "prefixDecoder", ",", "maxSyms", ",", "hskip", "uint", ")", "{", "// Read the code-lengths prefix table.", "var", "codeCLensArr", "[", "len", "(", "complexLens", ")", "]", "prefixCode", "// Sorted, but may have holes", "\n", "sum", ":=", "32", "\n", "for", "_", ",", "sym", ":=", "range", "complexLens", "[", "hskip", ":", "]", "{", "clen", ":=", "br", ".", "ReadSymbol", "(", "&", "decCLens", ")", "\n", "if", "clen", ">", "0", "{", "codeCLensArr", "[", "sym", "]", "=", "prefixCode", "{", "sym", ":", "uint32", "(", "sym", ")", ",", "len", ":", "uint32", "(", "clen", ")", "}", "\n", "if", "sum", "-=", "32", ">>", "clen", ";", "sum", "<=", "0", "{", "break", "\n", "}", "\n", "}", "\n", "}", "\n", "codeCLens", ":=", "codeCLensArr", "[", ":", "0", "]", "// Compact the array to have no holes", "\n", "for", "_", ",", "c", ":=", "range", "codeCLensArr", "{", "if", "c", ".", "len", ">", "0", "{", "codeCLens", "=", "append", "(", "codeCLens", ",", "c", ")", "\n", "}", "\n", "}", "\n", "if", "len", "(", "codeCLens", ")", "<", "1", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "\n", "}", "\n", "br", ".", "prefix", ".", "Init", "(", "codeCLens", ",", "true", ")", "// Must have 1..len(complexLens) symbols", "\n\n", "// Use code-lengths table to decode rest of prefix table.", "var", "codesArr", "[", "maxNumAlphabetSyms", "]", "prefixCode", "\n", "var", "sym", ",", "repSymLast", ",", "repCntLast", ",", "clenLast", "uint", "=", "0", ",", "0", ",", "0", ",", "8", "\n", "codes", ":=", "codesArr", "[", ":", "0", "]", "\n", "for", "sym", ",", "sum", "=", "0", ",", "32768", ";", "sym", "<", "maxSyms", "&&", "sum", ">", "0", ";", "{", "clen", ":=", "br", ".", "ReadSymbol", "(", "&", "br", ".", "prefix", ")", "\n", "if", "clen", "<", "16", "{", "// Literal bit-length symbol used.", "if", "clen", ">", "0", "{", "codes", "=", "append", "(", "codes", ",", "prefixCode", "{", "sym", ":", "uint32", "(", "sym", ")", ",", "len", ":", "uint32", "(", "clen", ")", "}", ")", "\n", "clenLast", "=", "clen", "\n", "sum", "-=", "32768", ">>", "clen", "\n", "}", "\n", "repSymLast", "=", "0", "// Reset last repeater symbol", "\n", "sym", "++", "\n", "}", "else", "{", "// Repeater symbol used.", "//\t16: Repeat previous non-zero code-length", "//\t17: Repeat code length of zero", "repSym", ":=", "clen", "// Rename clen for better clarity", "\n", "if", "repSym", "!=", "repSymLast", "{", "repCntLast", "=", "0", "\n", "repSymLast", "=", "repSym", "\n", "}", "\n\n", "nb", ":=", "repSym", "-", "14", "// 2..3 bits", "\n", "rep", ":=", "br", ".", "ReadBits", "(", "nb", ")", "+", "3", "// 3..6 or 3..10", "\n", "if", "repCntLast", ">", "0", "{", "rep", "+=", "(", "repCntLast", "-", "2", ")", "<<", "nb", "// Modify previous repeat count", "\n", "}", "\n", "repDiff", ":=", "rep", "-", "repCntLast", "// Always positive", "\n", "repCntLast", "=", "rep", "\n\n", "if", "repSym", "==", "16", "{", "clen", ":=", "clenLast", "\n", "for", "symEnd", ":=", "sym", "+", "repDiff", ";", "sym", "<", "symEnd", ";", "sym", "++", "{", "codes", "=", "append", "(", "codes", ",", "prefixCode", "{", "sym", ":", "uint32", "(", "sym", ")", ",", "len", ":", "uint32", "(", "clen", ")", "}", ")", "\n", "}", "\n", "sum", "-=", "int", "(", "repDiff", ")", "*", "(", "32768", ">>", "clen", ")", "\n", "}", "else", "{", "sym", "+=", "repDiff", "\n", "}", "\n", "}", "\n", "}", "\n", "if", "len", "(", "codes", ")", "<", "2", "||", "sym", ">", "maxSyms", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "\n", "}", "\n", "pd", ".", "Init", "(", "codes", ",", "true", ")", "// Must have 2..maxSyms symbols", "\n", "}" ]
// readComplexPrefixCode reads the prefix code according to RFC section 3.5.
[ "readComplexPrefixCode", "reads", "the", "prefix", "code", "according", "to", "RFC", "section", "3", ".", "5", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/bit_reader.go#L304-L377
9,707
dsnet/compress
bzip2/fuzz_on.go
Apply
func (cs Checksums) Apply(d []byte) []byte { d = append([]byte(nil), d...) for _, c := range cs { setU32(d, c.Offset, c.Value) } return d }
go
func (cs Checksums) Apply(d []byte) []byte { d = append([]byte(nil), d...) for _, c := range cs { setU32(d, c.Offset, c.Value) } return d }
[ "func", "(", "cs", "Checksums", ")", "Apply", "(", "d", "[", "]", "byte", ")", "[", "]", "byte", "{", "d", "=", "append", "(", "[", "]", "byte", "(", "nil", ")", ",", "d", "...", ")", "\n", "for", "_", ",", "c", ":=", "range", "cs", "{", "setU32", "(", "d", ",", "c", ".", "Offset", ",", "c", ".", "Value", ")", "\n", "}", "\n", "return", "d", "\n", "}" ]
// Apply overwrites all checksum fields in d with the ones in cs.
[ "Apply", "overwrites", "all", "checksum", "fields", "in", "d", "with", "the", "ones", "in", "cs", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/bzip2/fuzz_on.go#L45-L51
9,708
dsnet/compress
bzip2/fuzz_on.go
Verify
func (cs Checksums) Verify(d []byte) bool { for _, c := range cs { if getU32(d, c.Offset) != c.Value { return false } } return true }
go
func (cs Checksums) Verify(d []byte) bool { for _, c := range cs { if getU32(d, c.Offset) != c.Value { return false } } return true }
[ "func", "(", "cs", "Checksums", ")", "Verify", "(", "d", "[", "]", "byte", ")", "bool", "{", "for", "_", ",", "c", ":=", "range", "cs", "{", "if", "getU32", "(", "d", ",", "c", ".", "Offset", ")", "!=", "c", ".", "Value", "{", "return", "false", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// Verify checks that all checksum fields in d matches those in cs.
[ "Verify", "checks", "that", "all", "checksum", "fields", "in", "d", "matches", "those", "in", "cs", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/bzip2/fuzz_on.go#L62-L69
9,709
dsnet/compress
internal/prefix/prefix.go
Length
func (pc PrefixCodes) Length() (nb uint) { for _, c := range pc { nb += uint(c.Len * c.Cnt) } return nb }
go
func (pc PrefixCodes) Length() (nb uint) { for _, c := range pc { nb += uint(c.Len * c.Cnt) } return nb }
[ "func", "(", "pc", "PrefixCodes", ")", "Length", "(", ")", "(", "nb", "uint", ")", "{", "for", "_", ",", "c", ":=", "range", "pc", "{", "nb", "+=", "uint", "(", "c", ".", "Len", "*", "c", ".", "Cnt", ")", "\n", "}", "\n", "return", "nb", "\n", "}" ]
// Length computes the total bit-length using the Len and Cnt fields.
[ "Length", "computes", "the", "total", "bit", "-", "length", "using", "the", "Len", "and", "Cnt", "fields", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/internal/prefix/prefix.go#L62-L67
9,710
dsnet/compress
internal/prefix/prefix.go
checkLengths
func (pc PrefixCodes) checkLengths() bool { sum := 1 << valueBits for _, c := range pc { sum -= (1 << valueBits) >> uint(c.Len) } return sum == 0 || len(pc) == 0 }
go
func (pc PrefixCodes) checkLengths() bool { sum := 1 << valueBits for _, c := range pc { sum -= (1 << valueBits) >> uint(c.Len) } return sum == 0 || len(pc) == 0 }
[ "func", "(", "pc", "PrefixCodes", ")", "checkLengths", "(", ")", "bool", "{", "sum", ":=", "1", "<<", "valueBits", "\n", "for", "_", ",", "c", ":=", "range", "pc", "{", "sum", "-=", "(", "1", "<<", "valueBits", ")", ">>", "uint", "(", "c", ".", "Len", ")", "\n", "}", "\n", "return", "sum", "==", "0", "||", "len", "(", "pc", ")", "==", "0", "\n", "}" ]
// checkLengths reports whether the codes form a complete prefix tree.
[ "checkLengths", "reports", "whether", "the", "codes", "form", "a", "complete", "prefix", "tree", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/internal/prefix/prefix.go#L70-L76
9,711
dsnet/compress
internal/prefix/prefix.go
checkPrefixes
func (pc PrefixCodes) checkPrefixes() bool { for i, c1 := range pc { for j, c2 := range pc { mask := uint32(1)<<c1.Len - 1 if i != j && c1.Len <= c2.Len && c1.Val&mask == c2.Val&mask { return false } } } return true }
go
func (pc PrefixCodes) checkPrefixes() bool { for i, c1 := range pc { for j, c2 := range pc { mask := uint32(1)<<c1.Len - 1 if i != j && c1.Len <= c2.Len && c1.Val&mask == c2.Val&mask { return false } } } return true }
[ "func", "(", "pc", "PrefixCodes", ")", "checkPrefixes", "(", ")", "bool", "{", "for", "i", ",", "c1", ":=", "range", "pc", "{", "for", "j", ",", "c2", ":=", "range", "pc", "{", "mask", ":=", "uint32", "(", "1", ")", "<<", "c1", ".", "Len", "-", "1", "\n", "if", "i", "!=", "j", "&&", "c1", ".", "Len", "<=", "c2", ".", "Len", "&&", "c1", ".", "Val", "&", "mask", "==", "c2", ".", "Val", "&", "mask", "{", "return", "false", "\n", "}", "\n", "}", "\n", "}", "\n", "return", "true", "\n", "}" ]
// checkPrefixes reports whether all codes have non-overlapping prefixes.
[ "checkPrefixes", "reports", "whether", "all", "codes", "have", "non", "-", "overlapping", "prefixes", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/internal/prefix/prefix.go#L79-L89
9,712
dsnet/compress
internal/prefix/prefix.go
GeneratePrefixes
func GeneratePrefixes(codes PrefixCodes) error { if len(codes) <= 1 { if len(codes) == 1 { if codes[0].Len != 0 { return errorf(errors.Invalid, "degenerate prefix tree with one node") } codes[0].Val = 0 } return nil } // Compute basic statistics on the symbols. var bitCnts [valueBits + 1]uint c0 := codes[0] bitCnts[c0.Len]++ minBits, maxBits, symLast := c0.Len, c0.Len, c0.Sym for _, c := range codes[1:] { if c.Sym <= symLast { return errorf(errors.Invalid, "non-unique or non-monotonically increasing symbols") } if minBits > c.Len { minBits = c.Len } if maxBits < c.Len { maxBits = c.Len } bitCnts[c.Len]++ // Histogram of bit counts symLast = c.Sym // Keep track of last symbol } if minBits == 0 { return errorf(errors.Invalid, "invalid prefix bit-length") } // Compute the next code for a symbol of a given bit length. var nextCodes [valueBits + 1]uint var code uint for i := minBits; i <= maxBits; i++ { code <<= 1 nextCodes[i] = code code += bitCnts[i] } if code != 1<<maxBits { return errorf(errors.Invalid, "degenerate prefix tree") } // Assign the code to each symbol. for i, c := range codes { codes[i].Val = internal.ReverseUint32N(uint32(nextCodes[c.Len]), uint(c.Len)) nextCodes[c.Len]++ } if internal.Debug && !codes.checkPrefixes() { panic("overlapping prefixes detected") } if internal.Debug && !codes.checkCanonical() { panic("non-canonical prefixes detected") } return nil }
go
func GeneratePrefixes(codes PrefixCodes) error { if len(codes) <= 1 { if len(codes) == 1 { if codes[0].Len != 0 { return errorf(errors.Invalid, "degenerate prefix tree with one node") } codes[0].Val = 0 } return nil } // Compute basic statistics on the symbols. var bitCnts [valueBits + 1]uint c0 := codes[0] bitCnts[c0.Len]++ minBits, maxBits, symLast := c0.Len, c0.Len, c0.Sym for _, c := range codes[1:] { if c.Sym <= symLast { return errorf(errors.Invalid, "non-unique or non-monotonically increasing symbols") } if minBits > c.Len { minBits = c.Len } if maxBits < c.Len { maxBits = c.Len } bitCnts[c.Len]++ // Histogram of bit counts symLast = c.Sym // Keep track of last symbol } if minBits == 0 { return errorf(errors.Invalid, "invalid prefix bit-length") } // Compute the next code for a symbol of a given bit length. var nextCodes [valueBits + 1]uint var code uint for i := minBits; i <= maxBits; i++ { code <<= 1 nextCodes[i] = code code += bitCnts[i] } if code != 1<<maxBits { return errorf(errors.Invalid, "degenerate prefix tree") } // Assign the code to each symbol. for i, c := range codes { codes[i].Val = internal.ReverseUint32N(uint32(nextCodes[c.Len]), uint(c.Len)) nextCodes[c.Len]++ } if internal.Debug && !codes.checkPrefixes() { panic("overlapping prefixes detected") } if internal.Debug && !codes.checkCanonical() { panic("non-canonical prefixes detected") } return nil }
[ "func", "GeneratePrefixes", "(", "codes", "PrefixCodes", ")", "error", "{", "if", "len", "(", "codes", ")", "<=", "1", "{", "if", "len", "(", "codes", ")", "==", "1", "{", "if", "codes", "[", "0", "]", ".", "Len", "!=", "0", "{", "return", "errorf", "(", "errors", ".", "Invalid", ",", "\"", "\"", ")", "\n", "}", "\n", "codes", "[", "0", "]", ".", "Val", "=", "0", "\n", "}", "\n", "return", "nil", "\n", "}", "\n\n", "// Compute basic statistics on the symbols.", "var", "bitCnts", "[", "valueBits", "+", "1", "]", "uint", "\n", "c0", ":=", "codes", "[", "0", "]", "\n", "bitCnts", "[", "c0", ".", "Len", "]", "++", "\n", "minBits", ",", "maxBits", ",", "symLast", ":=", "c0", ".", "Len", ",", "c0", ".", "Len", ",", "c0", ".", "Sym", "\n", "for", "_", ",", "c", ":=", "range", "codes", "[", "1", ":", "]", "{", "if", "c", ".", "Sym", "<=", "symLast", "{", "return", "errorf", "(", "errors", ".", "Invalid", ",", "\"", "\"", ")", "\n", "}", "\n", "if", "minBits", ">", "c", ".", "Len", "{", "minBits", "=", "c", ".", "Len", "\n", "}", "\n", "if", "maxBits", "<", "c", ".", "Len", "{", "maxBits", "=", "c", ".", "Len", "\n", "}", "\n", "bitCnts", "[", "c", ".", "Len", "]", "++", "// Histogram of bit counts", "\n", "symLast", "=", "c", ".", "Sym", "// Keep track of last symbol", "\n", "}", "\n", "if", "minBits", "==", "0", "{", "return", "errorf", "(", "errors", ".", "Invalid", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Compute the next code for a symbol of a given bit length.", "var", "nextCodes", "[", "valueBits", "+", "1", "]", "uint", "\n", "var", "code", "uint", "\n", "for", "i", ":=", "minBits", ";", "i", "<=", "maxBits", ";", "i", "++", "{", "code", "<<=", "1", "\n", "nextCodes", "[", "i", "]", "=", "code", "\n", "code", "+=", "bitCnts", "[", "i", "]", "\n", "}", "\n", "if", "code", "!=", "1", "<<", "maxBits", "{", "return", "errorf", "(", "errors", ".", "Invalid", ",", "\"", "\"", ")", "\n", "}", "\n\n", "// Assign the code to each symbol.", "for", "i", ",", "c", ":=", "range", "codes", "{", "codes", "[", "i", "]", ".", "Val", "=", "internal", ".", "ReverseUint32N", "(", "uint32", "(", "nextCodes", "[", "c", ".", "Len", "]", ")", ",", "uint", "(", "c", ".", "Len", ")", ")", "\n", "nextCodes", "[", "c", ".", "Len", "]", "++", "\n", "}", "\n\n", "if", "internal", ".", "Debug", "&&", "!", "codes", ".", "checkPrefixes", "(", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "if", "internal", ".", "Debug", "&&", "!", "codes", ".", "checkCanonical", "(", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// GeneratePrefixes assigns a prefix value to all codes according to the // bit-lengths. This function is used by both compressors and decompressors. // // The input codes must have the Sym and Len fields populated and be // sorted by symbol. The bit-lengths of each code must be properly allocated, // such that it forms a complete tree. // // The result will have the Val field populated and will produce a canonical // prefix tree. The resulting codes will remain sorted by symbol.
[ "GeneratePrefixes", "assigns", "a", "prefix", "value", "to", "all", "codes", "according", "to", "the", "bit", "-", "lengths", ".", "This", "function", "is", "used", "by", "both", "compressors", "and", "decompressors", ".", "The", "input", "codes", "must", "have", "the", "Sym", "and", "Len", "fields", "populated", "and", "be", "sorted", "by", "symbol", ".", "The", "bit", "-", "lengths", "of", "each", "code", "must", "be", "properly", "allocated", "such", "that", "it", "forms", "a", "complete", "tree", ".", "The", "result", "will", "have", "the", "Val", "field", "populated", "and", "will", "produce", "a", "canonical", "prefix", "tree", ".", "The", "resulting", "codes", "will", "remain", "sorted", "by", "symbol", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/internal/prefix/prefix.go#L326-L384
9,713
dsnet/compress
brotli/reader.go
readStreamHeader
func (br *Reader) readStreamHeader() { wbits := br.rd.ReadSymbol(&decWinBits) if wbits == 0 { errors.Panic(errCorrupted) // Reserved value used } size := int(1<<wbits) - 16 br.dict.Init(size) br.readBlockHeader() }
go
func (br *Reader) readStreamHeader() { wbits := br.rd.ReadSymbol(&decWinBits) if wbits == 0 { errors.Panic(errCorrupted) // Reserved value used } size := int(1<<wbits) - 16 br.dict.Init(size) br.readBlockHeader() }
[ "func", "(", "br", "*", "Reader", ")", "readStreamHeader", "(", ")", "{", "wbits", ":=", "br", ".", "rd", ".", "ReadSymbol", "(", "&", "decWinBits", ")", "\n", "if", "wbits", "==", "0", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "// Reserved value used", "\n", "}", "\n", "size", ":=", "int", "(", "1", "<<", "wbits", ")", "-", "16", "\n", "br", ".", "dict", ".", "Init", "(", "size", ")", "\n", "br", ".", "readBlockHeader", "(", ")", "\n", "}" ]
// readStreamHeader reads the Brotli stream header according to RFC section 9.1.
[ "readStreamHeader", "reads", "the", "Brotli", "stream", "header", "according", "to", "RFC", "section", "9", ".", "1", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/reader.go#L138-L146
9,714
dsnet/compress
brotli/reader.go
readBlockHeader
func (br *Reader) readBlockHeader() { if br.last { if br.rd.ReadPads() > 0 { errors.Panic(errCorrupted) } errors.Panic(io.EOF) } // Read ISLAST and ISLASTEMPTY. if br.last = br.rd.ReadBits(1) == 1; br.last { if empty := br.rd.ReadBits(1) == 1; empty { br.readBlockHeader() // Next call will terminate stream return } } // Read MLEN and MNIBBLES and process meta data. var blkLen int // 1..1<<24 nibbles := br.rd.ReadBits(2) + 4 if nibbles == 7 { if reserved := br.rd.ReadBits(1) == 1; reserved { errors.Panic(errCorrupted) } var skipLen int // 0..1<<24 if skipBytes := br.rd.ReadBits(2); skipBytes > 0 { skipLen = int(br.rd.ReadBits(skipBytes * 8)) if skipBytes > 1 && skipLen>>((skipBytes-1)*8) == 0 { errors.Panic(errCorrupted) // Shortest representation not used } skipLen++ } if br.rd.ReadPads() > 0 { errors.Panic(errCorrupted) } br.blkLen = skipLen // Use blkLen to track metadata number of bytes br.readMetaData() return } blkLen = int(br.rd.ReadBits(nibbles * 4)) if nibbles > 4 && blkLen>>((nibbles-1)*4) == 0 { errors.Panic(errCorrupted) // Shortest representation not used } br.blkLen = blkLen + 1 // Read ISUNCOMPRESSED and process uncompressed data. if !br.last { if uncompressed := br.rd.ReadBits(1) == 1; uncompressed { if br.rd.ReadPads() > 0 { errors.Panic(errCorrupted) } br.readRawData() return } } br.readPrefixCodes() }
go
func (br *Reader) readBlockHeader() { if br.last { if br.rd.ReadPads() > 0 { errors.Panic(errCorrupted) } errors.Panic(io.EOF) } // Read ISLAST and ISLASTEMPTY. if br.last = br.rd.ReadBits(1) == 1; br.last { if empty := br.rd.ReadBits(1) == 1; empty { br.readBlockHeader() // Next call will terminate stream return } } // Read MLEN and MNIBBLES and process meta data. var blkLen int // 1..1<<24 nibbles := br.rd.ReadBits(2) + 4 if nibbles == 7 { if reserved := br.rd.ReadBits(1) == 1; reserved { errors.Panic(errCorrupted) } var skipLen int // 0..1<<24 if skipBytes := br.rd.ReadBits(2); skipBytes > 0 { skipLen = int(br.rd.ReadBits(skipBytes * 8)) if skipBytes > 1 && skipLen>>((skipBytes-1)*8) == 0 { errors.Panic(errCorrupted) // Shortest representation not used } skipLen++ } if br.rd.ReadPads() > 0 { errors.Panic(errCorrupted) } br.blkLen = skipLen // Use blkLen to track metadata number of bytes br.readMetaData() return } blkLen = int(br.rd.ReadBits(nibbles * 4)) if nibbles > 4 && blkLen>>((nibbles-1)*4) == 0 { errors.Panic(errCorrupted) // Shortest representation not used } br.blkLen = blkLen + 1 // Read ISUNCOMPRESSED and process uncompressed data. if !br.last { if uncompressed := br.rd.ReadBits(1) == 1; uncompressed { if br.rd.ReadPads() > 0 { errors.Panic(errCorrupted) } br.readRawData() return } } br.readPrefixCodes() }
[ "func", "(", "br", "*", "Reader", ")", "readBlockHeader", "(", ")", "{", "if", "br", ".", "last", "{", "if", "br", ".", "rd", ".", "ReadPads", "(", ")", ">", "0", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "\n", "}", "\n", "errors", ".", "Panic", "(", "io", ".", "EOF", ")", "\n", "}", "\n\n", "// Read ISLAST and ISLASTEMPTY.", "if", "br", ".", "last", "=", "br", ".", "rd", ".", "ReadBits", "(", "1", ")", "==", "1", ";", "br", ".", "last", "{", "if", "empty", ":=", "br", ".", "rd", ".", "ReadBits", "(", "1", ")", "==", "1", ";", "empty", "{", "br", ".", "readBlockHeader", "(", ")", "// Next call will terminate stream", "\n", "return", "\n", "}", "\n", "}", "\n\n", "// Read MLEN and MNIBBLES and process meta data.", "var", "blkLen", "int", "// 1..1<<24", "\n", "nibbles", ":=", "br", ".", "rd", ".", "ReadBits", "(", "2", ")", "+", "4", "\n", "if", "nibbles", "==", "7", "{", "if", "reserved", ":=", "br", ".", "rd", ".", "ReadBits", "(", "1", ")", "==", "1", ";", "reserved", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "\n", "}", "\n\n", "var", "skipLen", "int", "// 0..1<<24", "\n", "if", "skipBytes", ":=", "br", ".", "rd", ".", "ReadBits", "(", "2", ")", ";", "skipBytes", ">", "0", "{", "skipLen", "=", "int", "(", "br", ".", "rd", ".", "ReadBits", "(", "skipBytes", "*", "8", ")", ")", "\n", "if", "skipBytes", ">", "1", "&&", "skipLen", ">>", "(", "(", "skipBytes", "-", "1", ")", "*", "8", ")", "==", "0", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "// Shortest representation not used", "\n", "}", "\n", "skipLen", "++", "\n", "}", "\n\n", "if", "br", ".", "rd", ".", "ReadPads", "(", ")", ">", "0", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "\n", "}", "\n", "br", ".", "blkLen", "=", "skipLen", "// Use blkLen to track metadata number of bytes", "\n", "br", ".", "readMetaData", "(", ")", "\n", "return", "\n", "}", "\n", "blkLen", "=", "int", "(", "br", ".", "rd", ".", "ReadBits", "(", "nibbles", "*", "4", ")", ")", "\n", "if", "nibbles", ">", "4", "&&", "blkLen", ">>", "(", "(", "nibbles", "-", "1", ")", "*", "4", ")", "==", "0", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "// Shortest representation not used", "\n", "}", "\n", "br", ".", "blkLen", "=", "blkLen", "+", "1", "\n\n", "// Read ISUNCOMPRESSED and process uncompressed data.", "if", "!", "br", ".", "last", "{", "if", "uncompressed", ":=", "br", ".", "rd", ".", "ReadBits", "(", "1", ")", "==", "1", ";", "uncompressed", "{", "if", "br", ".", "rd", ".", "ReadPads", "(", ")", ">", "0", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "\n", "}", "\n", "br", ".", "readRawData", "(", ")", "\n", "return", "\n", "}", "\n", "}", "\n", "br", ".", "readPrefixCodes", "(", ")", "\n", "}" ]
// readBlockHeader reads a meta-block header according to RFC section 9.2.
[ "readBlockHeader", "reads", "a", "meta", "-", "block", "header", "according", "to", "RFC", "section", "9", ".", "2", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/reader.go#L149-L206
9,715
dsnet/compress
brotli/reader.go
readMetaData
func (br *Reader) readMetaData() { br.metaRd.R = &br.rd br.metaRd.N = int64(br.blkLen) if br.metaBuf == nil { br.metaBuf = make([]byte, 4096) // Lazy allocate } if cnt, err := io.CopyBuffer(br.metaWr, &br.metaRd, br.metaBuf); err != nil { errors.Panic(err) // Will never panic with io.EOF } else if cnt < int64(br.blkLen) { errors.Panic(io.ErrUnexpectedEOF) } br.step = (*Reader).readBlockHeader }
go
func (br *Reader) readMetaData() { br.metaRd.R = &br.rd br.metaRd.N = int64(br.blkLen) if br.metaBuf == nil { br.metaBuf = make([]byte, 4096) // Lazy allocate } if cnt, err := io.CopyBuffer(br.metaWr, &br.metaRd, br.metaBuf); err != nil { errors.Panic(err) // Will never panic with io.EOF } else if cnt < int64(br.blkLen) { errors.Panic(io.ErrUnexpectedEOF) } br.step = (*Reader).readBlockHeader }
[ "func", "(", "br", "*", "Reader", ")", "readMetaData", "(", ")", "{", "br", ".", "metaRd", ".", "R", "=", "&", "br", ".", "rd", "\n", "br", ".", "metaRd", ".", "N", "=", "int64", "(", "br", ".", "blkLen", ")", "\n", "if", "br", ".", "metaBuf", "==", "nil", "{", "br", ".", "metaBuf", "=", "make", "(", "[", "]", "byte", ",", "4096", ")", "// Lazy allocate", "\n", "}", "\n", "if", "cnt", ",", "err", ":=", "io", ".", "CopyBuffer", "(", "br", ".", "metaWr", ",", "&", "br", ".", "metaRd", ",", "br", ".", "metaBuf", ")", ";", "err", "!=", "nil", "{", "errors", ".", "Panic", "(", "err", ")", "// Will never panic with io.EOF", "\n", "}", "else", "if", "cnt", "<", "int64", "(", "br", ".", "blkLen", ")", "{", "errors", ".", "Panic", "(", "io", ".", "ErrUnexpectedEOF", ")", "\n", "}", "\n", "br", ".", "step", "=", "(", "*", "Reader", ")", ".", "readBlockHeader", "\n", "}" ]
// readMetaData reads meta data according to RFC section 9.2.
[ "readMetaData", "reads", "meta", "data", "according", "to", "RFC", "section", "9", ".", "2", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/reader.go#L209-L221
9,716
dsnet/compress
brotli/reader.go
readRawData
func (br *Reader) readRawData() { buf := br.dict.WriteSlice() if len(buf) > br.blkLen { buf = buf[:br.blkLen] } cnt, err := br.rd.Read(buf) br.blkLen -= cnt br.dict.WriteMark(cnt) if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF } errors.Panic(err) } if br.blkLen > 0 { br.toRead = br.dict.ReadFlush() br.step = (*Reader).readRawData // We need to continue this work return } br.step = (*Reader).readBlockHeader }
go
func (br *Reader) readRawData() { buf := br.dict.WriteSlice() if len(buf) > br.blkLen { buf = buf[:br.blkLen] } cnt, err := br.rd.Read(buf) br.blkLen -= cnt br.dict.WriteMark(cnt) if err != nil { if err == io.EOF { err = io.ErrUnexpectedEOF } errors.Panic(err) } if br.blkLen > 0 { br.toRead = br.dict.ReadFlush() br.step = (*Reader).readRawData // We need to continue this work return } br.step = (*Reader).readBlockHeader }
[ "func", "(", "br", "*", "Reader", ")", "readRawData", "(", ")", "{", "buf", ":=", "br", ".", "dict", ".", "WriteSlice", "(", ")", "\n", "if", "len", "(", "buf", ")", ">", "br", ".", "blkLen", "{", "buf", "=", "buf", "[", ":", "br", ".", "blkLen", "]", "\n", "}", "\n\n", "cnt", ",", "err", ":=", "br", ".", "rd", ".", "Read", "(", "buf", ")", "\n", "br", ".", "blkLen", "-=", "cnt", "\n", "br", ".", "dict", ".", "WriteMark", "(", "cnt", ")", "\n", "if", "err", "!=", "nil", "{", "if", "err", "==", "io", ".", "EOF", "{", "err", "=", "io", ".", "ErrUnexpectedEOF", "\n", "}", "\n", "errors", ".", "Panic", "(", "err", ")", "\n", "}", "\n\n", "if", "br", ".", "blkLen", ">", "0", "{", "br", ".", "toRead", "=", "br", ".", "dict", ".", "ReadFlush", "(", ")", "\n", "br", ".", "step", "=", "(", "*", "Reader", ")", ".", "readRawData", "// We need to continue this work", "\n", "return", "\n", "}", "\n", "br", ".", "step", "=", "(", "*", "Reader", ")", ".", "readBlockHeader", "\n", "}" ]
// readRawData reads raw data according to RFC section 9.2.
[ "readRawData", "reads", "raw", "data", "according", "to", "RFC", "section", "9", ".", "2", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/reader.go#L224-L246
9,717
dsnet/compress
brotli/reader.go
readContextMap
func (br *Reader) readContextMap(cm []uint8, numTrees uint) { // TODO(dsnet): Test the following edge cases: // * Test with largest and smallest MAXRLE sizes // * Test with with very large MAXRLE value // * Test inverseMoveToFront maxRLE := br.rd.ReadSymbol(&decMaxRLE) br.rd.ReadPrefixCode(&br.rd.prefix, maxRLE+numTrees) for i := 0; i < len(cm); { sym := br.rd.ReadSymbol(&br.rd.prefix) if sym == 0 || sym > maxRLE { // Single non-zero value. if sym > 0 { sym -= maxRLE } cm[i] = uint8(sym) i++ } else { // Repeated zeros. n := int(br.rd.ReadOffset(sym-1, maxRLERanges)) if i+n > len(cm) { errors.Panic(errCorrupted) } for j := i + n; i < j; i++ { cm[i] = 0 } } } if invert := br.rd.ReadBits(1) == 1; invert { br.mtf.Decode(cm) } }
go
func (br *Reader) readContextMap(cm []uint8, numTrees uint) { // TODO(dsnet): Test the following edge cases: // * Test with largest and smallest MAXRLE sizes // * Test with with very large MAXRLE value // * Test inverseMoveToFront maxRLE := br.rd.ReadSymbol(&decMaxRLE) br.rd.ReadPrefixCode(&br.rd.prefix, maxRLE+numTrees) for i := 0; i < len(cm); { sym := br.rd.ReadSymbol(&br.rd.prefix) if sym == 0 || sym > maxRLE { // Single non-zero value. if sym > 0 { sym -= maxRLE } cm[i] = uint8(sym) i++ } else { // Repeated zeros. n := int(br.rd.ReadOffset(sym-1, maxRLERanges)) if i+n > len(cm) { errors.Panic(errCorrupted) } for j := i + n; i < j; i++ { cm[i] = 0 } } } if invert := br.rd.ReadBits(1) == 1; invert { br.mtf.Decode(cm) } }
[ "func", "(", "br", "*", "Reader", ")", "readContextMap", "(", "cm", "[", "]", "uint8", ",", "numTrees", "uint", ")", "{", "// TODO(dsnet): Test the following edge cases:", "// * Test with largest and smallest MAXRLE sizes", "// * Test with with very large MAXRLE value", "// * Test inverseMoveToFront", "maxRLE", ":=", "br", ".", "rd", ".", "ReadSymbol", "(", "&", "decMaxRLE", ")", "\n", "br", ".", "rd", ".", "ReadPrefixCode", "(", "&", "br", ".", "rd", ".", "prefix", ",", "maxRLE", "+", "numTrees", ")", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "cm", ")", ";", "{", "sym", ":=", "br", ".", "rd", ".", "ReadSymbol", "(", "&", "br", ".", "rd", ".", "prefix", ")", "\n", "if", "sym", "==", "0", "||", "sym", ">", "maxRLE", "{", "// Single non-zero value.", "if", "sym", ">", "0", "{", "sym", "-=", "maxRLE", "\n", "}", "\n", "cm", "[", "i", "]", "=", "uint8", "(", "sym", ")", "\n", "i", "++", "\n", "}", "else", "{", "// Repeated zeros.", "n", ":=", "int", "(", "br", ".", "rd", ".", "ReadOffset", "(", "sym", "-", "1", ",", "maxRLERanges", ")", ")", "\n", "if", "i", "+", "n", ">", "len", "(", "cm", ")", "{", "errors", ".", "Panic", "(", "errCorrupted", ")", "\n", "}", "\n", "for", "j", ":=", "i", "+", "n", ";", "i", "<", "j", ";", "i", "++", "{", "cm", "[", "i", "]", "=", "0", "\n", "}", "\n", "}", "\n", "}", "\n\n", "if", "invert", ":=", "br", ".", "rd", ".", "ReadBits", "(", "1", ")", "==", "1", ";", "invert", "{", "br", ".", "mtf", ".", "Decode", "(", "cm", ")", "\n", "}", "\n", "}" ]
// readContextMap reads the context map according to RFC section 7.3.
[ "readContextMap", "reads", "the", "context", "map", "according", "to", "RFC", "section", "7", ".", "3", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/reader.go#L572-L604
9,718
dsnet/compress
brotli/reader.go
readBlockSwitch
func (br *Reader) readBlockSwitch(bd *blockDecoder) { symType := br.rd.ReadSymbol(&bd.decType) switch symType { case 0: symType = uint(bd.types[1]) case 1: symType = uint(bd.types[0]) + 1 if symType >= uint(bd.numTypes) { symType -= uint(bd.numTypes) } default: symType -= 2 } bd.types = [2]uint8{uint8(symType), bd.types[0]} symLen := br.rd.ReadSymbol(&bd.decLen) bd.typeLen = int(br.rd.ReadOffset(symLen, blkLenRanges)) }
go
func (br *Reader) readBlockSwitch(bd *blockDecoder) { symType := br.rd.ReadSymbol(&bd.decType) switch symType { case 0: symType = uint(bd.types[1]) case 1: symType = uint(bd.types[0]) + 1 if symType >= uint(bd.numTypes) { symType -= uint(bd.numTypes) } default: symType -= 2 } bd.types = [2]uint8{uint8(symType), bd.types[0]} symLen := br.rd.ReadSymbol(&bd.decLen) bd.typeLen = int(br.rd.ReadOffset(symLen, blkLenRanges)) }
[ "func", "(", "br", "*", "Reader", ")", "readBlockSwitch", "(", "bd", "*", "blockDecoder", ")", "{", "symType", ":=", "br", ".", "rd", ".", "ReadSymbol", "(", "&", "bd", ".", "decType", ")", "\n", "switch", "symType", "{", "case", "0", ":", "symType", "=", "uint", "(", "bd", ".", "types", "[", "1", "]", ")", "\n", "case", "1", ":", "symType", "=", "uint", "(", "bd", ".", "types", "[", "0", "]", ")", "+", "1", "\n", "if", "symType", ">=", "uint", "(", "bd", ".", "numTypes", ")", "{", "symType", "-=", "uint", "(", "bd", ".", "numTypes", ")", "\n", "}", "\n", "default", ":", "symType", "-=", "2", "\n", "}", "\n", "bd", ".", "types", "=", "[", "2", "]", "uint8", "{", "uint8", "(", "symType", ")", ",", "bd", ".", "types", "[", "0", "]", "}", "\n\n", "symLen", ":=", "br", ".", "rd", ".", "ReadSymbol", "(", "&", "bd", ".", "decLen", ")", "\n", "bd", ".", "typeLen", "=", "int", "(", "br", ".", "rd", ".", "ReadOffset", "(", "symLen", ",", "blkLenRanges", ")", ")", "\n", "}" ]
// readBlockSwitch handles a block switch command according to RFC section 6.
[ "readBlockSwitch", "handles", "a", "block", "switch", "command", "according", "to", "RFC", "section", "6", "." ]
da652975a8eea9fa0735aba8056747a751db0bd3
https://github.com/dsnet/compress/blob/da652975a8eea9fa0735aba8056747a751db0bd3/brotli/reader.go#L607-L624
9,719
labstack/armor
tls.go
setupTLSConfig
func (a *Armor) setupTLSConfig() *tls.Config { cfg := new(tls.Config) cfg.GetConfigForClient = a.GetConfigForClient if a.TLS.Secured { cfg.MinVersion = tls.VersionTLS12 cfg.CipherSuites = []uint16{ tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, } } return cfg }
go
func (a *Armor) setupTLSConfig() *tls.Config { cfg := new(tls.Config) cfg.GetConfigForClient = a.GetConfigForClient if a.TLS.Secured { cfg.MinVersion = tls.VersionTLS12 cfg.CipherSuites = []uint16{ tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305, tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, } } return cfg }
[ "func", "(", "a", "*", "Armor", ")", "setupTLSConfig", "(", ")", "*", "tls", ".", "Config", "{", "cfg", ":=", "new", "(", "tls", ".", "Config", ")", "\n", "cfg", ".", "GetConfigForClient", "=", "a", ".", "GetConfigForClient", "\n\n", "if", "a", ".", "TLS", ".", "Secured", "{", "cfg", ".", "MinVersion", "=", "tls", ".", "VersionTLS12", "\n", "cfg", ".", "CipherSuites", "=", "[", "]", "uint16", "{", "tls", ".", "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305", ",", "tls", ".", "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256", ",", "tls", ".", "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", ",", "tls", ".", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384", ",", "}", "\n", "}", "\n\n", "return", "cfg", "\n", "}" ]
// setupTLSConfig builds the TLS configuration
[ "setupTLSConfig", "builds", "the", "TLS", "configuration" ]
40c3a61dec87035970b3b2591d327731e7a801f3
https://github.com/labstack/armor/blob/40c3a61dec87035970b3b2591d327731e7a801f3/tls.go#L15-L33
9,720
labstack/armor
tls.go
GetConfigForClient
func (a *Armor) GetConfigForClient(clientHelloInfo *tls.ClientHelloInfo) (*tls.Config, error) { // Get the host from the hello info host := a.Hosts[clientHelloInfo.ServerName] // If the host or the clientCAs are not configured the function // returns the default TLS configuration if host == nil || len(host.ClientCAs) == 0 { return nil, nil } // Use existing host config if exist if host.TLSConfig != nil { return host.TLSConfig, nil } // Build and save the host config host.TLSConfig = a.buildTLSConfig(clientHelloInfo, host) return host.TLSConfig, nil }
go
func (a *Armor) GetConfigForClient(clientHelloInfo *tls.ClientHelloInfo) (*tls.Config, error) { // Get the host from the hello info host := a.Hosts[clientHelloInfo.ServerName] // If the host or the clientCAs are not configured the function // returns the default TLS configuration if host == nil || len(host.ClientCAs) == 0 { return nil, nil } // Use existing host config if exist if host.TLSConfig != nil { return host.TLSConfig, nil } // Build and save the host config host.TLSConfig = a.buildTLSConfig(clientHelloInfo, host) return host.TLSConfig, nil }
[ "func", "(", "a", "*", "Armor", ")", "GetConfigForClient", "(", "clientHelloInfo", "*", "tls", ".", "ClientHelloInfo", ")", "(", "*", "tls", ".", "Config", ",", "error", ")", "{", "// Get the host from the hello info", "host", ":=", "a", ".", "Hosts", "[", "clientHelloInfo", ".", "ServerName", "]", "\n", "// If the host or the clientCAs are not configured the function", "// returns the default TLS configuration", "if", "host", "==", "nil", "||", "len", "(", "host", ".", "ClientCAs", ")", "==", "0", "{", "return", "nil", ",", "nil", "\n", "}", "\n\n", "// Use existing host config if exist", "if", "host", ".", "TLSConfig", "!=", "nil", "{", "return", "host", ".", "TLSConfig", ",", "nil", "\n", "}", "\n\n", "// Build and save the host config", "host", ".", "TLSConfig", "=", "a", ".", "buildTLSConfig", "(", "clientHelloInfo", ",", "host", ")", "\n\n", "return", "host", ".", "TLSConfig", ",", "nil", "\n", "}" ]
// GetConfigForClient implements the Config.GetClientCertificate callback
[ "GetConfigForClient", "implements", "the", "Config", ".", "GetClientCertificate", "callback" ]
40c3a61dec87035970b3b2591d327731e7a801f3
https://github.com/labstack/armor/blob/40c3a61dec87035970b3b2591d327731e7a801f3/tls.go#L36-L54
9,721
labstack/armor
plugin/plugin.go
Decode
func Decode(r RawPlugin, e *echo.Echo, l *log.Logger) (p Plugin) { name := r.Name() base := Base{ name: name, mutex: new(sync.RWMutex), Skip: "false", Echo: e, Logger: l, } if p = Lookup(base); p == nil { panic(fmt.Sprintf("plugin=%s not found", name)) } dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ TagName: "yaml", Result: p, }) err = dec.Decode(r) if err != nil { panic(err) } return }
go
func Decode(r RawPlugin, e *echo.Echo, l *log.Logger) (p Plugin) { name := r.Name() base := Base{ name: name, mutex: new(sync.RWMutex), Skip: "false", Echo: e, Logger: l, } if p = Lookup(base); p == nil { panic(fmt.Sprintf("plugin=%s not found", name)) } dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ TagName: "yaml", Result: p, }) err = dec.Decode(r) if err != nil { panic(err) } return }
[ "func", "Decode", "(", "r", "RawPlugin", ",", "e", "*", "echo", ".", "Echo", ",", "l", "*", "log", ".", "Logger", ")", "(", "p", "Plugin", ")", "{", "name", ":=", "r", ".", "Name", "(", ")", "\n", "base", ":=", "Base", "{", "name", ":", "name", ",", "mutex", ":", "new", "(", "sync", ".", "RWMutex", ")", ",", "Skip", ":", "\"", "\"", ",", "Echo", ":", "e", ",", "Logger", ":", "l", ",", "}", "\n", "if", "p", "=", "Lookup", "(", "base", ")", ";", "p", "==", "nil", "{", "panic", "(", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "name", ")", ")", "\n", "}", "\n", "dec", ",", "err", ":=", "mapstructure", ".", "NewDecoder", "(", "&", "mapstructure", ".", "DecoderConfig", "{", "TagName", ":", "\"", "\"", ",", "Result", ":", "p", ",", "}", ")", "\n", "err", "=", "dec", ".", "Decode", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n", "return", "\n", "}" ]
// Decode searches the plugin by name, decodes the provided map into plugin.
[ "Decode", "searches", "the", "plugin", "by", "name", "decodes", "the", "provided", "map", "into", "plugin", "." ]
40c3a61dec87035970b3b2591d327731e7a801f3
https://github.com/labstack/armor/blob/40c3a61dec87035970b3b2591d327731e7a801f3/plugin/plugin.go#L123-L144
9,722
olebedev/go-duktape
timers.go
PushTimers
func (d *Context) PushTimers() error { d.PushGlobalStash() // check if timers already exists if !d.HasPropString(-1, "timers") { d.PushObject() d.PutPropString(-2, "timers") // stash -> [ timers:{} ] d.Pop() d.PushGlobalGoFunction("setTimeout", setTimeout) d.PushGlobalGoFunction("setInterval", setInterval) d.PushGlobalGoFunction("clearTimeout", clearTimeout) d.PushGlobalGoFunction("clearInterval", clearTimeout) return nil } else { d.Pop() return errors.New("Timers are already defined") } }
go
func (d *Context) PushTimers() error { d.PushGlobalStash() // check if timers already exists if !d.HasPropString(-1, "timers") { d.PushObject() d.PutPropString(-2, "timers") // stash -> [ timers:{} ] d.Pop() d.PushGlobalGoFunction("setTimeout", setTimeout) d.PushGlobalGoFunction("setInterval", setInterval) d.PushGlobalGoFunction("clearTimeout", clearTimeout) d.PushGlobalGoFunction("clearInterval", clearTimeout) return nil } else { d.Pop() return errors.New("Timers are already defined") } }
[ "func", "(", "d", "*", "Context", ")", "PushTimers", "(", ")", "error", "{", "d", ".", "PushGlobalStash", "(", ")", "\n", "// check if timers already exists", "if", "!", "d", ".", "HasPropString", "(", "-", "1", ",", "\"", "\"", ")", "{", "d", ".", "PushObject", "(", ")", "\n", "d", ".", "PutPropString", "(", "-", "2", ",", "\"", "\"", ")", "// stash -> [ timers:{} ]", "\n", "d", ".", "Pop", "(", ")", "\n\n", "d", ".", "PushGlobalGoFunction", "(", "\"", "\"", ",", "setTimeout", ")", "\n", "d", ".", "PushGlobalGoFunction", "(", "\"", "\"", ",", "setInterval", ")", "\n", "d", ".", "PushGlobalGoFunction", "(", "\"", "\"", ",", "clearTimeout", ")", "\n", "d", ".", "PushGlobalGoFunction", "(", "\"", "\"", ",", "clearTimeout", ")", "\n", "return", "nil", "\n", "}", "else", "{", "d", ".", "Pop", "(", ")", "\n", "return", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "}" ]
// DefineTimers defines `setTimeout`, `clearTimeout`, `setInterval`, // `clearInterval` into global context.
[ "DefineTimers", "defines", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "into", "global", "context", "." ]
ec84240a7772c7a122b1c58a13398210659f7c40
https://github.com/olebedev/go-duktape/blob/ec84240a7772c7a122b1c58a13398210659f7c40/timers.go#L11-L28
9,723
spaolacci/murmur3
murmur32.go
New32WithSeed
func New32WithSeed(seed uint32) hash.Hash32 { d := new(digest32) d.seed = seed d.bmixer = d d.Reset() return d }
go
func New32WithSeed(seed uint32) hash.Hash32 { d := new(digest32) d.seed = seed d.bmixer = d d.Reset() return d }
[ "func", "New32WithSeed", "(", "seed", "uint32", ")", "hash", ".", "Hash32", "{", "d", ":=", "new", "(", "digest32", ")", "\n", "d", ".", "seed", "=", "seed", "\n", "d", ".", "bmixer", "=", "d", "\n", "d", ".", "Reset", "(", ")", "\n", "return", "d", "\n", "}" ]
// New32WithSeed returns new 32-bit hasher set with explicit seed value
[ "New32WithSeed", "returns", "new", "32", "-", "bit", "hasher", "set", "with", "explicit", "seed", "value" ]
539464a789e9b9f01bc857458ffe2c5c1a2ed382
https://github.com/spaolacci/murmur3/blob/539464a789e9b9f01bc857458ffe2c5c1a2ed382/murmur32.go#L33-L39
9,724
spaolacci/murmur3
murmur64.go
New64WithSeed
func New64WithSeed(seed uint32) hash.Hash64 { d := (*digest64)(New128WithSeed(seed).(*digest128)) return d }
go
func New64WithSeed(seed uint32) hash.Hash64 { d := (*digest64)(New128WithSeed(seed).(*digest128)) return d }
[ "func", "New64WithSeed", "(", "seed", "uint32", ")", "hash", ".", "Hash64", "{", "d", ":=", "(", "*", "digest64", ")", "(", "New128WithSeed", "(", "seed", ")", ".", "(", "*", "digest128", ")", ")", "\n", "return", "d", "\n", "}" ]
// New64WithSeed returns a 64-bit hasher set with explicit seed value
[ "New64WithSeed", "returns", "a", "64", "-", "bit", "hasher", "set", "with", "explicit", "seed", "value" ]
539464a789e9b9f01bc857458ffe2c5c1a2ed382
https://github.com/spaolacci/murmur3/blob/539464a789e9b9f01bc857458ffe2c5c1a2ed382/murmur64.go#L21-L24
9,725
spaolacci/murmur3
murmur128.go
New128WithSeed
func New128WithSeed(seed uint32) Hash128 { d := new(digest128) d.seed = seed d.bmixer = d d.Reset() return d }
go
func New128WithSeed(seed uint32) Hash128 { d := new(digest128) d.seed = seed d.bmixer = d d.Reset() return d }
[ "func", "New128WithSeed", "(", "seed", "uint32", ")", "Hash128", "{", "d", ":=", "new", "(", "digest128", ")", "\n", "d", ".", "seed", "=", "seed", "\n", "d", ".", "bmixer", "=", "d", "\n", "d", ".", "Reset", "(", ")", "\n", "return", "d", "\n", "}" ]
// New128WithSeed returns a 128-bit hasher set with explicit seed value
[ "New128WithSeed", "returns", "a", "128", "-", "bit", "hasher", "set", "with", "explicit", "seed", "value" ]
539464a789e9b9f01bc857458ffe2c5c1a2ed382
https://github.com/spaolacci/murmur3/blob/539464a789e9b9f01bc857458ffe2c5c1a2ed382/murmur128.go#L40-L46
9,726
cbergoon/merkletree
merkle_tree.go
verifyNode
func (n *Node) verifyNode() ([]byte, error) { if n.leaf { return n.C.CalculateHash() } rightBytes, err := n.Right.verifyNode() if err != nil { return nil, err } leftBytes, err := n.Left.verifyNode() if err != nil { return nil, err } h := sha256.New() if _, err := h.Write(append(leftBytes, rightBytes...)); err != nil { return nil, err } return h.Sum(nil), nil }
go
func (n *Node) verifyNode() ([]byte, error) { if n.leaf { return n.C.CalculateHash() } rightBytes, err := n.Right.verifyNode() if err != nil { return nil, err } leftBytes, err := n.Left.verifyNode() if err != nil { return nil, err } h := sha256.New() if _, err := h.Write(append(leftBytes, rightBytes...)); err != nil { return nil, err } return h.Sum(nil), nil }
[ "func", "(", "n", "*", "Node", ")", "verifyNode", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "n", ".", "leaf", "{", "return", "n", ".", "C", ".", "CalculateHash", "(", ")", "\n", "}", "\n", "rightBytes", ",", "err", ":=", "n", ".", "Right", ".", "verifyNode", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "leftBytes", ",", "err", ":=", "n", ".", "Left", ".", "verifyNode", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "h", ":=", "sha256", ".", "New", "(", ")", "\n", "if", "_", ",", "err", ":=", "h", ".", "Write", "(", "append", "(", "leftBytes", ",", "rightBytes", "...", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "h", ".", "Sum", "(", "nil", ")", ",", "nil", "\n", "}" ]
//verifyNode walks down the tree until hitting a leaf, calculating the hash at each level //and returning the resulting hash of Node n.
[ "verifyNode", "walks", "down", "the", "tree", "until", "hitting", "a", "leaf", "calculating", "the", "hash", "at", "each", "level", "and", "returning", "the", "resulting", "hash", "of", "Node", "n", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L42-L62
9,727
cbergoon/merkletree
merkle_tree.go
calculateNodeHash
func (n *Node) calculateNodeHash() ([]byte, error) { if n.leaf { return n.C.CalculateHash() } h := sha256.New() if _, err := h.Write(append(n.Left.Hash, n.Right.Hash...)); err != nil { return nil, err } return h.Sum(nil), nil }
go
func (n *Node) calculateNodeHash() ([]byte, error) { if n.leaf { return n.C.CalculateHash() } h := sha256.New() if _, err := h.Write(append(n.Left.Hash, n.Right.Hash...)); err != nil { return nil, err } return h.Sum(nil), nil }
[ "func", "(", "n", "*", "Node", ")", "calculateNodeHash", "(", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "if", "n", ".", "leaf", "{", "return", "n", ".", "C", ".", "CalculateHash", "(", ")", "\n", "}", "\n\n", "h", ":=", "sha256", ".", "New", "(", ")", "\n", "if", "_", ",", "err", ":=", "h", ".", "Write", "(", "append", "(", "n", ".", "Left", ".", "Hash", ",", "n", ".", "Right", ".", "Hash", "...", ")", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n\n", "return", "h", ".", "Sum", "(", "nil", ")", ",", "nil", "\n", "}" ]
//calculateNodeHash is a helper function that calculates the hash of the node.
[ "calculateNodeHash", "is", "a", "helper", "function", "that", "calculates", "the", "hash", "of", "the", "node", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L65-L76
9,728
cbergoon/merkletree
merkle_tree.go
NewTree
func NewTree(cs []Content) (*MerkleTree, error) { root, leafs, err := buildWithContent(cs) if err != nil { return nil, err } t := &MerkleTree{ Root: root, merkleRoot: root.Hash, Leafs: leafs, } return t, nil }
go
func NewTree(cs []Content) (*MerkleTree, error) { root, leafs, err := buildWithContent(cs) if err != nil { return nil, err } t := &MerkleTree{ Root: root, merkleRoot: root.Hash, Leafs: leafs, } return t, nil }
[ "func", "NewTree", "(", "cs", "[", "]", "Content", ")", "(", "*", "MerkleTree", ",", "error", ")", "{", "root", ",", "leafs", ",", "err", ":=", "buildWithContent", "(", "cs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "t", ":=", "&", "MerkleTree", "{", "Root", ":", "root", ",", "merkleRoot", ":", "root", ".", "Hash", ",", "Leafs", ":", "leafs", ",", "}", "\n", "return", "t", ",", "nil", "\n", "}" ]
//NewTree creates a new Merkle Tree using the content cs.
[ "NewTree", "creates", "a", "new", "Merkle", "Tree", "using", "the", "content", "cs", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L79-L90
9,729
cbergoon/merkletree
merkle_tree.go
buildWithContent
func buildWithContent(cs []Content) (*Node, []*Node, error) { if len(cs) == 0 { return nil, nil, errors.New("error: cannot construct tree with no content") } var leafs []*Node for _, c := range cs { hash, err := c.CalculateHash() if err != nil { return nil, nil, err } leafs = append(leafs, &Node{ Hash: hash, C: c, leaf: true, }) } if len(leafs)%2 == 1 { duplicate := &Node{ Hash: leafs[len(leafs)-1].Hash, C: leafs[len(leafs)-1].C, leaf: true, dup: true, } leafs = append(leafs, duplicate) } root, err := buildIntermediate(leafs) if err != nil { return nil, nil, err } return root, leafs, nil }
go
func buildWithContent(cs []Content) (*Node, []*Node, error) { if len(cs) == 0 { return nil, nil, errors.New("error: cannot construct tree with no content") } var leafs []*Node for _, c := range cs { hash, err := c.CalculateHash() if err != nil { return nil, nil, err } leafs = append(leafs, &Node{ Hash: hash, C: c, leaf: true, }) } if len(leafs)%2 == 1 { duplicate := &Node{ Hash: leafs[len(leafs)-1].Hash, C: leafs[len(leafs)-1].C, leaf: true, dup: true, } leafs = append(leafs, duplicate) } root, err := buildIntermediate(leafs) if err != nil { return nil, nil, err } return root, leafs, nil }
[ "func", "buildWithContent", "(", "cs", "[", "]", "Content", ")", "(", "*", "Node", ",", "[", "]", "*", "Node", ",", "error", ")", "{", "if", "len", "(", "cs", ")", "==", "0", "{", "return", "nil", ",", "nil", ",", "errors", ".", "New", "(", "\"", "\"", ")", "\n", "}", "\n", "var", "leafs", "[", "]", "*", "Node", "\n", "for", "_", ",", "c", ":=", "range", "cs", "{", "hash", ",", "err", ":=", "c", ".", "CalculateHash", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "leafs", "=", "append", "(", "leafs", ",", "&", "Node", "{", "Hash", ":", "hash", ",", "C", ":", "c", ",", "leaf", ":", "true", ",", "}", ")", "\n", "}", "\n", "if", "len", "(", "leafs", ")", "%", "2", "==", "1", "{", "duplicate", ":=", "&", "Node", "{", "Hash", ":", "leafs", "[", "len", "(", "leafs", ")", "-", "1", "]", ".", "Hash", ",", "C", ":", "leafs", "[", "len", "(", "leafs", ")", "-", "1", "]", ".", "C", ",", "leaf", ":", "true", ",", "dup", ":", "true", ",", "}", "\n", "leafs", "=", "append", "(", "leafs", ",", "duplicate", ")", "\n", "}", "\n", "root", ",", "err", ":=", "buildIntermediate", "(", "leafs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "nil", ",", "err", "\n", "}", "\n\n", "return", "root", ",", "leafs", ",", "nil", "\n", "}" ]
//buildWithContent is a helper function that for a given set of Contents, generates a //corresponding tree and returns the root node, a list of leaf nodes, and a possible error. //Returns an error if cs contains no Contents.
[ "buildWithContent", "is", "a", "helper", "function", "that", "for", "a", "given", "set", "of", "Contents", "generates", "a", "corresponding", "tree", "and", "returns", "the", "root", "node", "a", "list", "of", "leaf", "nodes", "and", "a", "possible", "error", ".", "Returns", "an", "error", "if", "cs", "contains", "no", "Contents", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L124-L156
9,730
cbergoon/merkletree
merkle_tree.go
buildIntermediate
func buildIntermediate(nl []*Node) (*Node, error) { var nodes []*Node for i := 0; i < len(nl); i += 2 { h := sha256.New() var left, right int = i, i + 1 if i+1 == len(nl) { right = i } chash := append(nl[left].Hash, nl[right].Hash...) if _, err := h.Write(chash); err != nil { return nil, err } n := &Node{ Left: nl[left], Right: nl[right], Hash: h.Sum(nil), } nodes = append(nodes, n) nl[left].Parent = n nl[right].Parent = n if len(nl) == 2 { return n, nil } } return buildIntermediate(nodes) }
go
func buildIntermediate(nl []*Node) (*Node, error) { var nodes []*Node for i := 0; i < len(nl); i += 2 { h := sha256.New() var left, right int = i, i + 1 if i+1 == len(nl) { right = i } chash := append(nl[left].Hash, nl[right].Hash...) if _, err := h.Write(chash); err != nil { return nil, err } n := &Node{ Left: nl[left], Right: nl[right], Hash: h.Sum(nil), } nodes = append(nodes, n) nl[left].Parent = n nl[right].Parent = n if len(nl) == 2 { return n, nil } } return buildIntermediate(nodes) }
[ "func", "buildIntermediate", "(", "nl", "[", "]", "*", "Node", ")", "(", "*", "Node", ",", "error", ")", "{", "var", "nodes", "[", "]", "*", "Node", "\n", "for", "i", ":=", "0", ";", "i", "<", "len", "(", "nl", ")", ";", "i", "+=", "2", "{", "h", ":=", "sha256", ".", "New", "(", ")", "\n", "var", "left", ",", "right", "int", "=", "i", ",", "i", "+", "1", "\n", "if", "i", "+", "1", "==", "len", "(", "nl", ")", "{", "right", "=", "i", "\n", "}", "\n", "chash", ":=", "append", "(", "nl", "[", "left", "]", ".", "Hash", ",", "nl", "[", "right", "]", ".", "Hash", "...", ")", "\n", "if", "_", ",", "err", ":=", "h", ".", "Write", "(", "chash", ")", ";", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "n", ":=", "&", "Node", "{", "Left", ":", "nl", "[", "left", "]", ",", "Right", ":", "nl", "[", "right", "]", ",", "Hash", ":", "h", ".", "Sum", "(", "nil", ")", ",", "}", "\n", "nodes", "=", "append", "(", "nodes", ",", "n", ")", "\n", "nl", "[", "left", "]", ".", "Parent", "=", "n", "\n", "nl", "[", "right", "]", ".", "Parent", "=", "n", "\n", "if", "len", "(", "nl", ")", "==", "2", "{", "return", "n", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "buildIntermediate", "(", "nodes", ")", "\n", "}" ]
//buildIntermediate is a helper function that for a given list of leaf nodes, constructs //the intermediate and root levels of the tree. Returns the resulting root node of the tree.
[ "buildIntermediate", "is", "a", "helper", "function", "that", "for", "a", "given", "list", "of", "leaf", "nodes", "constructs", "the", "intermediate", "and", "root", "levels", "of", "the", "tree", ".", "Returns", "the", "resulting", "root", "node", "of", "the", "tree", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L160-L185
9,731
cbergoon/merkletree
merkle_tree.go
RebuildTree
func (m *MerkleTree) RebuildTree() error { var cs []Content for _, c := range m.Leafs { cs = append(cs, c.C) } root, leafs, err := buildWithContent(cs) if err != nil { return err } m.Root = root m.Leafs = leafs m.merkleRoot = root.Hash return nil }
go
func (m *MerkleTree) RebuildTree() error { var cs []Content for _, c := range m.Leafs { cs = append(cs, c.C) } root, leafs, err := buildWithContent(cs) if err != nil { return err } m.Root = root m.Leafs = leafs m.merkleRoot = root.Hash return nil }
[ "func", "(", "m", "*", "MerkleTree", ")", "RebuildTree", "(", ")", "error", "{", "var", "cs", "[", "]", "Content", "\n", "for", "_", ",", "c", ":=", "range", "m", ".", "Leafs", "{", "cs", "=", "append", "(", "cs", ",", "c", ".", "C", ")", "\n", "}", "\n", "root", ",", "leafs", ",", "err", ":=", "buildWithContent", "(", "cs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "m", ".", "Root", "=", "root", "\n", "m", ".", "Leafs", "=", "leafs", "\n", "m", ".", "merkleRoot", "=", "root", ".", "Hash", "\n", "return", "nil", "\n", "}" ]
//RebuildTree is a helper function that will rebuild the tree reusing only the content that //it holds in the leaves.
[ "RebuildTree", "is", "a", "helper", "function", "that", "will", "rebuild", "the", "tree", "reusing", "only", "the", "content", "that", "it", "holds", "in", "the", "leaves", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L194-L207
9,732
cbergoon/merkletree
merkle_tree.go
RebuildTreeWith
func (m *MerkleTree) RebuildTreeWith(cs []Content) error { root, leafs, err := buildWithContent(cs) if err != nil { return err } m.Root = root m.Leafs = leafs m.merkleRoot = root.Hash return nil }
go
func (m *MerkleTree) RebuildTreeWith(cs []Content) error { root, leafs, err := buildWithContent(cs) if err != nil { return err } m.Root = root m.Leafs = leafs m.merkleRoot = root.Hash return nil }
[ "func", "(", "m", "*", "MerkleTree", ")", "RebuildTreeWith", "(", "cs", "[", "]", "Content", ")", "error", "{", "root", ",", "leafs", ",", "err", ":=", "buildWithContent", "(", "cs", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "m", ".", "Root", "=", "root", "\n", "m", ".", "Leafs", "=", "leafs", "\n", "m", ".", "merkleRoot", "=", "root", ".", "Hash", "\n", "return", "nil", "\n", "}" ]
//RebuildTreeWith replaces the content of the tree and does a complete rebuild; while the root of //the tree will be replaced the MerkleTree completely survives this operation. Returns an error if the //list of content cs contains no entries.
[ "RebuildTreeWith", "replaces", "the", "content", "of", "the", "tree", "and", "does", "a", "complete", "rebuild", ";", "while", "the", "root", "of", "the", "tree", "will", "be", "replaced", "the", "MerkleTree", "completely", "survives", "this", "operation", ".", "Returns", "an", "error", "if", "the", "list", "of", "content", "cs", "contains", "no", "entries", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L212-L221
9,733
cbergoon/merkletree
merkle_tree.go
VerifyTree
func (m *MerkleTree) VerifyTree() (bool, error) { calculatedMerkleRoot, err := m.Root.verifyNode() if err != nil { return false, err } if bytes.Compare(m.merkleRoot, calculatedMerkleRoot) == 0 { return true, nil } return false, nil }
go
func (m *MerkleTree) VerifyTree() (bool, error) { calculatedMerkleRoot, err := m.Root.verifyNode() if err != nil { return false, err } if bytes.Compare(m.merkleRoot, calculatedMerkleRoot) == 0 { return true, nil } return false, nil }
[ "func", "(", "m", "*", "MerkleTree", ")", "VerifyTree", "(", ")", "(", "bool", ",", "error", ")", "{", "calculatedMerkleRoot", ",", "err", ":=", "m", ".", "Root", ".", "verifyNode", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "bytes", ".", "Compare", "(", "m", ".", "merkleRoot", ",", "calculatedMerkleRoot", ")", "==", "0", "{", "return", "true", ",", "nil", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
//VerifyTree verify tree validates the hashes at each level of the tree and returns true if the //resulting hash at the root of the tree matches the resulting root hash; returns false otherwise.
[ "VerifyTree", "verify", "tree", "validates", "the", "hashes", "at", "each", "level", "of", "the", "tree", "and", "returns", "true", "if", "the", "resulting", "hash", "at", "the", "root", "of", "the", "tree", "matches", "the", "resulting", "root", "hash", ";", "returns", "false", "otherwise", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L225-L235
9,734
cbergoon/merkletree
merkle_tree.go
VerifyContent
func (m *MerkleTree) VerifyContent(content Content) (bool, error) { for _, l := range m.Leafs { ok, err := l.C.Equals(content) if err != nil { return false, err } if ok { currentParent := l.Parent for currentParent != nil { h := sha256.New() rightBytes, err := currentParent.Right.calculateNodeHash() if err != nil { return false, err } leftBytes, err := currentParent.Left.calculateNodeHash() if err != nil { return false, err } if _, err := h.Write(append(leftBytes, rightBytes...)); err != nil { return false, err } if bytes.Compare(h.Sum(nil), currentParent.Hash) != 0 { return false, nil } currentParent = currentParent.Parent } return true, nil } } return false, nil }
go
func (m *MerkleTree) VerifyContent(content Content) (bool, error) { for _, l := range m.Leafs { ok, err := l.C.Equals(content) if err != nil { return false, err } if ok { currentParent := l.Parent for currentParent != nil { h := sha256.New() rightBytes, err := currentParent.Right.calculateNodeHash() if err != nil { return false, err } leftBytes, err := currentParent.Left.calculateNodeHash() if err != nil { return false, err } if _, err := h.Write(append(leftBytes, rightBytes...)); err != nil { return false, err } if bytes.Compare(h.Sum(nil), currentParent.Hash) != 0 { return false, nil } currentParent = currentParent.Parent } return true, nil } } return false, nil }
[ "func", "(", "m", "*", "MerkleTree", ")", "VerifyContent", "(", "content", "Content", ")", "(", "bool", ",", "error", ")", "{", "for", "_", ",", "l", ":=", "range", "m", ".", "Leafs", "{", "ok", ",", "err", ":=", "l", ".", "C", ".", "Equals", "(", "content", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "ok", "{", "currentParent", ":=", "l", ".", "Parent", "\n", "for", "currentParent", "!=", "nil", "{", "h", ":=", "sha256", ".", "New", "(", ")", "\n", "rightBytes", ",", "err", ":=", "currentParent", ".", "Right", ".", "calculateNodeHash", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "leftBytes", ",", "err", ":=", "currentParent", ".", "Left", ".", "calculateNodeHash", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n\n", "if", "_", ",", "err", ":=", "h", ".", "Write", "(", "append", "(", "leftBytes", ",", "rightBytes", "...", ")", ")", ";", "err", "!=", "nil", "{", "return", "false", ",", "err", "\n", "}", "\n", "if", "bytes", ".", "Compare", "(", "h", ".", "Sum", "(", "nil", ")", ",", "currentParent", ".", "Hash", ")", "!=", "0", "{", "return", "false", ",", "nil", "\n", "}", "\n", "currentParent", "=", "currentParent", ".", "Parent", "\n", "}", "\n", "return", "true", ",", "nil", "\n", "}", "\n", "}", "\n", "return", "false", ",", "nil", "\n", "}" ]
//VerifyContent indicates whether a given content is in the tree and the hashes are valid for that content. //Returns true if the expected Merkle Root is equivalent to the Merkle root calculated on the critical path //for a given content. Returns true if valid and false otherwise.
[ "VerifyContent", "indicates", "whether", "a", "given", "content", "is", "in", "the", "tree", "and", "the", "hashes", "are", "valid", "for", "that", "content", ".", "Returns", "true", "if", "the", "expected", "Merkle", "Root", "is", "equivalent", "to", "the", "Merkle", "root", "calculated", "on", "the", "critical", "path", "for", "a", "given", "content", ".", "Returns", "true", "if", "valid", "and", "false", "otherwise", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L240-L273
9,735
cbergoon/merkletree
merkle_tree.go
String
func (m *MerkleTree) String() string { s := "" for _, l := range m.Leafs { s += fmt.Sprint(l) s += "\n" } return s }
go
func (m *MerkleTree) String() string { s := "" for _, l := range m.Leafs { s += fmt.Sprint(l) s += "\n" } return s }
[ "func", "(", "m", "*", "MerkleTree", ")", "String", "(", ")", "string", "{", "s", ":=", "\"", "\"", "\n", "for", "_", ",", "l", ":=", "range", "m", ".", "Leafs", "{", "s", "+=", "fmt", ".", "Sprint", "(", "l", ")", "\n", "s", "+=", "\"", "\\n", "\"", "\n", "}", "\n", "return", "s", "\n", "}" ]
//String returns a string representation of the tree. Only leaf nodes are included //in the output.
[ "String", "returns", "a", "string", "representation", "of", "the", "tree", ".", "Only", "leaf", "nodes", "are", "included", "in", "the", "output", "." ]
015148bca40086408b36bb43ecff4010a7907215
https://github.com/cbergoon/merkletree/blob/015148bca40086408b36bb43ecff4010a7907215/merkle_tree.go#L277-L284
9,736
gchaincl/dotsql
dotsql.go
Load
func Load(r io.Reader) (*DotSql, error) { scanner := &Scanner{} queries := scanner.Run(bufio.NewScanner(r)) dotsql := &DotSql{ queries: queries, } return dotsql, nil }
go
func Load(r io.Reader) (*DotSql, error) { scanner := &Scanner{} queries := scanner.Run(bufio.NewScanner(r)) dotsql := &DotSql{ queries: queries, } return dotsql, nil }
[ "func", "Load", "(", "r", "io", ".", "Reader", ")", "(", "*", "DotSql", ",", "error", ")", "{", "scanner", ":=", "&", "Scanner", "{", "}", "\n", "queries", ":=", "scanner", ".", "Run", "(", "bufio", ".", "NewScanner", "(", "r", ")", ")", "\n\n", "dotsql", ":=", "&", "DotSql", "{", "queries", ":", "queries", ",", "}", "\n\n", "return", "dotsql", ",", "nil", "\n", "}" ]
// Load imports sql queries from any io.Reader.
[ "Load", "imports", "sql", "queries", "from", "any", "io", ".", "Reader", "." ]
f8e452f37f648d9ffee122eeb50bd986dff3c4ca
https://github.com/gchaincl/dotsql/blob/f8e452f37f648d9ffee122eeb50bd986dff3c4ca/dotsql.go#L103-L112
9,737
gchaincl/dotsql
dotsql.go
LoadFromFile
func LoadFromFile(sqlFile string) (*DotSql, error) { f, err := os.Open(sqlFile) if err != nil { return nil, err } defer f.Close() return Load(f) }
go
func LoadFromFile(sqlFile string) (*DotSql, error) { f, err := os.Open(sqlFile) if err != nil { return nil, err } defer f.Close() return Load(f) }
[ "func", "LoadFromFile", "(", "sqlFile", "string", ")", "(", "*", "DotSql", ",", "error", ")", "{", "f", ",", "err", ":=", "os", ".", "Open", "(", "sqlFile", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "defer", "f", ".", "Close", "(", ")", "\n\n", "return", "Load", "(", "f", ")", "\n", "}" ]
// LoadFromFile imports SQL queries from the file.
[ "LoadFromFile", "imports", "SQL", "queries", "from", "the", "file", "." ]
f8e452f37f648d9ffee122eeb50bd986dff3c4ca
https://github.com/gchaincl/dotsql/blob/f8e452f37f648d9ffee122eeb50bd986dff3c4ca/dotsql.go#L115-L123
9,738
gchaincl/dotsql
dotsql.go
LoadFromString
func LoadFromString(sql string) (*DotSql, error) { buf := bytes.NewBufferString(sql) return Load(buf) }
go
func LoadFromString(sql string) (*DotSql, error) { buf := bytes.NewBufferString(sql) return Load(buf) }
[ "func", "LoadFromString", "(", "sql", "string", ")", "(", "*", "DotSql", ",", "error", ")", "{", "buf", ":=", "bytes", ".", "NewBufferString", "(", "sql", ")", "\n", "return", "Load", "(", "buf", ")", "\n", "}" ]
// LoadFromString imports SQL queries from the string.
[ "LoadFromString", "imports", "SQL", "queries", "from", "the", "string", "." ]
f8e452f37f648d9ffee122eeb50bd986dff3c4ca
https://github.com/gchaincl/dotsql/blob/f8e452f37f648d9ffee122eeb50bd986dff3c4ca/dotsql.go#L126-L129
9,739
go-redis/cache
cache.go
UseLocalCache
func (cd *Codec) UseLocalCache(maxLen int, expiration time.Duration) { cd.localCache = lrucache.New(maxLen, expiration) }
go
func (cd *Codec) UseLocalCache(maxLen int, expiration time.Duration) { cd.localCache = lrucache.New(maxLen, expiration) }
[ "func", "(", "cd", "*", "Codec", ")", "UseLocalCache", "(", "maxLen", "int", ",", "expiration", "time", ".", "Duration", ")", "{", "cd", ".", "localCache", "=", "lrucache", ".", "New", "(", "maxLen", ",", "expiration", ")", "\n", "}" ]
// UseLocalCache causes Codec to cache items in local LRU cache.
[ "UseLocalCache", "causes", "Codec", "to", "cache", "items", "in", "local", "LRU", "cache", "." ]
a5ee4f2d5b9707072a51d87313cfebf2935aed4f
https://github.com/go-redis/cache/blob/a5ee4f2d5b9707072a51d87313cfebf2935aed4f/cache.go#L81-L83
9,740
go-redis/cache
cache.go
Set
func (cd *Codec) Set(item *Item) error { cd.beforeSet(item) _, err := cd.setItem(item) cd.afterSet(item) return err }
go
func (cd *Codec) Set(item *Item) error { cd.beforeSet(item) _, err := cd.setItem(item) cd.afterSet(item) return err }
[ "func", "(", "cd", "*", "Codec", ")", "Set", "(", "item", "*", "Item", ")", "error", "{", "cd", ".", "beforeSet", "(", "item", ")", "\n", "_", ",", "err", ":=", "cd", ".", "setItem", "(", "item", ")", "\n", "cd", ".", "afterSet", "(", "item", ")", "\n", "return", "err", "\n", "}" ]
// Set caches the item.
[ "Set", "caches", "the", "item", "." ]
a5ee4f2d5b9707072a51d87313cfebf2935aed4f
https://github.com/go-redis/cache/blob/a5ee4f2d5b9707072a51d87313cfebf2935aed4f/cache.go#L86-L91
9,741
go-redis/cache
cache.go
Exists
func (cd *Codec) Exists(key string) bool { return cd.Get(key, nil) == nil }
go
func (cd *Codec) Exists(key string) bool { return cd.Get(key, nil) == nil }
[ "func", "(", "cd", "*", "Codec", ")", "Exists", "(", "key", "string", ")", "bool", "{", "return", "cd", ".", "Get", "(", "key", ",", "nil", ")", "==", "nil", "\n", "}" ]
// Exists reports whether object for the given key exists.
[ "Exists", "reports", "whether", "object", "for", "the", "given", "key", "exists", "." ]
a5ee4f2d5b9707072a51d87313cfebf2935aed4f
https://github.com/go-redis/cache/blob/a5ee4f2d5b9707072a51d87313cfebf2935aed4f/cache.go#L124-L126
9,742
go-redis/cache
cache.go
Get
func (cd *Codec) Get(key string, object interface{}) error { return cd.get(nil, key, object) }
go
func (cd *Codec) Get(key string, object interface{}) error { return cd.get(nil, key, object) }
[ "func", "(", "cd", "*", "Codec", ")", "Get", "(", "key", "string", ",", "object", "interface", "{", "}", ")", "error", "{", "return", "cd", ".", "get", "(", "nil", ",", "key", ",", "object", ")", "\n", "}" ]
// Get gets the object for the given key.
[ "Get", "gets", "the", "object", "for", "the", "given", "key", "." ]
a5ee4f2d5b9707072a51d87313cfebf2935aed4f
https://github.com/go-redis/cache/blob/a5ee4f2d5b9707072a51d87313cfebf2935aed4f/cache.go#L129-L131
9,743
go-redis/cache
cache.go
Once
func (cd *Codec) Once(item *Item) error { cd.beforeOnce(item) err := cd.once(item) cd.afterOnce(item) return err }
go
func (cd *Codec) Once(item *Item) error { cd.beforeOnce(item) err := cd.once(item) cd.afterOnce(item) return err }
[ "func", "(", "cd", "*", "Codec", ")", "Once", "(", "item", "*", "Item", ")", "error", "{", "cd", ".", "beforeOnce", "(", "item", ")", "\n", "err", ":=", "cd", ".", "once", "(", "item", ")", "\n", "cd", ".", "afterOnce", "(", "item", ")", "\n", "return", "err", "\n", "}" ]
// Once gets the item.Object for the given item.Key from the cache or // executes, caches, and returns the results of the given item.Func, // making sure that only one execution is in-flight for a given item.Key // at a time. If a duplicate comes in, the duplicate caller waits for the // original to complete and receives the same results.
[ "Once", "gets", "the", "item", ".", "Object", "for", "the", "given", "item", ".", "Key", "from", "the", "cache", "or", "executes", "caches", "and", "returns", "the", "results", "of", "the", "given", "item", ".", "Func", "making", "sure", "that", "only", "one", "execution", "is", "in", "-", "flight", "for", "a", "given", "item", ".", "Key", "at", "a", "time", ".", "If", "a", "duplicate", "comes", "in", "the", "duplicate", "caller", "waits", "for", "the", "original", "to", "complete", "and", "receives", "the", "same", "results", "." ]
a5ee4f2d5b9707072a51d87313cfebf2935aed4f
https://github.com/go-redis/cache/blob/a5ee4f2d5b9707072a51d87313cfebf2935aed4f/cache.go#L205-L210
9,744
go-redis/cache
cache.go
Stats
func (cd *Codec) Stats() *Stats { stats := Stats{ Hits: atomic.LoadUint64(&cd.hits), Misses: atomic.LoadUint64(&cd.misses), } if cd.localCache != nil { stats.LocalHits = atomic.LoadUint64(&cd.localHits) stats.LocalMisses = atomic.LoadUint64(&cd.localMisses) } return &stats }
go
func (cd *Codec) Stats() *Stats { stats := Stats{ Hits: atomic.LoadUint64(&cd.hits), Misses: atomic.LoadUint64(&cd.misses), } if cd.localCache != nil { stats.LocalHits = atomic.LoadUint64(&cd.localHits) stats.LocalMisses = atomic.LoadUint64(&cd.localMisses) } return &stats }
[ "func", "(", "cd", "*", "Codec", ")", "Stats", "(", ")", "*", "Stats", "{", "stats", ":=", "Stats", "{", "Hits", ":", "atomic", ".", "LoadUint64", "(", "&", "cd", ".", "hits", ")", ",", "Misses", ":", "atomic", ".", "LoadUint64", "(", "&", "cd", ".", "misses", ")", ",", "}", "\n", "if", "cd", ".", "localCache", "!=", "nil", "{", "stats", ".", "LocalHits", "=", "atomic", ".", "LoadUint64", "(", "&", "cd", ".", "localHits", ")", "\n", "stats", ".", "LocalMisses", "=", "atomic", ".", "LoadUint64", "(", "&", "cd", ".", "localMisses", ")", "\n", "}", "\n", "return", "&", "stats", "\n", "}" ]
// Stats returns cache statistics.
[ "Stats", "returns", "cache", "statistics", "." ]
a5ee4f2d5b9707072a51d87313cfebf2935aed4f
https://github.com/go-redis/cache/blob/a5ee4f2d5b9707072a51d87313cfebf2935aed4f/cache.go#L392-L402
9,745
pravj/geopattern
examples/default.go
main
func main() { args := map[string]string{} gp := geopattern.Generate(args) fmt.Println(gp) }
go
func main() { args := map[string]string{} gp := geopattern.Generate(args) fmt.Println(gp) }
[ "func", "main", "(", ")", "{", "args", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "gp", ":=", "geopattern", ".", "Generate", "(", "args", ")", "\n", "fmt", ".", "Println", "(", "gp", ")", "\n", "}" ]
// Prints pattern's SVG string without any argument
[ "Prints", "pattern", "s", "SVG", "string", "without", "any", "argument" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/examples/default.go#L9-L13
9,746
pravj/geopattern
geopattern.go
Generate
func Generate(args map[string]string) string { p := pattern.New(args) return p.SvgStr() }
go
func Generate(args map[string]string) string { p := pattern.New(args) return p.SvgStr() }
[ "func", "Generate", "(", "args", "map", "[", "string", "]", "string", ")", "string", "{", "p", ":=", "pattern", ".", "New", "(", "args", ")", "\n\n", "return", "p", ".", "SvgStr", "(", ")", "\n", "}" ]
// Generate returns pattern's SVG string
[ "Generate", "returns", "pattern", "s", "SVG", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/geopattern.go#L11-L15
9,747
pravj/geopattern
geopattern.go
Base64String
func Base64String(args map[string]string) string { svgStr := Generate(args) base64Str := base64.StdEncoding.EncodeToString([]byte(svgStr)) return base64Str }
go
func Base64String(args map[string]string) string { svgStr := Generate(args) base64Str := base64.StdEncoding.EncodeToString([]byte(svgStr)) return base64Str }
[ "func", "Base64String", "(", "args", "map", "[", "string", "]", "string", ")", "string", "{", "svgStr", ":=", "Generate", "(", "args", ")", "\n", "base64Str", ":=", "base64", ".", "StdEncoding", ".", "EncodeToString", "(", "[", "]", "byte", "(", "svgStr", ")", ")", "\n\n", "return", "base64Str", "\n", "}" ]
// Base64String returns pattern's Base64 encoded string
[ "Base64String", "returns", "pattern", "s", "Base64", "encoded", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/geopattern.go#L18-L23
9,748
pravj/geopattern
geopattern.go
URIimage
func URIimage(args map[string]string) string { base64Str := Base64String(args) return fmt.Sprintf("url(data:image/svg+xml;base64,%s);", base64Str) }
go
func URIimage(args map[string]string) string { base64Str := Base64String(args) return fmt.Sprintf("url(data:image/svg+xml;base64,%s);", base64Str) }
[ "func", "URIimage", "(", "args", "map", "[", "string", "]", "string", ")", "string", "{", "base64Str", ":=", "Base64String", "(", "args", ")", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "base64Str", ")", "\n", "}" ]
// URIimage returns pattern's uri image string
[ "URIimage", "returns", "pattern", "s", "uri", "image", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/geopattern.go#L26-L30
9,749
pravj/geopattern
utils/utils.go
Hash
func Hash(s string) string { h := sha1.New() h.Write([]byte(s)) hash := h.Sum(nil) return fmt.Sprintf("%x", hash) }
go
func Hash(s string) string { h := sha1.New() h.Write([]byte(s)) hash := h.Sum(nil) return fmt.Sprintf("%x", hash) }
[ "func", "Hash", "(", "s", "string", ")", "string", "{", "h", ":=", "sha1", ".", "New", "(", ")", "\n", "h", ".", "Write", "(", "[", "]", "byte", "(", "s", ")", ")", "\n\n", "hash", ":=", "h", ".", "Sum", "(", "nil", ")", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "hash", ")", "\n", "}" ]
// Hash returns SHA-1 encryption of a string
[ "Hash", "returns", "SHA", "-", "1", "encryption", "of", "a", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/utils/utils.go#L24-L31
9,750
pravj/geopattern
utils/utils.go
Map
func Map(value, aMin, aMax, bMin, bMax float64) float64 { aRange := aMax - aMin bRange := bMax - bMin return (bMax - (aMax-value)*(bRange/aRange)) }
go
func Map(value, aMin, aMax, bMin, bMax float64) float64 { aRange := aMax - aMin bRange := bMax - bMin return (bMax - (aMax-value)*(bRange/aRange)) }
[ "func", "Map", "(", "value", ",", "aMin", ",", "aMax", ",", "bMin", ",", "bMax", "float64", ")", "float64", "{", "aRange", ":=", "aMax", "-", "aMin", "\n", "bRange", ":=", "bMax", "-", "bMin", "\n\n", "return", "(", "bMax", "-", "(", "aMax", "-", "value", ")", "*", "(", "bRange", "/", "aRange", ")", ")", "\n", "}" ]
// Map returns respective value of a number from a range to different range
[ "Map", "returns", "respective", "value", "of", "a", "number", "from", "a", "range", "to", "different", "range" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/utils/utils.go#L34-L39
9,751
pravj/geopattern
utils/utils.go
HexVal
func HexVal(str string, index, length int) float64 { hexStr := str[index : index+length] hexVal, err := strconv.ParseInt(hexStr, 16, 0) if err != nil { panic(err) } return float64(hexVal) }
go
func HexVal(str string, index, length int) float64 { hexStr := str[index : index+length] hexVal, err := strconv.ParseInt(hexStr, 16, 0) if err != nil { panic(err) } return float64(hexVal) }
[ "func", "HexVal", "(", "str", "string", ",", "index", ",", "length", "int", ")", "float64", "{", "hexStr", ":=", "str", "[", "index", ":", "index", "+", "length", "]", "\n\n", "hexVal", ",", "err", ":=", "strconv", ".", "ParseInt", "(", "hexStr", ",", "16", ",", "0", ")", "\n", "if", "err", "!=", "nil", "{", "panic", "(", "err", ")", "\n", "}", "\n\n", "return", "float64", "(", "hexVal", ")", "\n", "}" ]
// HexVal returns decimal representation of a substring of a hexa decimal string
[ "HexVal", "returns", "decimal", "representation", "of", "a", "substring", "of", "a", "hexa", "decimal", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/utils/utils.go#L42-L51
9,752
pravj/geopattern
utils/utils.go
Merge
func Merge(mapA map[string]interface{}, mapB map[string]interface{}) map[string]interface{} { for k, v := range mapA { mapB[k] = v } return mapB }
go
func Merge(mapA map[string]interface{}, mapB map[string]interface{}) map[string]interface{} { for k, v := range mapA { mapB[k] = v } return mapB }
[ "func", "Merge", "(", "mapA", "map", "[", "string", "]", "interface", "{", "}", ",", "mapB", "map", "[", "string", "]", "interface", "{", "}", ")", "map", "[", "string", "]", "interface", "{", "}", "{", "for", "k", ",", "v", ":=", "range", "mapA", "{", "mapB", "[", "k", "]", "=", "v", "\n", "}", "\n\n", "return", "mapB", "\n", "}" ]
// Merge merges two 'map' objects and returns the resultant object
[ "Merge", "merges", "two", "map", "objects", "and", "returns", "the", "resultant", "object" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/utils/utils.go#L54-L60
9,753
pravj/geopattern
examples/uri_image.go
main
func main() { args := map[string]string{} gp := geopattern.URIimage(args) fmt.Println(gp) }
go
func main() { args := map[string]string{} gp := geopattern.URIimage(args) fmt.Println(gp) }
[ "func", "main", "(", ")", "{", "args", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "gp", ":=", "geopattern", ".", "URIimage", "(", "args", ")", "\n", "fmt", ".", "Println", "(", "gp", ")", "\n", "}" ]
// Prints pattern's uri image string
[ "Prints", "pattern", "s", "uri", "image", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/examples/uri_image.go#L9-L13
9,754
pravj/geopattern
pattern/pattern.go
New
func New(args map[string]string) *Pattern { var phrase, generator, color, baseColor string phrase = fmt.Sprintf("%s", time.Now().Local()) if args["phrase"] != "" { phrase = args["phrase"] } if args["generator"] != "" { generator = args["generator"] } if args["color"] != "" { color = args["color"] } if args["baseColor"] != "" { baseColor = args["baseColor"] } return &Pattern{BaseColor: baseColor, Color: color, Generator: generator, Hash: utils.Hash(phrase), Svg: new(svg.SVG)} }
go
func New(args map[string]string) *Pattern { var phrase, generator, color, baseColor string phrase = fmt.Sprintf("%s", time.Now().Local()) if args["phrase"] != "" { phrase = args["phrase"] } if args["generator"] != "" { generator = args["generator"] } if args["color"] != "" { color = args["color"] } if args["baseColor"] != "" { baseColor = args["baseColor"] } return &Pattern{BaseColor: baseColor, Color: color, Generator: generator, Hash: utils.Hash(phrase), Svg: new(svg.SVG)} }
[ "func", "New", "(", "args", "map", "[", "string", "]", "string", ")", "*", "Pattern", "{", "var", "phrase", ",", "generator", ",", "color", ",", "baseColor", "string", "\n\n", "phrase", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "time", ".", "Now", "(", ")", ".", "Local", "(", ")", ")", "\n\n", "if", "args", "[", "\"", "\"", "]", "!=", "\"", "\"", "{", "phrase", "=", "args", "[", "\"", "\"", "]", "\n", "}", "\n\n", "if", "args", "[", "\"", "\"", "]", "!=", "\"", "\"", "{", "generator", "=", "args", "[", "\"", "\"", "]", "\n", "}", "\n\n", "if", "args", "[", "\"", "\"", "]", "!=", "\"", "\"", "{", "color", "=", "args", "[", "\"", "\"", "]", "\n", "}", "\n\n", "if", "args", "[", "\"", "\"", "]", "!=", "\"", "\"", "{", "baseColor", "=", "args", "[", "\"", "\"", "]", "\n", "}", "\n\n", "return", "&", "Pattern", "{", "BaseColor", ":", "baseColor", ",", "Color", ":", "color", ",", "Generator", ":", "generator", ",", "Hash", ":", "utils", ".", "Hash", "(", "phrase", ")", ",", "Svg", ":", "new", "(", "svg", ".", "SVG", ")", "}", "\n", "}" ]
// New parses the arguments and returns an instance of Pattern struct that has linked // methods to work further things
[ "New", "parses", "the", "arguments", "and", "returns", "an", "instance", "of", "Pattern", "struct", "that", "has", "linked", "methods", "to", "work", "further", "things" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L48-L70
9,755
pravj/geopattern
pattern/pattern.go
SvgStr
func (p *Pattern) SvgStr() string { p.generateBackground() p.genaratePattern() return p.Svg.Str() }
go
func (p *Pattern) SvgStr() string { p.generateBackground() p.genaratePattern() return p.Svg.Str() }
[ "func", "(", "p", "*", "Pattern", ")", "SvgStr", "(", ")", "string", "{", "p", ".", "generateBackground", "(", ")", "\n", "p", ".", "genaratePattern", "(", ")", "\n\n", "return", "p", ".", "Svg", ".", "Str", "(", ")", "\n", "}" ]
// SvgStr returns string representing pattern's SVG string
[ "SvgStr", "returns", "string", "representing", "pattern", "s", "SVG", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L73-L78
9,756
pravj/geopattern
pattern/pattern.go
generateBackground
func (p *Pattern) generateBackground() { var rgb, color colorful.Color if p.Color != "" { rgb, _ = colorful.Hex(p.Color) } else { hueOffset := utils.Map(utils.HexVal(p.Hash, 14, 3), 0, 4095, 0, 359) satOffset := utils.Map(utils.HexVal(p.Hash, 17, 1), 0, 15, -1, 1) if p.BaseColor == "" { color, _ = colorful.Hex(utils.BaseColor) } else { color, _ = colorful.Hex(p.BaseColor) } h, c, l := color.Hcl() h -= hueOffset if satOffset >= 0 { c += float64(satOffset) } else { c -= float64(satOffset) } rgb = colorful.Color{h, c, l} } r, g, b := int(rgb.R*105), int(rgb.G*105), int(rgb.B*150) args := make(map[string]interface{}) args["fill"] = fmt.Sprintf("rgb(%v, %v, %v)", r, g, b) p.Svg.Rect(0, 0, "100%", "100%", args) }
go
func (p *Pattern) generateBackground() { var rgb, color colorful.Color if p.Color != "" { rgb, _ = colorful.Hex(p.Color) } else { hueOffset := utils.Map(utils.HexVal(p.Hash, 14, 3), 0, 4095, 0, 359) satOffset := utils.Map(utils.HexVal(p.Hash, 17, 1), 0, 15, -1, 1) if p.BaseColor == "" { color, _ = colorful.Hex(utils.BaseColor) } else { color, _ = colorful.Hex(p.BaseColor) } h, c, l := color.Hcl() h -= hueOffset if satOffset >= 0 { c += float64(satOffset) } else { c -= float64(satOffset) } rgb = colorful.Color{h, c, l} } r, g, b := int(rgb.R*105), int(rgb.G*105), int(rgb.B*150) args := make(map[string]interface{}) args["fill"] = fmt.Sprintf("rgb(%v, %v, %v)", r, g, b) p.Svg.Rect(0, 0, "100%", "100%", args) }
[ "func", "(", "p", "*", "Pattern", ")", "generateBackground", "(", ")", "{", "var", "rgb", ",", "color", "colorful", ".", "Color", "\n\n", "if", "p", ".", "Color", "!=", "\"", "\"", "{", "rgb", ",", "_", "=", "colorful", ".", "Hex", "(", "p", ".", "Color", ")", "\n", "}", "else", "{", "hueOffset", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "14", ",", "3", ")", ",", "0", ",", "4095", ",", "0", ",", "359", ")", "\n", "satOffset", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "17", ",", "1", ")", ",", "0", ",", "15", ",", "-", "1", ",", "1", ")", "\n\n", "if", "p", ".", "BaseColor", "==", "\"", "\"", "{", "color", ",", "_", "=", "colorful", ".", "Hex", "(", "utils", ".", "BaseColor", ")", "\n", "}", "else", "{", "color", ",", "_", "=", "colorful", ".", "Hex", "(", "p", ".", "BaseColor", ")", "\n", "}", "\n\n", "h", ",", "c", ",", "l", ":=", "color", ".", "Hcl", "(", ")", "\n\n", "h", "-=", "hueOffset", "\n", "if", "satOffset", ">=", "0", "{", "c", "+=", "float64", "(", "satOffset", ")", "\n", "}", "else", "{", "c", "-=", "float64", "(", "satOffset", ")", "\n", "}", "\n\n", "rgb", "=", "colorful", ".", "Color", "{", "h", ",", "c", ",", "l", "}", "\n", "}", "\n\n", "r", ",", "g", ",", "b", ":=", "int", "(", "rgb", ".", "R", "*", "105", ")", ",", "int", "(", "rgb", ".", "G", "*", "105", ")", ",", "int", "(", "rgb", ".", "B", "*", "150", ")", "\n\n", "args", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "args", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "r", ",", "g", ",", "b", ")", "\n\n", "p", ".", "Svg", ".", "Rect", "(", "0", ",", "0", ",", "\"", "\"", ",", "\"", "\"", ",", "args", ")", "\n", "}" ]
// generateBackground decides on background color for the pattern. // // It uses 'color' or 'baseColor' arguments for this task.
[ "generateBackground", "decides", "on", "background", "color", "for", "the", "pattern", ".", "It", "uses", "color", "or", "baseColor", "arguments", "for", "this", "task", "." ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L83-L116
9,757
pravj/geopattern
pattern/pattern.go
isPattern
func isPattern(generator string) bool { for _, ptn := range PATTERNS { if ptn == generator { return true } } return false }
go
func isPattern(generator string) bool { for _, ptn := range PATTERNS { if ptn == generator { return true } } return false }
[ "func", "isPattern", "(", "generator", "string", ")", "bool", "{", "for", "_", ",", "ptn", ":=", "range", "PATTERNS", "{", "if", "ptn", "==", "generator", "{", "return", "true", "\n", "}", "\n", "}", "\n", "return", "false", "\n", "}" ]
// isPattern decides whether a pattern is a valid one or not
[ "isPattern", "decides", "whether", "a", "pattern", "is", "a", "valid", "one", "or", "not" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L119-L126
9,758
pravj/geopattern
pattern/pattern.go
genaratePattern
func (p *Pattern) genaratePattern() { if p.Generator == "" { p.Generator = PATTERNS[int(utils.HexVal(p.Hash, 20, 1))] } else { if !isPattern(p.Generator) { panic("Error: the requested generator is invalid.") } } switch p.Generator { case "chevrons": p.geoChevrons() case "concentric-circles": p.geoConcentricCircles() case "diamonds": p.geoDiamonds() case "hexagons": p.geoHexagons() case "mosaic-squares": p.geoMosaicSquares() case "nested-squares": p.geoNestedSquares() case "octagons": p.geoOctagons() case "overlapping-circles": p.geoOverlappingCircles() case "overlapping-rings": p.geoOverlappingRings() case "plaid": p.geoPlaid() case "plus-signs": p.geoPlusSigns() case "sine-waves": p.geoSineWaves() case "squares": p.geoSquares() case "tessellation": p.geoTessellation() case "triangles": p.geoTriangles() case "xes": p.geoXes() } }
go
func (p *Pattern) genaratePattern() { if p.Generator == "" { p.Generator = PATTERNS[int(utils.HexVal(p.Hash, 20, 1))] } else { if !isPattern(p.Generator) { panic("Error: the requested generator is invalid.") } } switch p.Generator { case "chevrons": p.geoChevrons() case "concentric-circles": p.geoConcentricCircles() case "diamonds": p.geoDiamonds() case "hexagons": p.geoHexagons() case "mosaic-squares": p.geoMosaicSquares() case "nested-squares": p.geoNestedSquares() case "octagons": p.geoOctagons() case "overlapping-circles": p.geoOverlappingCircles() case "overlapping-rings": p.geoOverlappingRings() case "plaid": p.geoPlaid() case "plus-signs": p.geoPlusSigns() case "sine-waves": p.geoSineWaves() case "squares": p.geoSquares() case "tessellation": p.geoTessellation() case "triangles": p.geoTriangles() case "xes": p.geoXes() } }
[ "func", "(", "p", "*", "Pattern", ")", "genaratePattern", "(", ")", "{", "if", "p", ".", "Generator", "==", "\"", "\"", "{", "p", ".", "Generator", "=", "PATTERNS", "[", "int", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "20", ",", "1", ")", ")", "]", "\n", "}", "else", "{", "if", "!", "isPattern", "(", "p", ".", "Generator", ")", "{", "panic", "(", "\"", "\"", ")", "\n", "}", "\n", "}", "\n\n", "switch", "p", ".", "Generator", "{", "case", "\"", "\"", ":", "p", ".", "geoChevrons", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoConcentricCircles", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoDiamonds", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoHexagons", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoMosaicSquares", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoNestedSquares", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoOctagons", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoOverlappingCircles", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoOverlappingRings", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoPlaid", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoPlusSigns", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoSineWaves", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoSquares", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoTessellation", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoTriangles", "(", ")", "\n", "case", "\"", "\"", ":", "p", ".", "geoXes", "(", ")", "\n", "}", "\n", "}" ]
// genaratePattern decides on type of pattern and build respective SVG object
[ "genaratePattern", "decides", "on", "type", "of", "pattern", "and", "build", "respective", "SVG", "object" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L129-L172
9,759
pravj/geopattern
pattern/pattern.go
geoChevrons
func (p *Pattern) geoChevrons() { chevronWidth := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 30, 80) chevronHeight := chevronWidth chevron := shapes.BuildChevron(chevronWidth, chevronHeight) p.Svg.SetHeight(int(chevronHeight * 6 * 0.66)) p.Svg.SetWidth(int(chevronWidth * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity styles["stroke-width"] = 1 style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*chevronWidth, float64(y)*chevronHeight*0.66-chevronHeight/2) p.Svg.Group(chevron, utils.Merge(styles, style)) if y == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*chevronWidth, 6*chevronHeight*0.66-chevronHeight/2) p.Svg.Group(chevron, utils.Merge(styles, style)) } i = i + 1 } } }
go
func (p *Pattern) geoChevrons() { chevronWidth := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 30, 80) chevronHeight := chevronWidth chevron := shapes.BuildChevron(chevronWidth, chevronHeight) p.Svg.SetHeight(int(chevronHeight * 6 * 0.66)) p.Svg.SetWidth(int(chevronWidth * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity styles["stroke-width"] = 1 style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*chevronWidth, float64(y)*chevronHeight*0.66-chevronHeight/2) p.Svg.Group(chevron, utils.Merge(styles, style)) if y == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*chevronWidth, 6*chevronHeight*0.66-chevronHeight/2) p.Svg.Group(chevron, utils.Merge(styles, style)) } i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoChevrons", "(", ")", "{", "chevronWidth", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", ",", "0", ",", "15", ",", "30", ",", "80", ")", "\n", "chevronHeight", ":=", "chevronWidth", "\n", "chevron", ":=", "shapes", ".", "BuildChevron", "(", "chevronWidth", ",", "chevronHeight", ")", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "chevronHeight", "*", "6", "*", "0.66", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "chevronWidth", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeColor", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeOpacity", "\n", "styles", "[", "\"", "\"", "]", "=", "1", "\n\n", "style", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "float64", "(", "x", ")", "*", "chevronWidth", ",", "float64", "(", "y", ")", "*", "chevronHeight", "*", "0.66", "-", "chevronHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Group", "(", "chevron", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n\n", "if", "y", "==", "0", "{", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "float64", "(", "x", ")", "*", "chevronWidth", ",", "6", "*", "chevronHeight", "*", "0.66", "-", "chevronHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Group", "(", "chevron", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n", "}", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoChevrons build the chevrons SVG pattern
[ "geoChevrons", "build", "the", "chevrons", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L175-L211
9,760
pravj/geopattern
pattern/pattern.go
geoConcentricCircles
func (p *Pattern) geoConcentricCircles() { scale := utils.HexVal(p.Hash, 0, 1) ringSize := utils.Map(scale, 0, 15, 10, 60) strokeWidth := ringSize / 5 p.Svg.SetHeight(int((ringSize + strokeWidth) * 6)) p.Svg.SetWidth(int((ringSize + strokeWidth) * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) cx := float64(x)*ringSize + float64(x)*strokeWidth + (ringSize+strokeWidth)/2 cy := float64(y)*ringSize + float64(y)*strokeWidth + (ringSize+strokeWidth)/2 styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", strokeWidth)} p.Svg.Circle(cx, cy, ringSize/2, styles) val = utils.HexVal(p.Hash, 39-i, 1) opacity = utils.Opacity(val) fill = utils.FillColor(val) styles = make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity p.Svg.Circle(cx, cy, ringSize/4, styles) i = i + 1 } } }
go
func (p *Pattern) geoConcentricCircles() { scale := utils.HexVal(p.Hash, 0, 1) ringSize := utils.Map(scale, 0, 15, 10, 60) strokeWidth := ringSize / 5 p.Svg.SetHeight(int((ringSize + strokeWidth) * 6)) p.Svg.SetWidth(int((ringSize + strokeWidth) * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) cx := float64(x)*ringSize + float64(x)*strokeWidth + (ringSize+strokeWidth)/2 cy := float64(y)*ringSize + float64(y)*strokeWidth + (ringSize+strokeWidth)/2 styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", strokeWidth)} p.Svg.Circle(cx, cy, ringSize/2, styles) val = utils.HexVal(p.Hash, 39-i, 1) opacity = utils.Opacity(val) fill = utils.FillColor(val) styles = make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity p.Svg.Circle(cx, cy, ringSize/4, styles) i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoConcentricCircles", "(", ")", "{", "scale", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", "\n", "ringSize", ":=", "utils", ".", "Map", "(", "scale", ",", "0", ",", "15", ",", "10", ",", "60", ")", "\n", "strokeWidth", ":=", "ringSize", "/", "5", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "(", "ringSize", "+", "strokeWidth", ")", "*", "6", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "(", "ringSize", "+", "strokeWidth", ")", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "cx", ":=", "float64", "(", "x", ")", "*", "ringSize", "+", "float64", "(", "x", ")", "*", "strokeWidth", "+", "(", "ringSize", "+", "strokeWidth", ")", "/", "2", "\n", "cy", ":=", "float64", "(", "y", ")", "*", "ringSize", "+", "float64", "(", "y", ")", "*", "strokeWidth", "+", "(", "ringSize", "+", "strokeWidth", ")", "/", "2", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opacity", ")", ",", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strokeWidth", ")", "}", "\n\n", "p", ".", "Svg", ".", "Circle", "(", "cx", ",", "cy", ",", "ringSize", "/", "2", ",", "styles", ")", "\n\n", "val", "=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "39", "-", "i", ",", "1", ")", "\n", "opacity", "=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", "=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n\n", "p", ".", "Svg", ".", "Circle", "(", "cx", ",", "cy", ",", "ringSize", "/", "4", ",", "styles", ")", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoConcentricCircles build the concentric_circles SVG pattern
[ "geoConcentricCircles", "build", "the", "concentric_circles", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L214-L253
9,761
pravj/geopattern
pattern/pattern.go
geoDiamonds
func (p *Pattern) geoDiamonds() { diamondWidth := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 50) diamondHeight := utils.Map(utils.HexVal(p.Hash, 1, 1), 0, 15, 10, 50) diamond := shapes.BuildDiamond(diamondWidth, diamondHeight) p.Svg.SetHeight(int(diamondHeight * 3)) p.Svg.SetWidth(int(diamondWidth * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity var dx float64 if y%2 != 0 { dx = diamondWidth / 2 } style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + float64(x)*diamondWidth - diamondWidth/2, diamondHeight/2*float64(y) - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) if x == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + 6*diamondWidth - diamondWidth/2, diamondHeight/2*float64(y) - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) } if y == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + float64(x)*diamondWidth - diamondWidth/2, diamondHeight/2*6 - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) } if x == 0 && y == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + 6*diamondWidth - diamondWidth/2, diamondHeight/2*6 - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) } i = i + 1 } } }
go
func (p *Pattern) geoDiamonds() { diamondWidth := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 50) diamondHeight := utils.Map(utils.HexVal(p.Hash, 1, 1), 0, 15, 10, 50) diamond := shapes.BuildDiamond(diamondWidth, diamondHeight) p.Svg.SetHeight(int(diamondHeight * 3)) p.Svg.SetWidth(int(diamondWidth * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity var dx float64 if y%2 != 0 { dx = diamondWidth / 2 } style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + float64(x)*diamondWidth - diamondWidth/2, diamondHeight/2*float64(y) - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) if x == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + 6*diamondWidth - diamondWidth/2, diamondHeight/2*float64(y) - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) } if y == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + float64(x)*diamondWidth - diamondWidth/2, diamondHeight/2*6 - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) } if x == 0 && y == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v)", dx + 6*diamondWidth - diamondWidth/2, diamondHeight/2*6 - diamondHeight/2) p.Svg.Polyline(diamond, utils.Merge(styles, style)) } i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoDiamonds", "(", ")", "{", "diamondWidth", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", ",", "0", ",", "15", ",", "10", ",", "50", ")", "\n", "diamondHeight", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "1", ",", "1", ")", ",", "0", ",", "15", ",", "10", ",", "50", ")", "\n", "diamond", ":=", "shapes", ".", "BuildDiamond", "(", "diamondWidth", ",", "diamondHeight", ")", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "diamondHeight", "*", "3", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "diamondWidth", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeColor", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeOpacity", "\n\n", "var", "dx", "float64", "\n", "if", "y", "%", "2", "!=", "0", "{", "dx", "=", "diamondWidth", "/", "2", "\n", "}", "\n\n", "style", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dx", "+", "float64", "(", "x", ")", "*", "diamondWidth", "-", "diamondWidth", "/", "2", ",", "diamondHeight", "/", "2", "*", "float64", "(", "y", ")", "-", "diamondHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Polyline", "(", "diamond", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n\n", "if", "x", "==", "0", "{", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dx", "+", "6", "*", "diamondWidth", "-", "diamondWidth", "/", "2", ",", "diamondHeight", "/", "2", "*", "float64", "(", "y", ")", "-", "diamondHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Polyline", "(", "diamond", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n", "}", "\n\n", "if", "y", "==", "0", "{", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dx", "+", "float64", "(", "x", ")", "*", "diamondWidth", "-", "diamondWidth", "/", "2", ",", "diamondHeight", "/", "2", "*", "6", "-", "diamondHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Polyline", "(", "diamond", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n", "}", "\n\n", "if", "x", "==", "0", "&&", "y", "==", "0", "{", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "dx", "+", "6", "*", "diamondWidth", "-", "diamondWidth", "/", "2", ",", "diamondHeight", "/", "2", "*", "6", "-", "diamondHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Polyline", "(", "diamond", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n", "}", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoDiamonds build the diamonds SVG pattern
[ "geoDiamonds", "build", "the", "diamonds", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L256-L306
9,762
pravj/geopattern
pattern/pattern.go
geoMosaicSquares
func (p *Pattern) geoMosaicSquares() { triangleSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 15, 50) p.Svg.SetHeight(int(triangleSize * 8)) p.Svg.SetWidth(int(triangleSize * 8)) i := 0 for y := 0; y <= 3; y++ { for x := 0; x <= 3; x++ { values := [2]float64{utils.HexVal(p.Hash, i, 1), utils.HexVal(p.Hash, i+1, 1)} if x%2 == 0 { if y%2 == 0 { shapes.DrawOuterMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, utils.HexVal(p.Hash, i, 1)) } else { shapes.DrawInnerMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, values) } } else { if y%2 == 0 { shapes.DrawInnerMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, values) } else { shapes.DrawOuterMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, utils.HexVal(p.Hash, i, 1)) } } i = i + 1 } } }
go
func (p *Pattern) geoMosaicSquares() { triangleSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 15, 50) p.Svg.SetHeight(int(triangleSize * 8)) p.Svg.SetWidth(int(triangleSize * 8)) i := 0 for y := 0; y <= 3; y++ { for x := 0; x <= 3; x++ { values := [2]float64{utils.HexVal(p.Hash, i, 1), utils.HexVal(p.Hash, i+1, 1)} if x%2 == 0 { if y%2 == 0 { shapes.DrawOuterMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, utils.HexVal(p.Hash, i, 1)) } else { shapes.DrawInnerMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, values) } } else { if y%2 == 0 { shapes.DrawInnerMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, values) } else { shapes.DrawOuterMosaicTile(p.Svg, float64(x)*triangleSize*2, float64(y)*triangleSize*2, triangleSize, utils.HexVal(p.Hash, i, 1)) } } i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoMosaicSquares", "(", ")", "{", "triangleSize", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", ",", "0", ",", "15", ",", "15", ",", "50", ")", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "triangleSize", "*", "8", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "triangleSize", "*", "8", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "3", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "3", ";", "x", "++", "{", "values", ":=", "[", "2", "]", "float64", "{", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", ",", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", "+", "1", ",", "1", ")", "}", "\n\n", "if", "x", "%", "2", "==", "0", "{", "if", "y", "%", "2", "==", "0", "{", "shapes", ".", "DrawOuterMosaicTile", "(", "p", ".", "Svg", ",", "float64", "(", "x", ")", "*", "triangleSize", "*", "2", ",", "float64", "(", "y", ")", "*", "triangleSize", "*", "2", ",", "triangleSize", ",", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", ")", "\n", "}", "else", "{", "shapes", ".", "DrawInnerMosaicTile", "(", "p", ".", "Svg", ",", "float64", "(", "x", ")", "*", "triangleSize", "*", "2", ",", "float64", "(", "y", ")", "*", "triangleSize", "*", "2", ",", "triangleSize", ",", "values", ")", "\n", "}", "\n", "}", "else", "{", "if", "y", "%", "2", "==", "0", "{", "shapes", ".", "DrawInnerMosaicTile", "(", "p", ".", "Svg", ",", "float64", "(", "x", ")", "*", "triangleSize", "*", "2", ",", "float64", "(", "y", ")", "*", "triangleSize", "*", "2", ",", "triangleSize", ",", "values", ")", "\n", "}", "else", "{", "shapes", ".", "DrawOuterMosaicTile", "(", "p", ".", "Svg", ",", "float64", "(", "x", ")", "*", "triangleSize", "*", "2", ",", "float64", "(", "y", ")", "*", "triangleSize", "*", "2", ",", "triangleSize", ",", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", ")", "\n", "}", "\n", "}", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n\n", "}" ]
// geoMosaicSquares build the mosaic_squares SVG pattern
[ "geoMosaicSquares", "build", "the", "mosaic_squares", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L370-L400
9,763
pravj/geopattern
pattern/pattern.go
geoNestedSquares
func (p *Pattern) geoNestedSquares() { blockSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 4, 12) squareSize := blockSize * 7 p.Svg.SetHeight(int((squareSize+blockSize)*6 + blockSize*6)) p.Svg.SetWidth(int((squareSize+blockSize)*6 + blockSize*6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", blockSize)} p.Svg.Rect(float64(x)*squareSize+float64(x)*blockSize*2+blockSize/2, float64(y)*squareSize+float64(y)*blockSize*2+blockSize/2, squareSize, squareSize, styles) val = utils.HexVal(p.Hash, 39-i, 1) opacity = utils.Opacity(val) fill = utils.FillColor(val) styles = make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", blockSize)} p.Svg.Rect(float64(x)*squareSize+float64(x)*blockSize*2+blockSize/2+blockSize*2, float64(y)*squareSize+float64(y)*blockSize*2+blockSize/2+blockSize*2, blockSize*3, blockSize*3, styles) i = i + 1 } } }
go
func (p *Pattern) geoNestedSquares() { blockSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 4, 12) squareSize := blockSize * 7 p.Svg.SetHeight(int((squareSize+blockSize)*6 + blockSize*6)) p.Svg.SetWidth(int((squareSize+blockSize)*6 + blockSize*6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", blockSize)} p.Svg.Rect(float64(x)*squareSize+float64(x)*blockSize*2+blockSize/2, float64(y)*squareSize+float64(y)*blockSize*2+blockSize/2, squareSize, squareSize, styles) val = utils.HexVal(p.Hash, 39-i, 1) opacity = utils.Opacity(val) fill = utils.FillColor(val) styles = make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", blockSize)} p.Svg.Rect(float64(x)*squareSize+float64(x)*blockSize*2+blockSize/2+blockSize*2, float64(y)*squareSize+float64(y)*blockSize*2+blockSize/2+blockSize*2, blockSize*3, blockSize*3, styles) i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoNestedSquares", "(", ")", "{", "blockSize", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", ",", "0", ",", "15", ",", "4", ",", "12", ")", "\n", "squareSize", ":=", "blockSize", "*", "7", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "(", "squareSize", "+", "blockSize", ")", "*", "6", "+", "blockSize", "*", "6", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "(", "squareSize", "+", "blockSize", ")", "*", "6", "+", "blockSize", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opacity", ")", ",", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "blockSize", ")", "}", "\n\n", "p", ".", "Svg", ".", "Rect", "(", "float64", "(", "x", ")", "*", "squareSize", "+", "float64", "(", "x", ")", "*", "blockSize", "*", "2", "+", "blockSize", "/", "2", ",", "float64", "(", "y", ")", "*", "squareSize", "+", "float64", "(", "y", ")", "*", "blockSize", "*", "2", "+", "blockSize", "/", "2", ",", "squareSize", ",", "squareSize", ",", "styles", ")", "\n\n", "val", "=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "39", "-", "i", ",", "1", ")", "\n", "opacity", "=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", "=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", "=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opacity", ")", ",", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "blockSize", ")", "}", "\n\n", "p", ".", "Svg", ".", "Rect", "(", "float64", "(", "x", ")", "*", "squareSize", "+", "float64", "(", "x", ")", "*", "blockSize", "*", "2", "+", "blockSize", "/", "2", "+", "blockSize", "*", "2", ",", "float64", "(", "y", ")", "*", "squareSize", "+", "float64", "(", "y", ")", "*", "blockSize", "*", "2", "+", "blockSize", "/", "2", "+", "blockSize", "*", "2", ",", "blockSize", "*", "3", ",", "blockSize", "*", "3", ",", "styles", ")", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoNestedSquares build the nested_squares SVG pattern
[ "geoNestedSquares", "build", "the", "nested_squares", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L403-L439
9,764
pravj/geopattern
pattern/pattern.go
geoOctagons
func (p *Pattern) geoOctagons() { squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 60) tile := shapes.BuildOctagon(squareSize) p.Svg.SetHeight(int(squareSize * 6)) p.Svg.SetWidth(int(squareSize * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity styles["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*squareSize, float64(y)*squareSize) p.Svg.Polyline(tile, styles) i = i + 1 } } }
go
func (p *Pattern) geoOctagons() { squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 60) tile := shapes.BuildOctagon(squareSize) p.Svg.SetHeight(int(squareSize * 6)) p.Svg.SetWidth(int(squareSize * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity styles["transform"] = fmt.Sprintf("translate(%v, %v)", float64(x)*squareSize, float64(y)*squareSize) p.Svg.Polyline(tile, styles) i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoOctagons", "(", ")", "{", "squareSize", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", ",", "0", ",", "15", ",", "10", ",", "60", ")", "\n", "tile", ":=", "shapes", ".", "BuildOctagon", "(", "squareSize", ")", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "squareSize", "*", "6", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "squareSize", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeColor", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeOpacity", "\n", "styles", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "float64", "(", "x", ")", "*", "squareSize", ",", "float64", "(", "y", ")", "*", "squareSize", ")", "\n\n", "p", ".", "Svg", ".", "Polyline", "(", "tile", ",", "styles", ")", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoOctagons build the octagons SVG pattern
[ "geoOctagons", "build", "the", "octagons", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L442-L468
9,765
pravj/geopattern
pattern/pattern.go
geoOverlappingCircles
func (p *Pattern) geoOverlappingCircles() { scale := utils.HexVal(p.Hash, 0, 1) diameter := utils.Map(scale, 0, 15, 25, 200) radius := diameter / 2 p.Svg.SetHeight(int(radius * 6)) p.Svg.SetWidth(int(radius * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity)} p.Svg.Circle(float64(x)*radius, float64(y)*radius, radius, styles) if x == 0 { p.Svg.Circle(6*radius, float64(y)*radius, radius, styles) } if y == 0 { p.Svg.Circle(float64(x)*radius, 6*radius, radius, styles) } if x == 0 && y == 0 { p.Svg.Circle(6*radius, 6*radius, radius, styles) } i = i + 1 } } }
go
func (p *Pattern) geoOverlappingCircles() { scale := utils.HexVal(p.Hash, 0, 1) diameter := utils.Map(scale, 0, 15, 25, 200) radius := diameter / 2 p.Svg.SetHeight(int(radius * 6)) p.Svg.SetWidth(int(radius * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity)} p.Svg.Circle(float64(x)*radius, float64(y)*radius, radius, styles) if x == 0 { p.Svg.Circle(6*radius, float64(y)*radius, radius, styles) } if y == 0 { p.Svg.Circle(float64(x)*radius, 6*radius, radius, styles) } if x == 0 && y == 0 { p.Svg.Circle(6*radius, 6*radius, radius, styles) } i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoOverlappingCircles", "(", ")", "{", "scale", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", "\n", "diameter", ":=", "utils", ".", "Map", "(", "scale", ",", "0", ",", "15", ",", "25", ",", "200", ")", "\n", "radius", ":=", "diameter", "/", "2", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "radius", "*", "6", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "radius", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opacity", ")", "}", "\n\n", "p", ".", "Svg", ".", "Circle", "(", "float64", "(", "x", ")", "*", "radius", ",", "float64", "(", "y", ")", "*", "radius", ",", "radius", ",", "styles", ")", "\n\n", "if", "x", "==", "0", "{", "p", ".", "Svg", ".", "Circle", "(", "6", "*", "radius", ",", "float64", "(", "y", ")", "*", "radius", ",", "radius", ",", "styles", ")", "\n", "}", "\n\n", "if", "y", "==", "0", "{", "p", ".", "Svg", ".", "Circle", "(", "float64", "(", "x", ")", "*", "radius", ",", "6", "*", "radius", ",", "radius", ",", "styles", ")", "\n", "}", "\n\n", "if", "x", "==", "0", "&&", "y", "==", "0", "{", "p", ".", "Svg", ".", "Circle", "(", "6", "*", "radius", ",", "6", "*", "radius", ",", "radius", ",", "styles", ")", "\n", "}", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoOverlappingCircles build the overlapping_circles SVG pattern
[ "geoOverlappingCircles", "build", "the", "overlapping_circles", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L471-L508
9,766
pravj/geopattern
pattern/pattern.go
geoOverlappingRings
func (p *Pattern) geoOverlappingRings() { scale := utils.HexVal(p.Hash, 0, 1) ringSize := utils.Map(scale, 0, 15, 10, 60) strokeWidth := ringSize / 4 p.Svg.SetHeight(int(ringSize * 6)) p.Svg.SetWidth(int(ringSize * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", strokeWidth)} p.Svg.Circle(float64(x)*ringSize, float64(y)*ringSize, ringSize-(strokeWidth/2), styles) if x == 0 { p.Svg.Circle(6*ringSize, float64(y)*ringSize, ringSize-(strokeWidth/2), styles) } if y == 0 { p.Svg.Circle(float64(x)*ringSize, 6*ringSize, ringSize-(strokeWidth/2), styles) } if x == 0 && y == 0 { p.Svg.Circle(6*ringSize, 6*ringSize, ringSize-(strokeWidth/2), styles) } i = i + 1 } } }
go
func (p *Pattern) geoOverlappingRings() { scale := utils.HexVal(p.Hash, 0, 1) ringSize := utils.Map(scale, 0, 15, 10, 60) strokeWidth := ringSize / 4 p.Svg.SetHeight(int(ringSize * 6)) p.Svg.SetWidth(int(ringSize * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", strokeWidth)} p.Svg.Circle(float64(x)*ringSize, float64(y)*ringSize, ringSize-(strokeWidth/2), styles) if x == 0 { p.Svg.Circle(6*ringSize, float64(y)*ringSize, ringSize-(strokeWidth/2), styles) } if y == 0 { p.Svg.Circle(float64(x)*ringSize, 6*ringSize, ringSize-(strokeWidth/2), styles) } if x == 0 && y == 0 { p.Svg.Circle(6*ringSize, 6*ringSize, ringSize-(strokeWidth/2), styles) } i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoOverlappingRings", "(", ")", "{", "scale", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", "\n", "ringSize", ":=", "utils", ".", "Map", "(", "scale", ",", "0", ",", "15", ",", "10", ",", "60", ")", "\n", "strokeWidth", ":=", "ringSize", "/", "4", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "ringSize", "*", "6", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "ringSize", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opacity", ")", ",", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "strokeWidth", ")", "}", "\n\n", "p", ".", "Svg", ".", "Circle", "(", "float64", "(", "x", ")", "*", "ringSize", ",", "float64", "(", "y", ")", "*", "ringSize", ",", "ringSize", "-", "(", "strokeWidth", "/", "2", ")", ",", "styles", ")", "\n\n", "if", "x", "==", "0", "{", "p", ".", "Svg", ".", "Circle", "(", "6", "*", "ringSize", ",", "float64", "(", "y", ")", "*", "ringSize", ",", "ringSize", "-", "(", "strokeWidth", "/", "2", ")", ",", "styles", ")", "\n", "}", "\n\n", "if", "y", "==", "0", "{", "p", ".", "Svg", ".", "Circle", "(", "float64", "(", "x", ")", "*", "ringSize", ",", "6", "*", "ringSize", ",", "ringSize", "-", "(", "strokeWidth", "/", "2", ")", ",", "styles", ")", "\n", "}", "\n\n", "if", "x", "==", "0", "&&", "y", "==", "0", "{", "p", ".", "Svg", ".", "Circle", "(", "6", "*", "ringSize", ",", "6", "*", "ringSize", ",", "ringSize", "-", "(", "strokeWidth", "/", "2", ")", ",", "styles", ")", "\n", "}", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoOverlappingRings build the overlapping_rings SVG pattern
[ "geoOverlappingRings", "build", "the", "overlapping_rings", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L511-L549
9,767
pravj/geopattern
pattern/pattern.go
geoPlaid
func (p *Pattern) geoPlaid() { height := 0 width := 0 i := 1 j := 0 for i <= 18 { space := utils.HexVal(p.Hash, j, 1) height = height + int(space) + 5 val := utils.HexVal(p.Hash, j+1, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) stripeHeight := val + 5 styles := make(map[string]interface{}) styles["opacity"] = opacity styles["fill"] = fill p.Svg.Rect(0, height, "100%", stripeHeight, styles) height = height + int(stripeHeight) j = j + 2 i = i + 1 } i = 1 j = 0 for i <= 18 { space := utils.HexVal(p.Hash, j, 1) width = width + int(space) + 5 val := utils.HexVal(p.Hash, j+1, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) stripeWidth := val + 5 styles := make(map[string]interface{}) styles["opacity"] = opacity styles["fill"] = fill p.Svg.Rect(width, 0, stripeWidth, "100%", styles) width = width + int(stripeWidth) j = j + 2 i = i + 1 } p.Svg.SetHeight(int(height)) p.Svg.SetWidth(int(width)) }
go
func (p *Pattern) geoPlaid() { height := 0 width := 0 i := 1 j := 0 for i <= 18 { space := utils.HexVal(p.Hash, j, 1) height = height + int(space) + 5 val := utils.HexVal(p.Hash, j+1, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) stripeHeight := val + 5 styles := make(map[string]interface{}) styles["opacity"] = opacity styles["fill"] = fill p.Svg.Rect(0, height, "100%", stripeHeight, styles) height = height + int(stripeHeight) j = j + 2 i = i + 1 } i = 1 j = 0 for i <= 18 { space := utils.HexVal(p.Hash, j, 1) width = width + int(space) + 5 val := utils.HexVal(p.Hash, j+1, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) stripeWidth := val + 5 styles := make(map[string]interface{}) styles["opacity"] = opacity styles["fill"] = fill p.Svg.Rect(width, 0, stripeWidth, "100%", styles) width = width + int(stripeWidth) j = j + 2 i = i + 1 } p.Svg.SetHeight(int(height)) p.Svg.SetWidth(int(width)) }
[ "func", "(", "p", "*", "Pattern", ")", "geoPlaid", "(", ")", "{", "height", ":=", "0", "\n", "width", ":=", "0", "\n\n", "i", ":=", "1", "\n", "j", ":=", "0", "\n", "for", "i", "<=", "18", "{", "space", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "j", ",", "1", ")", "\n", "height", "=", "height", "+", "int", "(", "space", ")", "+", "5", "\n\n", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "j", "+", "1", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n", "stripeHeight", ":=", "val", "+", "5", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n\n", "p", ".", "Svg", ".", "Rect", "(", "0", ",", "height", ",", "\"", "\"", ",", "stripeHeight", ",", "styles", ")", "\n\n", "height", "=", "height", "+", "int", "(", "stripeHeight", ")", "\n", "j", "=", "j", "+", "2", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n\n", "i", "=", "1", "\n", "j", "=", "0", "\n", "for", "i", "<=", "18", "{", "space", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "j", ",", "1", ")", "\n", "width", "=", "width", "+", "int", "(", "space", ")", "+", "5", "\n\n", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "j", "+", "1", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n", "stripeWidth", ":=", "val", "+", "5", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n\n", "p", ".", "Svg", ".", "Rect", "(", "width", ",", "0", ",", "stripeWidth", ",", "\"", "\"", ",", "styles", ")", "\n\n", "width", "=", "width", "+", "int", "(", "stripeWidth", ")", "\n", "j", "=", "j", "+", "2", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "height", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "width", ")", ")", "\n", "}" ]
// geoPlaid build the plaid SVG pattern
[ "geoPlaid", "build", "the", "plaid", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L552-L606
9,768
pravj/geopattern
pattern/pattern.go
geoSineWaves
func (p *Pattern) geoSineWaves() { period := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 100, 400) amplitude := utils.Map(utils.HexVal(p.Hash, 1, 1), 0, 15, 30, 100) waveWidth := utils.Map(utils.HexVal(p.Hash, 2, 1), 0, 15, 3, 30) p.Svg.SetHeight(int(waveWidth * 36)) p.Svg.SetWidth(int(period)) for i := 0; i <= 35; i++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) xOffset := (period / 4) * 0.7 styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", waveWidth)} str := fmt.Sprintf("M0 %v C %v 0, %v 0, %v %v S %v %v, %v %v S %v 0, %v, %v", amplitude, xOffset, period/2-xOffset, period/2, amplitude, period-xOffset, amplitude*2, period, amplitude, period*1.5-xOffset, period*1.5, amplitude) style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5)) p.Svg.Path(str, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5)+waveWidth*36) p.Svg.Path(str, utils.Merge(styles, style)) } }
go
func (p *Pattern) geoSineWaves() { period := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 100, 400) amplitude := utils.Map(utils.HexVal(p.Hash, 1, 1), 0, 15, 30, 100) waveWidth := utils.Map(utils.HexVal(p.Hash, 2, 1), 0, 15, 3, 30) p.Svg.SetHeight(int(waveWidth * 36)) p.Svg.SetWidth(int(period)) for i := 0; i <= 35; i++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) xOffset := (period / 4) * 0.7 styles := make(map[string]interface{}) styles["fill"] = "none" styles["stroke"] = fill styles["style"] = map[string]string{"opacity": fmt.Sprintf("%v", opacity), "stroke-width": fmt.Sprintf("%vpx", waveWidth)} str := fmt.Sprintf("M0 %v C %v 0, %v 0, %v %v S %v %v, %v %v S %v 0, %v, %v", amplitude, xOffset, period/2-xOffset, period/2, amplitude, period-xOffset, amplitude*2, period, amplitude, period*1.5-xOffset, period*1.5, amplitude) style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5)) p.Svg.Path(str, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(-%v, %v)", period/4, (waveWidth*float64(i))-(amplitude*1.5)+waveWidth*36) p.Svg.Path(str, utils.Merge(styles, style)) } }
[ "func", "(", "p", "*", "Pattern", ")", "geoSineWaves", "(", ")", "{", "period", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", ",", "0", ",", "15", ",", "100", ",", "400", ")", "\n", "amplitude", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "1", ",", "1", ")", ",", "0", ",", "15", ",", "30", ",", "100", ")", "\n", "waveWidth", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "2", ",", "1", ")", ",", "0", ",", "15", ",", "3", ",", "30", ")", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "waveWidth", "*", "36", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "period", ")", ")", "\n\n", "for", "i", ":=", "0", ";", "i", "<=", "35", ";", "i", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n", "xOffset", ":=", "(", "period", "/", "4", ")", "*", "0.7", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "\"", "\"", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "opacity", ")", ",", "\"", "\"", ":", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "waveWidth", ")", "}", "\n\n", "str", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "amplitude", ",", "xOffset", ",", "period", "/", "2", "-", "xOffset", ",", "period", "/", "2", ",", "amplitude", ",", "period", "-", "xOffset", ",", "amplitude", "*", "2", ",", "period", ",", "amplitude", ",", "period", "*", "1.5", "-", "xOffset", ",", "period", "*", "1.5", ",", "amplitude", ")", "\n\n", "style", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "period", "/", "4", ",", "(", "waveWidth", "*", "float64", "(", "i", ")", ")", "-", "(", "amplitude", "*", "1.5", ")", ")", "\n", "p", ".", "Svg", ".", "Path", "(", "str", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "period", "/", "4", ",", "(", "waveWidth", "*", "float64", "(", "i", ")", ")", "-", "(", "amplitude", "*", "1.5", ")", "+", "waveWidth", "*", "36", ")", "\n", "p", ".", "Svg", ".", "Path", "(", "str", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n", "}", "\n", "}" ]
// geoSineWaves build the sine_waves SVG pattern
[ "geoSineWaves", "build", "the", "sine_waves", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L662-L691
9,769
pravj/geopattern
pattern/pattern.go
geoSquares
func (p *Pattern) geoSquares() { squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 60) p.Svg.SetHeight(int(squareSize * 6)) p.Svg.SetWidth(int(squareSize * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity p.Svg.Rect(float64(x)*squareSize, float64(y)*squareSize, squareSize, squareSize, styles) i = i + 1 } } }
go
func (p *Pattern) geoSquares() { squareSize := utils.Map(utils.HexVal(p.Hash, 0, 1), 0, 15, 10, 60) p.Svg.SetHeight(int(squareSize * 6)) p.Svg.SetWidth(int(squareSize * 6)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity p.Svg.Rect(float64(x)*squareSize, float64(y)*squareSize, squareSize, squareSize, styles) i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoSquares", "(", ")", "{", "squareSize", ":=", "utils", ".", "Map", "(", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", ",", "0", ",", "15", ",", "10", ",", "60", ")", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "squareSize", "*", "6", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "squareSize", "*", "6", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeColor", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeOpacity", "\n\n", "p", ".", "Svg", ".", "Rect", "(", "float64", "(", "x", ")", "*", "squareSize", ",", "float64", "(", "y", ")", "*", "squareSize", ",", "squareSize", ",", "squareSize", ",", "styles", ")", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoSquares build the squares SVG pattern
[ "geoSquares", "build", "the", "squares", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L694-L719
9,770
pravj/geopattern
pattern/pattern.go
geoTriangles
func (p *Pattern) geoTriangles() { scale := utils.HexVal(p.Hash, 0, 1) sideLength := utils.Map(scale, 0, 15, 15, 80) triangleHeight := sideLength / 2 * math.Sqrt(3) triangle := shapes.BuildTriangle(sideLength, triangleHeight) p.Svg.SetHeight(int(triangleHeight * 6)) p.Svg.SetWidth(int(sideLength * 3)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity var rotation int if y%2 == 0 { if x%2 == 0 { rotation = 180 } } else { if x%2 != 0 { rotation = 180 } } style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", float64(x)*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2) p.Svg.Polyline(triangle, utils.Merge(styles, style)) if x == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", 6*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2) p.Svg.Polyline(triangle, utils.Merge(styles, style)) } i = i + 1 } } }
go
func (p *Pattern) geoTriangles() { scale := utils.HexVal(p.Hash, 0, 1) sideLength := utils.Map(scale, 0, 15, 15, 80) triangleHeight := sideLength / 2 * math.Sqrt(3) triangle := shapes.BuildTriangle(sideLength, triangleHeight) p.Svg.SetHeight(int(triangleHeight * 6)) p.Svg.SetWidth(int(sideLength * 3)) i := 0 for y := 0; y <= 5; y++ { for x := 0; x <= 5; x++ { val := utils.HexVal(p.Hash, i, 1) opacity := utils.Opacity(val) fill := utils.FillColor(val) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity var rotation int if y%2 == 0 { if x%2 == 0 { rotation = 180 } } else { if x%2 != 0 { rotation = 180 } } style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", float64(x)*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2) p.Svg.Polyline(triangle, utils.Merge(styles, style)) if x == 0 { style["transform"] = fmt.Sprintf("translate(%v, %v) rotate(%v, %v, %v)", 6*sideLength*0.5-sideLength/2, triangleHeight*float64(y), rotation, sideLength/2, triangleHeight/2) p.Svg.Polyline(triangle, utils.Merge(styles, style)) } i = i + 1 } } }
[ "func", "(", "p", "*", "Pattern", ")", "geoTriangles", "(", ")", "{", "scale", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "0", ",", "1", ")", "\n", "sideLength", ":=", "utils", ".", "Map", "(", "scale", ",", "0", ",", "15", ",", "15", ",", "80", ")", "\n", "triangleHeight", ":=", "sideLength", "/", "2", "*", "math", ".", "Sqrt", "(", "3", ")", "\n", "triangle", ":=", "shapes", ".", "BuildTriangle", "(", "sideLength", ",", "triangleHeight", ")", "\n\n", "p", ".", "Svg", ".", "SetHeight", "(", "int", "(", "triangleHeight", "*", "6", ")", ")", "\n", "p", ".", "Svg", ".", "SetWidth", "(", "int", "(", "sideLength", "*", "3", ")", ")", "\n\n", "i", ":=", "0", "\n", "for", "y", ":=", "0", ";", "y", "<=", "5", ";", "y", "++", "{", "for", "x", ":=", "0", ";", "x", "<=", "5", ";", "x", "++", "{", "val", ":=", "utils", ".", "HexVal", "(", "p", ".", "Hash", ",", "i", ",", "1", ")", "\n", "opacity", ":=", "utils", ".", "Opacity", "(", "val", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "val", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeColor", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeOpacity", "\n\n", "var", "rotation", "int", "\n", "if", "y", "%", "2", "==", "0", "{", "if", "x", "%", "2", "==", "0", "{", "rotation", "=", "180", "\n", "}", "\n", "}", "else", "{", "if", "x", "%", "2", "!=", "0", "{", "rotation", "=", "180", "\n", "}", "\n", "}", "\n\n", "style", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "float64", "(", "x", ")", "*", "sideLength", "*", "0.5", "-", "sideLength", "/", "2", ",", "triangleHeight", "*", "float64", "(", "y", ")", ",", "rotation", ",", "sideLength", "/", "2", ",", "triangleHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Polyline", "(", "triangle", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n\n", "if", "x", "==", "0", "{", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "6", "*", "sideLength", "*", "0.5", "-", "sideLength", "/", "2", ",", "triangleHeight", "*", "float64", "(", "y", ")", ",", "rotation", ",", "sideLength", "/", "2", ",", "triangleHeight", "/", "2", ")", "\n", "p", ".", "Svg", ".", "Polyline", "(", "triangle", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n", "}", "\n\n", "i", "=", "i", "+", "1", "\n", "}", "\n", "}", "\n", "}" ]
// geoTriangles build the triangles SVG pattern
[ "geoTriangles", "build", "the", "triangles", "SVG", "pattern" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/pattern/pattern.go#L818-L865
9,771
pravj/geopattern
shapes/shapes.go
BuildOctagon
func BuildOctagon(squareSize float64) string { s := squareSize c := 0.33 * s return fmt.Sprintf("%v,0,%v,0,%v,%v,%v,%v,%v,%v,%v,%v,0,%v,0,%v,%v,0", c, s-c, s, c, s, s-c, s-c, s, c, s, s-c, c, c) }
go
func BuildOctagon(squareSize float64) string { s := squareSize c := 0.33 * s return fmt.Sprintf("%v,0,%v,0,%v,%v,%v,%v,%v,%v,%v,%v,0,%v,0,%v,%v,0", c, s-c, s, c, s, s-c, s-c, s, c, s, s-c, c, c) }
[ "func", "BuildOctagon", "(", "squareSize", "float64", ")", "string", "{", "s", ":=", "squareSize", "\n", "c", ":=", "0.33", "*", "s", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "c", ",", "s", "-", "c", ",", "s", ",", "c", ",", "s", ",", "s", "-", "c", ",", "s", "-", "c", ",", "s", ",", "c", ",", "s", ",", "s", "-", "c", ",", "c", ",", "c", ")", "\n", "}" ]
// BuildOctagon returns string representing an octagon shape
[ "BuildOctagon", "returns", "string", "representing", "an", "octagon", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L12-L17
9,772
pravj/geopattern
shapes/shapes.go
BuildTriangle
func BuildTriangle(sideLength, height float64) string { halfWidth := sideLength / 2 return fmt.Sprintf("%v,0,%v,%v,0,%v,%v,0", halfWidth, sideLength, height, height, halfWidth) }
go
func BuildTriangle(sideLength, height float64) string { halfWidth := sideLength / 2 return fmt.Sprintf("%v,0,%v,%v,0,%v,%v,0", halfWidth, sideLength, height, height, halfWidth) }
[ "func", "BuildTriangle", "(", "sideLength", ",", "height", "float64", ")", "string", "{", "halfWidth", ":=", "sideLength", "/", "2", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "halfWidth", ",", "sideLength", ",", "height", ",", "height", ",", "halfWidth", ")", "\n", "}" ]
// BuildTriangle returns string representing a triangle shape
[ "BuildTriangle", "returns", "string", "representing", "a", "triangle", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L20-L24
9,773
pravj/geopattern
shapes/shapes.go
BuildDiamond
func BuildDiamond(width, height float64) string { return fmt.Sprintf("%v,0,%v,%v,%v,%v,0,%v", width/2, width, height/2, width/2, height, height/2) }
go
func BuildDiamond(width, height float64) string { return fmt.Sprintf("%v,0,%v,%v,%v,%v,0,%v", width/2, width, height/2, width/2, height, height/2) }
[ "func", "BuildDiamond", "(", "width", ",", "height", "float64", ")", "string", "{", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "width", "/", "2", ",", "width", ",", "height", "/", "2", ",", "width", "/", "2", ",", "height", ",", "height", "/", "2", ")", "\n", "}" ]
// BuildDiamond returns string representing a diamond shape
[ "BuildDiamond", "returns", "string", "representing", "a", "diamond", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L27-L29
9,774
pravj/geopattern
shapes/shapes.go
BuildRotatedTriangle
func BuildRotatedTriangle(sideLength, width float64) string { halfHeight := sideLength / 2 return fmt.Sprintf("0,0,%v,%v,0,%v,0,0", width, halfHeight, sideLength) }
go
func BuildRotatedTriangle(sideLength, width float64) string { halfHeight := sideLength / 2 return fmt.Sprintf("0,0,%v,%v,0,%v,0,0", width, halfHeight, sideLength) }
[ "func", "BuildRotatedTriangle", "(", "sideLength", ",", "width", "float64", ")", "string", "{", "halfHeight", ":=", "sideLength", "/", "2", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "width", ",", "halfHeight", ",", "sideLength", ")", "\n", "}" ]
// BuildRotatedTriangle returns string representing a rotated triangle shape
[ "BuildRotatedTriangle", "returns", "string", "representing", "a", "rotated", "triangle", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L37-L41
9,775
pravj/geopattern
shapes/shapes.go
BuildHexagon
func BuildHexagon(sideLength float64) string { c := sideLength a := c / 2 b := math.Sin(60*math.Pi/180) * c return fmt.Sprintf("0,%v,%v,0,%v,0,%v,%v,%v,%v,%v,%v,0,%v", b, a, a+c, 2*c, b, a+c, 2*b, a, 2*b, b) }
go
func BuildHexagon(sideLength float64) string { c := sideLength a := c / 2 b := math.Sin(60*math.Pi/180) * c return fmt.Sprintf("0,%v,%v,0,%v,0,%v,%v,%v,%v,%v,%v,0,%v", b, a, a+c, 2*c, b, a+c, 2*b, a, 2*b, b) }
[ "func", "BuildHexagon", "(", "sideLength", "float64", ")", "string", "{", "c", ":=", "sideLength", "\n", "a", ":=", "c", "/", "2", "\n", "b", ":=", "math", ".", "Sin", "(", "60", "*", "math", ".", "Pi", "/", "180", ")", "*", "c", "\n\n", "return", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "b", ",", "a", ",", "a", "+", "c", ",", "2", "*", "c", ",", "b", ",", "a", "+", "c", ",", "2", "*", "b", ",", "a", ",", "2", "*", "b", ",", "b", ")", "\n", "}" ]
// BuildHexagon returns string representing a hexagon shape
[ "BuildHexagon", "returns", "string", "representing", "a", "hexagon", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L44-L50
9,776
pravj/geopattern
shapes/shapes.go
BuildChevron
func BuildChevron(width, height float64) [2]string { e := height * 0.66 var elements [2]string elements[0] = fmt.Sprintf("<polyline points='0,0,%v,%v,%v,%v,0,%v,0,0' />", width/2, height-e, width/2, height, e) elements[1] = fmt.Sprintf("<polyline points='%v,%v,%v,0,%v,%v,%v,%v,%v,%v' />", width/2, height-e, width, width, e, width/2, height, width/2, height-e) return elements }
go
func BuildChevron(width, height float64) [2]string { e := height * 0.66 var elements [2]string elements[0] = fmt.Sprintf("<polyline points='0,0,%v,%v,%v,%v,0,%v,0,0' />", width/2, height-e, width/2, height, e) elements[1] = fmt.Sprintf("<polyline points='%v,%v,%v,0,%v,%v,%v,%v,%v,%v' />", width/2, height-e, width, width, e, width/2, height, width/2, height-e) return elements }
[ "func", "BuildChevron", "(", "width", ",", "height", "float64", ")", "[", "2", "]", "string", "{", "e", ":=", "height", "*", "0.66", "\n", "var", "elements", "[", "2", "]", "string", "\n\n", "elements", "[", "0", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "width", "/", "2", ",", "height", "-", "e", ",", "width", "/", "2", ",", "height", ",", "e", ")", "\n", "elements", "[", "1", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "width", "/", "2", ",", "height", "-", "e", ",", "width", ",", "width", ",", "e", ",", "width", "/", "2", ",", "height", ",", "width", "/", "2", ",", "height", "-", "e", ")", "\n\n", "return", "elements", "\n", "}" ]
// BuildChevron returns string representing a chevron shape
[ "BuildChevron", "returns", "string", "representing", "a", "chevron", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L53-L61
9,777
pravj/geopattern
shapes/shapes.go
BuildPlus
func BuildPlus(squareSize float64) [2]string { var elements [2]string elements[0] = fmt.Sprintf("<rect x='%v' y='0' width='%v' height='%v' />", squareSize, squareSize, squareSize*3) elements[1] = fmt.Sprintf("<rect x='0' y='%v' width='%v' height='%v' />", squareSize, squareSize*3, squareSize) return elements }
go
func BuildPlus(squareSize float64) [2]string { var elements [2]string elements[0] = fmt.Sprintf("<rect x='%v' y='0' width='%v' height='%v' />", squareSize, squareSize, squareSize*3) elements[1] = fmt.Sprintf("<rect x='0' y='%v' width='%v' height='%v' />", squareSize, squareSize*3, squareSize) return elements }
[ "func", "BuildPlus", "(", "squareSize", "float64", ")", "[", "2", "]", "string", "{", "var", "elements", "[", "2", "]", "string", "\n\n", "elements", "[", "0", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "squareSize", ",", "squareSize", ",", "squareSize", "*", "3", ")", "\n", "elements", "[", "1", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "squareSize", ",", "squareSize", "*", "3", ",", "squareSize", ")", "\n\n", "return", "elements", "\n", "}" ]
// BuildPlus returns string representing an plus shape
[ "BuildPlus", "returns", "string", "representing", "an", "plus", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L64-L71
9,778
pravj/geopattern
shapes/shapes.go
DrawOuterMosaicTile
func DrawOuterMosaicTile(s *svg.SVG, x, y, triangleSize, value float64) { opacity := utils.Opacity(value) fill := utils.FillColor(value) triangle := BuildRightTriangle(triangleSize) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(1, -1)", x, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, -1)", x+triangleSize*2, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(1, 1)", x, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, 1)", x+triangleSize*2, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) }
go
func DrawOuterMosaicTile(s *svg.SVG, x, y, triangleSize, value float64) { opacity := utils.Opacity(value) fill := utils.FillColor(value) triangle := BuildRightTriangle(triangleSize) styles := make(map[string]interface{}) styles["fill"] = fill styles["fill-opacity"] = opacity styles["stroke"] = utils.StrokeColor styles["stroke-opacity"] = utils.StrokeOpacity style := make(map[string]interface{}) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(1, -1)", x, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, -1)", x+triangleSize*2, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(1, 1)", x, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) style["transform"] = fmt.Sprintf("translate(%v, %v) scale(-1, 1)", x+triangleSize*2, y+triangleSize) s.Polyline(triangle, utils.Merge(styles, style)) }
[ "func", "DrawOuterMosaicTile", "(", "s", "*", "svg", ".", "SVG", ",", "x", ",", "y", ",", "triangleSize", ",", "value", "float64", ")", "{", "opacity", ":=", "utils", ".", "Opacity", "(", "value", ")", "\n", "fill", ":=", "utils", ".", "FillColor", "(", "value", ")", "\n", "triangle", ":=", "BuildRightTriangle", "(", "triangleSize", ")", "\n\n", "styles", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n", "styles", "[", "\"", "\"", "]", "=", "fill", "\n", "styles", "[", "\"", "\"", "]", "=", "opacity", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeColor", "\n", "styles", "[", "\"", "\"", "]", "=", "utils", ".", "StrokeOpacity", "\n\n", "style", ":=", "make", "(", "map", "[", "string", "]", "interface", "{", "}", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "x", ",", "y", "+", "triangleSize", ")", "\n", "s", ".", "Polyline", "(", "triangle", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "x", "+", "triangleSize", "*", "2", ",", "y", "+", "triangleSize", ")", "\n", "s", ".", "Polyline", "(", "triangle", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "x", ",", "y", "+", "triangleSize", ")", "\n", "s", ".", "Polyline", "(", "triangle", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n\n", "style", "[", "\"", "\"", "]", "=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "x", "+", "triangleSize", "*", "2", ",", "y", "+", "triangleSize", ")", "\n", "s", ".", "Polyline", "(", "triangle", ",", "utils", ".", "Merge", "(", "styles", ",", "style", ")", ")", "\n", "}" ]
// DrawOuterMosaicTile returns string representing an outer mosaic tile shape
[ "DrawOuterMosaicTile", "returns", "string", "representing", "an", "outer", "mosaic", "tile", "shape" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/shapes/shapes.go#L107-L131
9,779
pravj/geopattern
svg/svg.go
Str
func (s *SVG) Str() string { return s.header() + s.svgString + s.footer() }
go
func (s *SVG) Str() string { return s.header() + s.svgString + s.footer() }
[ "func", "(", "s", "*", "SVG", ")", "Str", "(", ")", "string", "{", "return", "s", ".", "header", "(", ")", "+", "s", ".", "svgString", "+", "s", ".", "footer", "(", ")", "\n", "}" ]
// Str returns string representing whole SVG object
[ "Str", "returns", "string", "representing", "whole", "SVG", "object" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/svg/svg.go#L37-L39
9,780
pravj/geopattern
svg/svg.go
Rect
func (s *SVG) Rect(x, y, w, h interface{}, args map[string]interface{}) { rectStr := fmt.Sprintf("<rect x='%v' y='%v' width='%v' height='%v' %s />", x, y, w, h, s.WriteArgs(args)) s.svgString += rectStr }
go
func (s *SVG) Rect(x, y, w, h interface{}, args map[string]interface{}) { rectStr := fmt.Sprintf("<rect x='%v' y='%v' width='%v' height='%v' %s />", x, y, w, h, s.WriteArgs(args)) s.svgString += rectStr }
[ "func", "(", "s", "*", "SVG", ")", "Rect", "(", "x", ",", "y", ",", "w", ",", "h", "interface", "{", "}", ",", "args", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "rectStr", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "x", ",", "y", ",", "w", ",", "h", ",", "s", ".", "WriteArgs", "(", "args", ")", ")", "\n", "s", ".", "svgString", "+=", "rectStr", "\n", "}" ]
// Rect adds a rectangle element to SVG object
[ "Rect", "adds", "a", "rectangle", "element", "to", "SVG", "object" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/svg/svg.go#L42-L45
9,781
pravj/geopattern
svg/svg.go
Circle
func (s *SVG) Circle(cx, cy, r interface{}, args map[string]interface{}) { circleStr := fmt.Sprintf("<circle cx='%v' cy='%v' r='%v' %s />", cx, cy, r, s.WriteArgs(args)) s.svgString += circleStr }
go
func (s *SVG) Circle(cx, cy, r interface{}, args map[string]interface{}) { circleStr := fmt.Sprintf("<circle cx='%v' cy='%v' r='%v' %s />", cx, cy, r, s.WriteArgs(args)) s.svgString += circleStr }
[ "func", "(", "s", "*", "SVG", ")", "Circle", "(", "cx", ",", "cy", ",", "r", "interface", "{", "}", ",", "args", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "circleStr", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "cx", ",", "cy", ",", "r", ",", "s", ".", "WriteArgs", "(", "args", ")", ")", "\n", "s", ".", "svgString", "+=", "circleStr", "\n", "}" ]
// Circle adds a circle element to SVG object
[ "Circle", "adds", "a", "circle", "element", "to", "SVG", "object" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/svg/svg.go#L48-L51
9,782
pravj/geopattern
svg/svg.go
Path
func (s *SVG) Path(str string, args map[string]interface{}) { pathStr := fmt.Sprintf("<path d='%s' %s />", str, s.WriteArgs(args)) s.svgString += pathStr }
go
func (s *SVG) Path(str string, args map[string]interface{}) { pathStr := fmt.Sprintf("<path d='%s' %s />", str, s.WriteArgs(args)) s.svgString += pathStr }
[ "func", "(", "s", "*", "SVG", ")", "Path", "(", "str", "string", ",", "args", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "pathStr", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "str", ",", "s", ".", "WriteArgs", "(", "args", ")", ")", "\n", "s", ".", "svgString", "+=", "pathStr", "\n", "}" ]
// Path adds a path element to SVG object
[ "Path", "adds", "a", "path", "element", "to", "SVG", "object" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/svg/svg.go#L54-L57
9,783
pravj/geopattern
svg/svg.go
Polyline
func (s *SVG) Polyline(str string, args map[string]interface{}) { polylineStr := fmt.Sprintf("<polyline points='%s' %s />", str, s.WriteArgs(args)) s.svgString += polylineStr }
go
func (s *SVG) Polyline(str string, args map[string]interface{}) { polylineStr := fmt.Sprintf("<polyline points='%s' %s />", str, s.WriteArgs(args)) s.svgString += polylineStr }
[ "func", "(", "s", "*", "SVG", ")", "Polyline", "(", "str", "string", ",", "args", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "polylineStr", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "str", ",", "s", ".", "WriteArgs", "(", "args", ")", ")", "\n", "s", ".", "svgString", "+=", "polylineStr", "\n", "}" ]
// Polyline adds a polyline element to SVG object
[ "Polyline", "adds", "a", "polyline", "element", "to", "SVG", "object" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/svg/svg.go#L60-L63
9,784
pravj/geopattern
svg/svg.go
Group
func (s *SVG) Group(elements [2]string, args map[string]interface{}) { s.svgString += fmt.Sprintf("<g %s>", s.WriteArgs(args)) s.svgString += elements[0] + elements[1] s.svgString += "</g>" }
go
func (s *SVG) Group(elements [2]string, args map[string]interface{}) { s.svgString += fmt.Sprintf("<g %s>", s.WriteArgs(args)) s.svgString += elements[0] + elements[1] s.svgString += "</g>" }
[ "func", "(", "s", "*", "SVG", ")", "Group", "(", "elements", "[", "2", "]", "string", ",", "args", "map", "[", "string", "]", "interface", "{", "}", ")", "{", "s", ".", "svgString", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "s", ".", "WriteArgs", "(", "args", ")", ")", "\n", "s", ".", "svgString", "+=", "elements", "[", "0", "]", "+", "elements", "[", "1", "]", "\n", "s", ".", "svgString", "+=", "\"", "\"", "\n", "}" ]
// Group adds a group element to SVG object. // // It groups optionally provided elements together.
[ "Group", "adds", "a", "group", "element", "to", "SVG", "object", ".", "It", "groups", "optionally", "provided", "elements", "together", "." ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/svg/svg.go#L68-L72
9,785
pravj/geopattern
svg/svg.go
WriteArgs
func (s *SVG) WriteArgs(args map[string]interface{}) string { str := "" for k, v := range args { objType := fmt.Sprintf("%s", reflect.TypeOf(v)) switch objType { case "string": str += fmt.Sprintf("%s='%s' ", k, v) case "int": str += fmt.Sprintf("%s='%v' ", k, v) case "float64": str += fmt.Sprintf("%s='%v' ", k, v) default: { str += fmt.Sprintf("%s='", k) for K, V := range v.(map[string]string) { str += fmt.Sprintf("%s:%s;", K, V) } str += "' " } } } return str }
go
func (s *SVG) WriteArgs(args map[string]interface{}) string { str := "" for k, v := range args { objType := fmt.Sprintf("%s", reflect.TypeOf(v)) switch objType { case "string": str += fmt.Sprintf("%s='%s' ", k, v) case "int": str += fmt.Sprintf("%s='%v' ", k, v) case "float64": str += fmt.Sprintf("%s='%v' ", k, v) default: { str += fmt.Sprintf("%s='", k) for K, V := range v.(map[string]string) { str += fmt.Sprintf("%s:%s;", K, V) } str += "' " } } } return str }
[ "func", "(", "s", "*", "SVG", ")", "WriteArgs", "(", "args", "map", "[", "string", "]", "interface", "{", "}", ")", "string", "{", "str", ":=", "\"", "\"", "\n\n", "for", "k", ",", "v", ":=", "range", "args", "{", "objType", ":=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "reflect", ".", "TypeOf", "(", "v", ")", ")", "\n\n", "switch", "objType", "{", "case", "\"", "\"", ":", "str", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", "\n", "case", "\"", "\"", ":", "str", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", "\n", "case", "\"", "\"", ":", "str", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ",", "v", ")", "\n", "default", ":", "{", "str", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "k", ")", "\n", "for", "K", ",", "V", ":=", "range", "v", ".", "(", "map", "[", "string", "]", "string", ")", "{", "str", "+=", "fmt", ".", "Sprintf", "(", "\"", "\"", ",", "K", ",", "V", ")", "\n", "}", "\n", "str", "+=", "\"", "\"", "\n", "}", "\n", "}", "\n", "}", "\n\n", "return", "str", "\n", "}" ]
// WriteArgs adds additional attributes to a SVG elements. // // It parses provides 'map' arguments to add attributes to SVG element.
[ "WriteArgs", "adds", "additional", "attributes", "to", "a", "SVG", "elements", ".", "It", "parses", "provides", "map", "arguments", "to", "add", "attributes", "to", "SVG", "element", "." ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/svg/svg.go#L77-L102
9,786
pravj/geopattern
examples/base64.go
main
func main() { args := map[string]string{} gp := geopattern.Base64String(args) fmt.Println(gp) }
go
func main() { args := map[string]string{} gp := geopattern.Base64String(args) fmt.Println(gp) }
[ "func", "main", "(", ")", "{", "args", ":=", "map", "[", "string", "]", "string", "{", "}", "\n", "gp", ":=", "geopattern", ".", "Base64String", "(", "args", ")", "\n", "fmt", ".", "Println", "(", "gp", ")", "\n", "}" ]
// Prints pattern's Base64 encoded string
[ "Prints", "pattern", "s", "Base64", "encoded", "string" ]
fe9aff9dff28e03f912d01846f8f00bf462363c4
https://github.com/pravj/geopattern/blob/fe9aff9dff28e03f912d01846f8f00bf462363c4/examples/base64.go#L9-L13
9,787
domainr/whois
adapter.go
Text
func (a *defaultAdapter) Text(res *Response) ([]byte, error) { r, err := res.Reader() if err != nil { return nil, err } text, err := ioutil.ReadAll(r) if err != nil { return nil, err } return text, nil }
go
func (a *defaultAdapter) Text(res *Response) ([]byte, error) { r, err := res.Reader() if err != nil { return nil, err } text, err := ioutil.ReadAll(r) if err != nil { return nil, err } return text, nil }
[ "func", "(", "a", "*", "defaultAdapter", ")", "Text", "(", "res", "*", "Response", ")", "(", "[", "]", "byte", ",", "error", ")", "{", "r", ",", "err", ":=", "res", ".", "Reader", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "text", ",", "err", ":=", "ioutil", ".", "ReadAll", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "text", ",", "nil", "\n", "}" ]
// Text returns the UTF-8 text content from the Response body.
[ "Text", "returns", "the", "UTF", "-", "8", "text", "content", "from", "the", "Response", "body", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/adapter.go#L39-L49
9,788
domainr/whois
adapter.go
adapterFor
func adapterFor(host string) Adapter { if a, ok := adapters[host]; ok { return a } return DefaultAdapter }
go
func adapterFor(host string) Adapter { if a, ok := adapters[host]; ok { return a } return DefaultAdapter }
[ "func", "adapterFor", "(", "host", "string", ")", "Adapter", "{", "if", "a", ",", "ok", ":=", "adapters", "[", "host", "]", ";", "ok", "{", "return", "a", "\n", "}", "\n", "return", "DefaultAdapter", "\n", "}" ]
// adapterFor returns an Adapter for the given host. // If it cannot find a specific named Adapter, it will return a the default Adapter. // It will always return a valid Adapter.
[ "adapterFor", "returns", "an", "Adapter", "for", "the", "given", "host", ".", "If", "it", "cannot", "find", "a", "specific", "named", "Adapter", "it", "will", "return", "a", "the", "default", "Adapter", ".", "It", "will", "always", "return", "a", "valid", "Adapter", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/adapter.go#L64-L69
9,789
domainr/whois
response.go
NewResponse
func NewResponse(query, host string) *Response { return &Response{ Query: query, Host: host, FetchedAt: time.Now().UTC(), MediaType: "text/plain", Charset: "utf-8", } }
go
func NewResponse(query, host string) *Response { return &Response{ Query: query, Host: host, FetchedAt: time.Now().UTC(), MediaType: "text/plain", Charset: "utf-8", } }
[ "func", "NewResponse", "(", "query", ",", "host", "string", ")", "*", "Response", "{", "return", "&", "Response", "{", "Query", ":", "query", ",", "Host", ":", "host", ",", "FetchedAt", ":", "time", ".", "Now", "(", ")", ".", "UTC", "(", ")", ",", "MediaType", ":", "\"", "\"", ",", "Charset", ":", "\"", "\"", ",", "}", "\n", "}" ]
// NewResponse initializes a new whois response.
[ "NewResponse", "initializes", "a", "new", "whois", "response", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L42-L50
9,790
domainr/whois
response.go
String
func (res *Response) String() string { text, err := res.Text() if err != nil { return "" } return string(text) }
go
func (res *Response) String() string { text, err := res.Text() if err != nil { return "" } return string(text) }
[ "func", "(", "res", "*", "Response", ")", "String", "(", ")", "string", "{", "text", ",", "err", ":=", "res", ".", "Text", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\"", "\"", "\n", "}", "\n", "return", "string", "(", "text", ")", "\n", "}" ]
// String returns a string representation of the response text. // Returns an empty string if an error occurs.
[ "String", "returns", "a", "string", "representation", "of", "the", "response", "text", ".", "Returns", "an", "empty", "string", "if", "an", "error", "occurs", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L59-L65
9,791
domainr/whois
response.go
Reader
func (res *Response) Reader() (io.Reader, error) { enc, err := res.Encoding() if err != nil { return nil, err } return transform.NewReader(bytes.NewReader(res.Body), enc.NewDecoder()), nil }
go
func (res *Response) Reader() (io.Reader, error) { enc, err := res.Encoding() if err != nil { return nil, err } return transform.NewReader(bytes.NewReader(res.Body), enc.NewDecoder()), nil }
[ "func", "(", "res", "*", "Response", ")", "Reader", "(", ")", "(", "io", ".", "Reader", ",", "error", ")", "{", "enc", ",", "err", ":=", "res", ".", "Encoding", "(", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "return", "transform", ".", "NewReader", "(", "bytes", ".", "NewReader", "(", "res", ".", "Body", ")", ",", "enc", ".", "NewDecoder", "(", ")", ")", ",", "nil", "\n", "}" ]
// Reader returns a new UTF-8 io.Reader for the response body.
[ "Reader", "returns", "a", "new", "UTF", "-", "8", "io", ".", "Reader", "for", "the", "response", "body", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L74-L80
9,792
domainr/whois
response.go
Encoding
func (res *Response) Encoding() (encoding.Encoding, error) { enc, _ := charset.Lookup(res.Charset) if enc == nil { return nil, fmt.Errorf("no encoding found for %s", res.Charset) } return enc, nil }
go
func (res *Response) Encoding() (encoding.Encoding, error) { enc, _ := charset.Lookup(res.Charset) if enc == nil { return nil, fmt.Errorf("no encoding found for %s", res.Charset) } return enc, nil }
[ "func", "(", "res", "*", "Response", ")", "Encoding", "(", ")", "(", "encoding", ".", "Encoding", ",", "error", ")", "{", "enc", ",", "_", ":=", "charset", ".", "Lookup", "(", "res", ".", "Charset", ")", "\n", "if", "enc", "==", "nil", "{", "return", "nil", ",", "fmt", ".", "Errorf", "(", "\"", "\"", ",", "res", ".", "Charset", ")", "\n", "}", "\n", "return", "enc", ",", "nil", "\n", "}" ]
// Encoding returns an Encoding for the response body.
[ "Encoding", "returns", "an", "Encoding", "for", "the", "response", "body", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L83-L89
9,793
domainr/whois
response.go
DetectContentType
func (res *Response) DetectContentType(ct string) { // Autodetect if not passed a Content-Type header if ct == "" { ct = http.DetectContentType(res.Body) } // Content type (e.g. text/plain or text/html) mt, params, err := mime.ParseMediaType(ct) if err != nil { return } res.MediaType = mt // Character set (e.g. utf-8) cs, ok := params["charset"] if ok { res.Charset = cs } res.DetectCharset() }
go
func (res *Response) DetectContentType(ct string) { // Autodetect if not passed a Content-Type header if ct == "" { ct = http.DetectContentType(res.Body) } // Content type (e.g. text/plain or text/html) mt, params, err := mime.ParseMediaType(ct) if err != nil { return } res.MediaType = mt // Character set (e.g. utf-8) cs, ok := params["charset"] if ok { res.Charset = cs } res.DetectCharset() }
[ "func", "(", "res", "*", "Response", ")", "DetectContentType", "(", "ct", "string", ")", "{", "// Autodetect if not passed a Content-Type header", "if", "ct", "==", "\"", "\"", "{", "ct", "=", "http", ".", "DetectContentType", "(", "res", ".", "Body", ")", "\n", "}", "\n\n", "// Content type (e.g. text/plain or text/html)", "mt", ",", "params", ",", "err", ":=", "mime", ".", "ParseMediaType", "(", "ct", ")", "\n", "if", "err", "!=", "nil", "{", "return", "\n", "}", "\n", "res", ".", "MediaType", "=", "mt", "\n\n", "// Character set (e.g. utf-8)", "cs", ",", "ok", ":=", "params", "[", "\"", "\"", "]", "\n", "if", "ok", "{", "res", ".", "Charset", "=", "cs", "\n", "}", "\n", "res", ".", "DetectCharset", "(", ")", "\n", "}" ]
// DetectContentType detects and sets the response content type and charset.
[ "DetectContentType", "detects", "and", "sets", "the", "response", "content", "type", "and", "charset", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L92-L111
9,794
domainr/whois
response.go
DetectCharset
func (res *Response) DetectCharset() { // Detect via BOM / HTML meta tag _, cs1, ok1 := charset.DetermineEncoding(res.Body, res.MediaType) // Detect via ICU cs2, ok2, html := "", false, false var det *chardet.Detector if strings.Contains(res.MediaType, "html") || true { det = chardet.NewHtmlDetector() html = true } else { det = chardet.NewTextDetector() } r, err := det.DetectAll(res.Body) if err == nil && len(r) > 0 { cs2 = strings.ToLower(r[0].Charset) ok2 = r[0].Confidence > 50 } // Prefer charset if HTML, otherwise ICU if !ok2 && (ok1 || html) { res.Charset = cs1 } else { res.Charset = cs2 } // fmt.Printf("Detected charset via go.net/html/charset: %s (%t)\n", cs1, ok1) // fmt.Printf("Detected charset via saintfish/chardet: %s (%d)\n", cs2, r[0].Confidence) }
go
func (res *Response) DetectCharset() { // Detect via BOM / HTML meta tag _, cs1, ok1 := charset.DetermineEncoding(res.Body, res.MediaType) // Detect via ICU cs2, ok2, html := "", false, false var det *chardet.Detector if strings.Contains(res.MediaType, "html") || true { det = chardet.NewHtmlDetector() html = true } else { det = chardet.NewTextDetector() } r, err := det.DetectAll(res.Body) if err == nil && len(r) > 0 { cs2 = strings.ToLower(r[0].Charset) ok2 = r[0].Confidence > 50 } // Prefer charset if HTML, otherwise ICU if !ok2 && (ok1 || html) { res.Charset = cs1 } else { res.Charset = cs2 } // fmt.Printf("Detected charset via go.net/html/charset: %s (%t)\n", cs1, ok1) // fmt.Printf("Detected charset via saintfish/chardet: %s (%d)\n", cs2, r[0].Confidence) }
[ "func", "(", "res", "*", "Response", ")", "DetectCharset", "(", ")", "{", "// Detect via BOM / HTML meta tag", "_", ",", "cs1", ",", "ok1", ":=", "charset", ".", "DetermineEncoding", "(", "res", ".", "Body", ",", "res", ".", "MediaType", ")", "\n\n", "// Detect via ICU", "cs2", ",", "ok2", ",", "html", ":=", "\"", "\"", ",", "false", ",", "false", "\n", "var", "det", "*", "chardet", ".", "Detector", "\n", "if", "strings", ".", "Contains", "(", "res", ".", "MediaType", ",", "\"", "\"", ")", "||", "true", "{", "det", "=", "chardet", ".", "NewHtmlDetector", "(", ")", "\n", "html", "=", "true", "\n", "}", "else", "{", "det", "=", "chardet", ".", "NewTextDetector", "(", ")", "\n", "}", "\n", "r", ",", "err", ":=", "det", ".", "DetectAll", "(", "res", ".", "Body", ")", "\n", "if", "err", "==", "nil", "&&", "len", "(", "r", ")", ">", "0", "{", "cs2", "=", "strings", ".", "ToLower", "(", "r", "[", "0", "]", ".", "Charset", ")", "\n", "ok2", "=", "r", "[", "0", "]", ".", "Confidence", ">", "50", "\n", "}", "\n\n", "// Prefer charset if HTML, otherwise ICU", "if", "!", "ok2", "&&", "(", "ok1", "||", "html", ")", "{", "res", ".", "Charset", "=", "cs1", "\n", "}", "else", "{", "res", ".", "Charset", "=", "cs2", "\n", "}", "\n\n", "// fmt.Printf(\"Detected charset via go.net/html/charset: %s (%t)\\n\", cs1, ok1)", "// fmt.Printf(\"Detected charset via saintfish/chardet: %s (%d)\\n\", cs2, r[0].Confidence)", "}" ]
// DetectCharset returns best guess for the reesponse body character set.
[ "DetectCharset", "returns", "best", "guess", "for", "the", "reesponse", "body", "character", "set", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L114-L142
9,795
domainr/whois
response.go
Checksum
func (res *Response) Checksum() string { h := sha1.New() h.Write(res.Body) return strings.ToLower(hex.EncodeToString(h.Sum(nil))) }
go
func (res *Response) Checksum() string { h := sha1.New() h.Write(res.Body) return strings.ToLower(hex.EncodeToString(h.Sum(nil))) }
[ "func", "(", "res", "*", "Response", ")", "Checksum", "(", ")", "string", "{", "h", ":=", "sha1", ".", "New", "(", ")", "\n", "h", ".", "Write", "(", "res", ".", "Body", ")", "\n", "return", "strings", ".", "ToLower", "(", "hex", ".", "EncodeToString", "(", "h", ".", "Sum", "(", "nil", ")", ")", ")", "\n", "}" ]
// Checksum returns a hex-encoded SHA-1 checksum of the response Body.
[ "Checksum", "returns", "a", "hex", "-", "encoded", "SHA", "-", "1", "checksum", "of", "the", "response", "Body", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L145-L149
9,796
domainr/whois
response.go
Header
func (res *Response) Header() http.Header { h := make(http.Header) h.Set("Query", res.Query) h.Set("Host", res.Host) h.Set("Fetched-At", res.FetchedAt.Format(time.RFC3339)) h.Set("Content-Type", res.ContentType()) h.Set("Content-Length", strconv.Itoa(len(res.Body))) h.Set("Content-Checksum", res.Checksum()) return h }
go
func (res *Response) Header() http.Header { h := make(http.Header) h.Set("Query", res.Query) h.Set("Host", res.Host) h.Set("Fetched-At", res.FetchedAt.Format(time.RFC3339)) h.Set("Content-Type", res.ContentType()) h.Set("Content-Length", strconv.Itoa(len(res.Body))) h.Set("Content-Checksum", res.Checksum()) return h }
[ "func", "(", "res", "*", "Response", ")", "Header", "(", ")", "http", ".", "Header", "{", "h", ":=", "make", "(", "http", ".", "Header", ")", "\n", "h", ".", "Set", "(", "\"", "\"", ",", "res", ".", "Query", ")", "\n", "h", ".", "Set", "(", "\"", "\"", ",", "res", ".", "Host", ")", "\n", "h", ".", "Set", "(", "\"", "\"", ",", "res", ".", "FetchedAt", ".", "Format", "(", "time", ".", "RFC3339", ")", ")", "\n", "h", ".", "Set", "(", "\"", "\"", ",", "res", ".", "ContentType", "(", ")", ")", "\n", "h", ".", "Set", "(", "\"", "\"", ",", "strconv", ".", "Itoa", "(", "len", "(", "res", ".", "Body", ")", ")", ")", "\n", "h", ".", "Set", "(", "\"", "\"", ",", "res", ".", "Checksum", "(", ")", ")", "\n", "return", "h", "\n", "}" ]
// Header returns a stringproto header representing the response.
[ "Header", "returns", "a", "stringproto", "header", "representing", "the", "response", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L152-L161
9,797
domainr/whois
response.go
ContentType
func (res *Response) ContentType() string { return mime.FormatMediaType(res.MediaType, map[string]string{"charset": res.Charset}) }
go
func (res *Response) ContentType() string { return mime.FormatMediaType(res.MediaType, map[string]string{"charset": res.Charset}) }
[ "func", "(", "res", "*", "Response", ")", "ContentType", "(", ")", "string", "{", "return", "mime", ".", "FormatMediaType", "(", "res", ".", "MediaType", ",", "map", "[", "string", "]", "string", "{", "\"", "\"", ":", "res", ".", "Charset", "}", ")", "\n", "}" ]
// ContentType returns an RFC 2045 compatible internet media type string.
[ "ContentType", "returns", "an", "RFC", "2045", "compatible", "internet", "media", "type", "string", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L164-L166
9,798
domainr/whois
response.go
WriteMIME
func (res *Response) WriteMIME(w io.Writer) error { io.WriteString(w, "MIME-Version: 1.0\r\n") err := res.Header().Write(w) if err != nil { return err } _, err = io.WriteString(w, "\r\n") if err != nil { return err } _, err = w.Write(res.Body) if err != nil { return err } return nil }
go
func (res *Response) WriteMIME(w io.Writer) error { io.WriteString(w, "MIME-Version: 1.0\r\n") err := res.Header().Write(w) if err != nil { return err } _, err = io.WriteString(w, "\r\n") if err != nil { return err } _, err = w.Write(res.Body) if err != nil { return err } return nil }
[ "func", "(", "res", "*", "Response", ")", "WriteMIME", "(", "w", "io", ".", "Writer", ")", "error", "{", "io", ".", "WriteString", "(", "w", ",", "\"", "\\r", "\\n", "\"", ")", "\n", "err", ":=", "res", ".", "Header", "(", ")", ".", "Write", "(", "w", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "io", ".", "WriteString", "(", "w", ",", "\"", "\\r", "\\n", "\"", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "_", ",", "err", "=", "w", ".", "Write", "(", "res", ".", "Body", ")", "\n", "if", "err", "!=", "nil", "{", "return", "err", "\n", "}", "\n", "return", "nil", "\n", "}" ]
// WriteMIME writes a MIME-formatted representation of the response to an io.Writer.
[ "WriteMIME", "writes", "a", "MIME", "-", "formatted", "representation", "of", "the", "response", "to", "an", "io", ".", "Writer", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L169-L184
9,799
domainr/whois
response.go
ReadMIME
func ReadMIME(r io.Reader) (*Response, error) { msg, err := mail.ReadMessage(r) if err != nil { return nil, err } h := msg.Header res := NewResponse(h.Get("Query"), h.Get("Host")) if res.Body, err = ioutil.ReadAll(msg.Body); err != nil { return res, err } if res.FetchedAt, err = time.Parse(time.RFC3339, h.Get("Fetched-At")); err != nil { return res, err } mt, params, err := mime.ParseMediaType(h.Get("Content-Type")) if err != nil { return res, err } res.MediaType = mt res.Charset = params["charset"] return res, nil }
go
func ReadMIME(r io.Reader) (*Response, error) { msg, err := mail.ReadMessage(r) if err != nil { return nil, err } h := msg.Header res := NewResponse(h.Get("Query"), h.Get("Host")) if res.Body, err = ioutil.ReadAll(msg.Body); err != nil { return res, err } if res.FetchedAt, err = time.Parse(time.RFC3339, h.Get("Fetched-At")); err != nil { return res, err } mt, params, err := mime.ParseMediaType(h.Get("Content-Type")) if err != nil { return res, err } res.MediaType = mt res.Charset = params["charset"] return res, nil }
[ "func", "ReadMIME", "(", "r", "io", ".", "Reader", ")", "(", "*", "Response", ",", "error", ")", "{", "msg", ",", "err", ":=", "mail", ".", "ReadMessage", "(", "r", ")", "\n", "if", "err", "!=", "nil", "{", "return", "nil", ",", "err", "\n", "}", "\n", "h", ":=", "msg", ".", "Header", "\n", "res", ":=", "NewResponse", "(", "h", ".", "Get", "(", "\"", "\"", ")", ",", "h", ".", "Get", "(", "\"", "\"", ")", ")", "\n", "if", "res", ".", "Body", ",", "err", "=", "ioutil", ".", "ReadAll", "(", "msg", ".", "Body", ")", ";", "err", "!=", "nil", "{", "return", "res", ",", "err", "\n", "}", "\n", "if", "res", ".", "FetchedAt", ",", "err", "=", "time", ".", "Parse", "(", "time", ".", "RFC3339", ",", "h", ".", "Get", "(", "\"", "\"", ")", ")", ";", "err", "!=", "nil", "{", "return", "res", ",", "err", "\n", "}", "\n", "mt", ",", "params", ",", "err", ":=", "mime", ".", "ParseMediaType", "(", "h", ".", "Get", "(", "\"", "\"", ")", ")", "\n", "if", "err", "!=", "nil", "{", "return", "res", ",", "err", "\n", "}", "\n", "res", ".", "MediaType", "=", "mt", "\n", "res", ".", "Charset", "=", "params", "[", "\"", "\"", "]", "\n", "return", "res", ",", "nil", "\n", "}" ]
// ReadMIME reads a MIME-formatted representation of the response into a Response.
[ "ReadMIME", "reads", "a", "MIME", "-", "formatted", "representation", "of", "the", "response", "into", "a", "Response", "." ]
975c7833b02e9b09b05f41cb5650339b4e913467
https://github.com/domainr/whois/blob/975c7833b02e9b09b05f41cb5650339b4e913467/response.go#L187-L207