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> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<title>Golang Counter Component</title> | |
<link rel="shortcut icon" href="data:,"> | |
<style> | |
@media (prefers-color-scheme: dark) { | |
:root { |
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" | |
"math/rand" | |
"time" | |
) | |
func main() { | |
rand.Seed(time.Now().UnixNano()) |
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 ( | |
"flag" | |
"log" | |
"net/http" | |
"os" | |
) | |
func main() { |
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
/** | |
* @param {string} text | |
*/ | |
export function parseJSON(text) { | |
if (typeof text !== 'string') { | |
return null | |
} | |
text = text.replace(/([^\"]+\"\:\s*)(\d{16,})(\,\s*\"[^\"]+|}$)/g, '$1"$2"$3') | |
return JSON.parse(text, (_, v) => typeof v === 'string' && /^\d{16,}$/.test(v) ? BigInt(v) : v) | |
} |
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
var rxEmail = regexp.MustCompile("^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$") | |
var rxUsername = regexp.MustCompile("^[a-z][a-z0-9_-]{0,17}$") |
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
const rxUpper = /([A-Z])/g | |
const observersMap = /** @type {WeakMap<any, {[x: string]: (function(string=): void)}>} */ (new WeakMap()) | |
/** | |
* Mixin that provides a mechanism to declare properties and render when they change. | |
* It uses type constructors (String, Boolean, Number, Object, Function and Symbol) to check type validity. | |
* Set the type to undefined if you don't care about it. | |
* Properties of type String, Boolean and Number are automatically reflected to attributes. | |
* Make sure to call super.connectedCallback() if you are overriding the method. | |
* |
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
const abortController = new AbortController() | |
fetch('/api/ndjson', { | |
headers: { accept: 'application/x-ndjson' }, | |
signal: abortController.signal, | |
}).then(async res => { | |
const reader = res.body.getReader() | |
const textDecoder = new TextDecoder() | |
try { |
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 ( | |
"log" | |
"net/http" | |
) | |
func main() { | |
h := http.FileServer(spaFileSystem{http.Dir("static")}) |
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 pubsub | |
import ( | |
"reflect" | |
"sync" | |
) | |
// PubSub system. | |
type PubSub interface { | |
// Pub publishes to the given topic. |
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
:root { | |
box-sizing: border-box; | |
font-family: sans-serif; | |
-ms-overflow-style: -ms-autohiding-scrollbar; | |
} | |
*, | |
::before, | |
::after { | |
box-sizing: inherit; |