Skip to content

Instantly share code, notes, and snippets.

a new journey

Oliver N olvrng

a new journey
View GitHub Profile
View unpopulatedFieldRanger.go
// 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
olvrng / findIntersection.js
Last active Mar 24, 2021
find intersection of N strictly sorted lists
View findIntersection.js
// 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
olvrng / go.json
Created Mar 20, 2021
List of golang/go files from GitHub API
View go.json
olvrng / regexp.go
Last active Mar 4, 2021
a function for batch processing regular expressions
View regexp.go
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 {
View index-0.html
<script type="module" src="myscript.js"></script>
View index.html
<!doctype html>
<html lang="en">
<title>My little app</title>
<script type="module" src="myscript.js"></script>
View promise_with_timeout.js
// 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) => {
olvrng / proxy.go
Created Jan 20, 2021
A simple http proxy in Go
View proxy.go
package main
import (
var client = http.Client{Timeout: 5 * time.Second}
olvrng / 0_simplest.go
Last active Jan 9, 2021
ujson: examples
View 0_simplest.go
package main
import "fmt"
import ""
func main() {
input0 := []byte(`true`)
ujson.Walk(input0, func(level int, key, value []byte) bool {
fmt.Printf("level=%v key=%s value=%s\n", level, key, value)
return true
olvrng / µjson.go
Last active Feb 27, 2019
Minimal JSON parser which works with correct input only
View µjson.go
// Minimal JSON parser which works with correct input only.
// Usecase:
// 1. Walk through unstructured json
// 2. Transform unstructured json
// without fully unmarshalling it into a map[string]interface{}
// Caution: Behaviour is undefined on invalid json. Use on trusted input only.
package µjson