Skip to content

Instantly share code, notes, and snippets.

View olanod's full-sized avatar
🐧

Daniel Olano olanod

🐧
View GitHub Profile
@olanod
olanod / custom_element.js
Last active August 18, 2023 19:29
Custom element boiler plate
const p = new DOMParser();
const tagFn = fn => (strings, ...parts) => fn(parts
.reduce((tpl, value, i) => `${tpl}${strings[i]}${value}`, '')
.concat(strings[parts.length]))
const html = tagFn(s => new DOMParser()
.parseFromString(`<template>${s}</template>`, 'text/html')
.querySelector('template'))
const css = tagFn(s => {
let style = new CSSStyleSheet()
style.replaceSync(s)

Keybase proof

I hereby claim:

  • I am olanod on github.
  • I am olanod (https://keybase.io/olanod) on keybase.
  • I have a public key ASCWuwXgnKf8lH_Xw4ZKTBNlMjuEshtkbtg6OeBq_yv7Jgo

To claim this, I am signing this object:

@olanod
olanod / Makefile
Created April 27, 2017 09:27
Go makefile with cross compilation
default: build
OS=$(shell uname | tr [:upper:] [:lower:])
PLATFORMS=linux darwin freebsd
PKG_NAME=$(shell glide name)
APP_NAME=$(shell basename $(PKG_NAME))
APP_VERSION=$(shell git describe --tags --always)
BRANCH?=$(shell git rev-parse --abbrev-ref HEAD)
BUILD_DIR?=build
@olanod
olanod / templates.js
Last active April 2, 2024 05:00
Simple template loader. A global object that loads and caches templates.
const templates = Object.create(null, {
load: {
value: async function(fileName) {
const url = new URL(fileName,
document.currentScript && document.currentScript.src || location.href)
if (url in this) return this[url]
// fetch and parse template as string
let template = await fetch(url)
template = await template.text()
template = new DOMParser().parseFromString(template, 'text/html')
@olanod
olanod / EventEmitter.js
Created January 12, 2016 16:04
Super simple and elegant implementation of an event emitter that follows the EventTarget interface of browsers using ES6 goodness.
// store for private variables
let _ = new WeakMap();
/**
* Event emitter following browser's EventTarget interface
*/
export class EventEmitter {
constructor() {
_.set(this, { callbacks: new Map() });
@olanod
olanod / recursive-list.js
Last active August 17, 2021 05:53
Recursive HTML List
var navigation = createList(globalDataSet);
/**
* Create an HTML list from a tree-like data set
* @param {Array} data Recursive array
* @return {HTMLUListElement} Unordered list with the recursive set of children
*/
function createList(data) {
var listElement = createListElement();