Skip to content

Instantly share code, notes, and snippets.

View nicolasparada's full-sized avatar
👨‍💻

Nicolás Parada nicolasparada

👨‍💻
View GitHub Profile
@nicolasparada
nicolasparada / counter.html.tmpl
Last active October 11, 2023 19:54
Golang partial rendering component
<!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 {
@nicolasparada
nicolasparada / random_string.go
Last active January 28, 2025 17:19
Quick and easy way to generate a random string in golang
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
rand.Seed(time.Now().UnixNano())
package main
import (
"flag"
"log"
"net/http"
"os"
)
func main() {
@nicolasparada
nicolasparada / json.js
Last active March 8, 2019 14:40
JSON encoding with BigInt support
/**
* @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)
}
var rxEmail = regexp.MustCompile("^[^\\s@]+@[^\\s@]+\\.[^\\s@]+$")
var rxUsername = regexp.MustCompile("^[a-z][a-z0-9_-]{0,17}$")
@nicolasparada
nicolasparada / properties-mixin.js
Created August 8, 2018 18:37
Mixin for custom elements to easily declare properties.
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.
*
@nicolasparada
nicolasparada / client.js
Last active September 18, 2023 15:58
Newline Delimited JSON (NDJSON) Demo
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 {
@nicolasparada
nicolasparada / main.go
Created June 1, 2018 00:32
To serve single page applications
package main
import (
"log"
"net/http"
)
func main() {
h := http.FileServer(spaFileSystem{http.Dir("static")})
@nicolasparada
nicolasparada / pubsub.go
Last active July 27, 2018 06:51
Golang PubSub
package pubsub
import (
"reflect"
"sync"
)
// PubSub system.
type PubSub interface {
// Pub publishes to the given topic.
@nicolasparada
nicolasparada / styles.css
Last active May 24, 2018 09:47
Base Stylesheet
:root {
box-sizing: border-box;
font-family: sans-serif;
-ms-overflow-style: -ms-autohiding-scrollbar;
}
*,
::before,
::after {
box-sizing: inherit;