Skip to content

Instantly share code, notes, and snippets.

@honewatson
honewatson / example.loader.html
Last active April 21, 2018 03:50
Loader JS Dynamic Loading
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Index</title>
</head>
<body>
<div id="ROOT"></div>
@honewatson
honewatson / pattern_matching.nim
Last active April 24, 2018 02:34
Nim Pattern Matching Example
#chokidar "*.nim" -c "nim js -r test.nim"
import patty
import jsconsole
import jsffi
import zero_functional
import templates
type
Html* = object
title*: cstring
@honewatson
honewatson / concepts.nim
Last active November 17, 2024 06:17
Nim Concepts Example - Concepts are Generics
import strutils
type
Dispatch = enum
Reveal
IKind = enum
Human, NonHuman
ObIkind = ref object of RootObj
kind*: IKind
Person = object of ObIkind
@honewatson
honewatson / nim-watcher.sh
Last active December 19, 2017 20:50
Watcher environment for Nim
npm install -g chokidar-cli
nim c --run <name_of_entry>.nim
chokidar '*.nim' -c 'killall -9 <name_of_entry>; nim c --run <name_of_entry>.nim'
@honewatson
honewatson / toggle.js
Last active September 20, 2017 22:54
Simple JS Class Toggle
const eventManager = (listeners, app={}) => (eventData, listener) => {
try {
listeners[listener](eventData, app);
}
catch(e) {
console.trace(e);
}
}
const toggle = classElement => {
@honewatson
honewatson / hyperapp-router.js
Created August 17, 2017 06:39
HyperApp 0.11.0 Router
/**
mixins: [
Router(view)
],
*/
export function Router(appView) {
return function router(emit, view) {
return {
state: {
router: match(location.pathname)
@honewatson
honewatson / app.js
Last active July 20, 2017 23:04
Basic Hyperapp Style application for React
const copy = obj =>
JSON.parse(JSON.stringify(obj));
export const app (obj) => {
let state = copy(obj.state);
const actions = {};
Object.keys(obj.actions).forEach(action => {
const actionWrapper = (...params) => {
if(Array.isArray(params)) {
params = copy(params);
@honewatson
honewatson / stateless.nim
Created July 18, 2017 08:39
Nim Stateless Components
import stringinterpolation
import sequtils
type
Link = tuple[name: string, url: string]
Links = seq[Link]
State = tuple[title: string, links: Links]
proc join(items: seq[string]): string =
result = ""
@honewatson
honewatson / XPATH
Created July 12, 2017 04:38
DOM XPATH first element by class name and text type
(.//span[@class='categoryCount' and text()="1"])[1]
@honewatson
honewatson / doc_tags.sql
Created February 9, 2017 21:53
Postgres Array, DOC Tags
table doc_tags_array (
doc_id int not null references documents(doc_id),
tags text[] not null default '{}'
)
unique index doc_tags_id_doc_id on (doc_id)
index doc_tags_id_tags using gin (tags)
-- One Tag + Offset
select doc_id