Skip to content

Instantly share code, notes, and snippets.

View nicolasparada's full-sized avatar
👨‍💻

Nicolás Parada nicolasparada

👨‍💻
View GitHub Profile
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;
Verifying my Blockstack ID is secured with the address 1CcXMTDRMcfAYnv2zMxn1dueK2mwrJJgoH https://explorer.blockstack.org/address/1CcXMTDRMcfAYnv2zMxn1dueK2mwrJJgoH
@nicolasparada
nicolasparada / ago.js
Last active June 3, 2018 00:15
Formats dates: Just now | 20s | 5m | 10h | 5d | 11 May | 18 Sep, 2017
const MONTHS = [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',