This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package xconvey | |
import ( | |
"fmt" | |
"testing" | |
// Workaround for ginkgo flags used in CI test commands. Without this import, ginkgo flags are not registered and | |
// the command "go test -v ./... -ginkgo.v" will fail. But for some other reason, ginkgo can not be imported from | |
// both test and non-test packages (error: flag redefined: ginkgo.seed). So test files using this package (xconvey) | |
// must NOT import ginkgo. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Counter { | |
constructor() { | |
this.name = 'Counter'; | |
this.count = 0; | |
} | |
inc() { | |
this.count++; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// unpopulatedFieldRanger wraps a protoreflect.Message and modifies its Range | |
// method to additionally iterate over unpopulated fields. | |
type unpopulatedFieldRanger struct{ pref.Message } | |
func (m unpopulatedFieldRanger) Range(f func(pref.FieldDescriptor, pref.Value) bool) { | |
fds := m.Descriptor().Fields() | |
for i := 0; i < fds.Len(); i++ { | |
fd := fds.Get(i) | |
if m.Has(fd) || fd.ContainingOneof() != nil { | |
continue // ignore populated fields and fields within a oneofs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// find intersection of 2 strictly sorted lists | |
function findIntersection(a: number[], b: number[]): number[] { | |
let ai = 0, bi = 0, result = []; | |
while (ai < a.length && bi < b.length) { | |
if (a[ai] < b[bi]) ai++; | |
else if (a[ai] > b[bi]) bi++; | |
else { // they are equal | |
result.push(a[ai]); | |
ai++; | |
bi++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
".gitattributes", | |
".github", | |
".github/CODE_OF_CONDUCT.md", | |
".github/ISSUE_TEMPLATE", | |
".github/PULL_REQUEST_TEMPLATE", | |
".github/SUPPORT.md", | |
".gitignore", | |
"AUTHORS", | |
"CONTRIBUTING.md", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func processRegex( | |
s string, rs []*regexp.Regexp, | |
fn func(string), funcs ...func(string, ...string), | |
) { | |
if len(rs) != len(funcs) { | |
panic("func and regex do not match") | |
} | |
for s != "" { | |
mi, minA, minB, mIdx := 0, len(s), len(s), []int(nil) | |
for i, re := range rs { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="module" src="myscript.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html lang="en"> | |
<head> | |
<title>My little app</title> | |
</head> | |
<body> | |
<script type="module" src="myscript.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// execute function(s) with a limit timeout, throws error if the function(s) | |
// do not complete within the given time | |
export function execWithTimeout(timeout, ...promises) { | |
let timeoutId; | |
const countDown = new Promise((_, reject) => { | |
timeoutId = setTimeout(reject, timeout, new Error('timed out')); | |
}); | |
return Promise.race([countDown, ...promises]).then((result) => { | |
clearTimeout(timeoutId); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"net/http" | |
"time" | |
) | |
var client = http.Client{Timeout: 5 * time.Second} |
NewerOlder