Skip to content

Instantly share code, notes, and snippets.

View kristoferjoseph's full-sized avatar
🐈‍⬛

kj kristoferjoseph

🐈‍⬛
View GitHub Profile
@kristoferjoseph
kristoferjoseph / store.mjs
Last active October 1, 2020 17:16
store
const listeners = []
const state = {}
let noop = x => x
function subscribe (fn) {
listeners.push(fn)
}
function unsubscribe (fn) {
listeners.splice(listeners.indexOf(fn), 1)
// dam
// https://hydra-editor-v1.glitch.me/?sketch_id=49UOxU0Jt6OzQwuc&code=YS5zZXRTY2FsZSUyMCgyMCklMEFhLnNldEJpbnMlMjAoMTUpJTBBJTJGJTJGJTBBYS5zZXR0aW5ncyU1QjAlNUQuY3V0b2ZmJTIwJTNEJTIwMSUwQWEuc2V0dGluZ3MlNUIxJTVELmN1dG9mZiUyMCUzRCUyMDIlMEFhLnNldHRpbmdzJTVCMiU1RC5jdXRvZmYlMjAlM0QlMjA0JTBBYS5zZXR0aW5ncyU1QjMlNUQuY3V0b2ZmJTIwJTNEJTIwNiUwQWEuc2V0dGluZ3MlNUI0JTVELmN1dG9mZiUyMCUzRCUyMDglMEFhLnNldHRpbmdzJTVCNSU1RC5jdXRvZmYlMjAlM0QlMjA5JTBBJTBBJTBBc2hhcGUoMykuc2NhbGUoKCklM0QlM0UlMjBhLmZmdCU1QjMlNUQqMiUyMCUyQjEpJTBBLmJsZW5kKG8wKS5hZGQoc2hhcGUoMykuY29sb3IoMCUyQzAlMkMwLjIpKSUwQS5ibGVuZChvMCkuY29sb3IoMCUyQzAuNSUyQzAuNSklMEEuYmxlbmQobzApLnJvdGF0ZSgoKSUzRCUzRSUyMGEuZmZ0JTVCMSU1RCowLjElMjAtMC4yKSUwQS5zY3JvbGxZKC0wLjUyJTJDLTAuMiklMEEuYWRkKHNoYXBlKDMpLmNvbG9yKDMlMkMwJTJDMikuc2Nyb2xsWSgoKSUzRCUzRSUyMGEuZmZ0JTVCMCU1RCowLjclMjAtMC4xJTJDLTAuMDIpKS5zY2FsZSgoKSUzRCUzRSUyMGEuZmZ0JTVCMiU1RCowLjclMjAtMC44KSUwQS5zY2FsZSgoKSUzRCUzRSUyMGEuZmZ0JTVCMyU1RCoyJTIwLTEpJTBBLm1vZHVsYXRlKG8wJTJDKCklM0QlM0UlMjBhLmZmdCU1QjMlNUQqMC4xJTIwLTAuMiklMEE
@kristoferjoseph
kristoferjoseph / get-index.js
Created October 25, 2018 21:54
Example get-index/index.js file for arc-example-views
let Layout = require('@architect/views/layout')
exports.handler = async function http (request) {
return {
type: 'text/html; charset=utf8',
body: Layout()
}
}
@kristoferjoseph
kristoferjoseph / layout.js
Created October 25, 2018 21:45
Example layout file for arc-example-views
module.exports = function Layout (props) {
props = props || {}
let heading = props.heading || 'Architect views!'
return `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Architect example</title>
</head>
@kristoferjoseph
kristoferjoseph / proxy-store.mjs
Created July 23, 2018 22:12
Possible store implementation using Proxy.
const state = {}
const listeners = []
let aid
const handler = {
set: function setter (obj, prop, value) {
let old = obj[prop]
if (old !== value) {
obj[prop] = value
if (aid) {
window.cancelAnimationFrame(aid)
@kristoferjoseph
kristoferjoseph / simple-store.mjs
Created July 19, 2018 23:44
Tried to make the simplest store module I could muster. Works pretty well.
var listeners = []
var state = {}
var noop = x => x
function subscribe (fn) {
listeners.push(fn)
}
function unsubscribe (fn) {
listeners.splice(listeners.indexOf(fn), 1)
@kristoferjoseph
kristoferjoseph / Server.py
Last active June 25, 2021 09:54 — forked from HaiyangXu/Server.py
A simper python http server can handle mime type properly
# -*- coding: utf-8 -*-
#test on python 3.4 ,python of lower version has different module organization.
import http.server
from http.server import HTTPServer, BaseHTTPRequestHandler
import socketserver
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler
@kristoferjoseph
kristoferjoseph / config.json
Last active May 16, 2018 17:19
Example styleguide css
{
"base": 18,
"scale": {
"ratio": "perfectFourth",
"steps": 8
},
"colors": {
"primary": [
{
"label": "transparent",
@kristoferjoseph
kristoferjoseph / component.js
Last active March 29, 2018 22:50
Modern Preact Component without class
var preact = require('preact')
module.exports = function Component (name, obj) {
name = name || 'F'
obj = obj || {}
var fn = function () { preact.Component.call(this) }
Object.defineProperty(fn, 'name', { value: name })
fn.prototype = Object.create(preact.Component.prototype)
fn.prototype = Object.assign(fn.prototype, obj)
if (obj.getDefaultProps &&
(typeof obj.getDefaultProps === 'function')) {
@kristoferjoseph
kristoferjoseph / component.js
Last active May 24, 2020 23:16
Component prototype
var html = require('bel')
var morph = require('nanomorph')
var inWindow = require('in-window')
var onload = require('on-load')
module.exports = function Component (options) {
options = options || {}
var template = options.template
var should = options.should || function () { return true }
var added = options.added