Using the -ldflags parameter can help set variable values at compile time.
Using the example provided here:
- Running
make buildwill create abuildexecutable. Running it will result in:
$> ./build
no version (Mon YYYY)
$>| set nocompatible " Use Vim defaults (much better!) | |
| set bs=2 " allow backspacing over everything in insert mode | |
| set ai " always set autoindenting on | |
| set backup " keep a backup file | |
| set viminfo='20,\"50 " read/write a .viminfo file, don't store more | |
| " than 50 lines of registers | |
| set history=50 " keep 50 lines of command line history | |
| " 000328 from article in Linux Journal, Apr 2000 | |
| set incsearch " searches as you enter the string! | |
| set ignorecase " Ignore case in searching for matches set smartcase " Ignore case ONLY if all lower case srch str |
| # suffix characters (base 32, sort of) | |
| SUFFIX_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ012345" | |
| def id18(s: str, *, check_suffix: bool = False) -> str: | |
| """ | |
| Converts a 15 character Salesforce ID (s) to its 18 character version. | |
| If the ID provided has length 18 and check_suffix is True, we will assert | |
| that the suffix is correct! |
| #!/usr/bin/env python2 | |
| # -*- coding: utf-8 -*- | |
| """ | |
| Learning me some context managers | |
| """ | |
| # NOTE: see also: contextlib.contextmanager | |
| class Context(object): |
| from urllib.parse import urlencode, urlparse | |
| def build_url(base: str, *path, qparams: dict=None, trail_slash: bool=False) -> str: | |
| ''' | |
| As close to a generic URL builder for G-API as possible | |
| Assumption(s): | |
| 1. base is a valid URL with an `https` scheme and a valid `netloc` | |
| 2. path is a variable number of path arguments |
| package fun | |
| // bufferedSequence | |
| type bufferedSeq struct { | |
| seq Seq // original Seq | |
| buf *[]float64 // shared slice | |
| pos int // this pos | |
| } | |
| // Next implements Seq interface |
| package tristate | |
| import "sync" | |
| // State for a tristate cache | |
| type State int | |
| // cache State contants | |
| const ( | |
| Miss State = iota |
| #!/usr/bin/env python3 | |
| # -*- coding: utf-8 -*- | |
| def dird(cls): | |
| """ | |
| return a generator that yields all methods for `cls` | |
| that do not start with underscore (_) | |
| """ | |
| cn = type(cls).__name__ |
Using the -ldflags parameter can help set variable values at compile time.
Using the example provided here:
make build will create a build executable. Running it will result in:$> ./build
no version (Mon YYYY)
$>| package stack | |
| import ( | |
| "reflect" | |
| "sync" | |
| ) | |
| // Stack implements Push & Pop | |
| type Stack interface { | |
| Push(interface{}) |
| package main | |
| import ( | |
| "context" | |
| "flag" | |
| "log" | |
| "math/rand" | |
| "os" | |
| "os/signal" | |
| "sync" |