Skip to content

Instantly share code, notes, and snippets.

View dzenzes's full-sized avatar

Daniel Zenzes dzenzes

View GitHub Profile
@dzenzes
dzenzes / HTML5-boilerplate
Created March 9, 2012 20:17
my HTML5 boilerplate
<!DOCTYPE html>
<meta charset=utf-8 />
<title>hi</title>
<style>
</style>
<div></div>
(ns roman-numeral)
(def number-to-roman-numeral
[
{:number 1000 :roman "M"}
{:number 900 :roman "CM"}
{:number 500 :roman "D"}
{:number 400 :roman "CD"}
{:number 100 :roman "C"}
{:number 90 :roman "XC"}

Types

A type is a collection of possible values. An integer can have values 0, 1, 2, 3, etc.; a boolean can have values true and false. We can imagine any type we like: for example, a HighFive type that allows the values "hi" or 5, but nothing else. It's not a string and it's not an integer; it's its own, separate type.

Statically typed languages constrain variables' types: the programming language might know, for example, that x is an Integer. In that case, the programmer isn't allowed to say x = true; that would be an invalid program. The compiler will refuse to compile it, so we can't even run it.

@dzenzes
dzenzes / react-string-list.js
Last active October 16, 2018 06:13
Example code for my blog article
const ListItem = ({ text }) => <li>{text}</li>;
const FeatureList = ({ features }) => (
<ul>
{features.map((feature, idx) => (
<ListItem text={feature} key={idx} />
))}
</ul>
);
<template id="feature">
<li></li>
</template>
<ul id="webcomponents">
<!-- list items should get here -->
</ul>
if ("content" in document.createElement("template")) {
// (1) the magic is gonna happen here
} else {
document.body.appendChild(
document.createTextNode("HTML templates are not supported") // (2)
);
}
if ("content" in document.createElement("template")) {
const features = [
"HTML Template",
"HTML Import",
"Shadow DOM",
"Custom Elements"
];
const template = document.querySelector("#feature"); // (1)
let listItem = template.content.querySelectorAll("li"); // (2)
<!-- importMe.html -->
<ul id="webcomponents">
<li>HTML Template</li>
<li>HTML Import</li>
<li>Shadow DOM</li>
<li>Custom Elements</li>
</ul>
<link rel="import" href="importMe.html" />