Skip to content

Instantly share code, notes, and snippets.

function updateList(container, make, newList, prev = [], keyName = "key") {
function insertNode(node, pos) {
if (pos >= container.children.length) {
container.appendChild(node);
prev.push(node.dataset[keyName]);
} else {
container.insertBefore(node, container.children[pos]);
prev.splice(pos, 0, node.dataset[keyName]);
}
}
@jaeschrich
jaeschrich / README.md
Last active March 20, 2021 03:17
traits.js -- a simple (25 LOC) way to make composable components with plain javascript

Traits

Traits are a lightweight way to create plain javascript components that play nicely with each other and with bigger frameworks like React, Angular, Vue, etc.

The API for most plain javascript components (sliders, buttons, click-to-drag, etc.) looks like something this:

let node = document.querySelector("#node")
let component = createComponent(node, /* config options */)
/*
** thumpButton(btn)
** btn should be reference to the button to
** make into a thump button
*/
function thumpButton(btn) {
/* env is a list of parameters that
affect the pitch of the thump
and whether the thump is reversed */
let env = {
@jaeschrich
jaeschrich / install_mod.bat
Last active December 20, 2015 10:49
On windows, drag Minecraft mod archive files (.jar, .zip, etc) onto this script to install them. Requires Minecraft forge and Minecraft 1.6.2.
@echo off
REM If needed, change this path
REM Place this file on your desktop to "just work"
copy "%1" "..\AppData\Roaming\.minecraft\mods"
echo If this says 1 file copied, install is complete
pause
@jaeschrich
jaeschrich / install_mod.bat
Created July 31, 2013 00:47
On windows, drag Minecraft mod archive files (.jar, .zip, etc) onto this script to install them. Requires Minecraft forge and Minecraft 1.6.2.
@echo off
REM If needed, change this path
REM Place this file on your desktop to "just work"
copy "%1" "..\AppData\Roaming\.minecraft\mods"
@jaeschrich
jaeschrich / coinToss.js
Created July 13, 2013 01:26
Heads or tails
function notZero(){
var i = Math.floor(Math.random()*10);
return (i!=0)?i:notZero();
}
function coin(){
return (notZero()%2 === 0)?"heads":"tails";
}
exports = module.exports = coin;
@jaeschrich
jaeschrich / jsx.js
Created June 15, 2013 14:05
Syntax sugar javascript
/*
javascript syntax sugar
see comments for detials
*/
var vm = require("vm"),
fs = require("fs");
function compile(f){
fn = fs.readFileSync(f)
.toString()
@jaeschrich
jaeschrich / emitter.coffee
Created June 14, 2013 02:25
CoffeScript event emitter
class Emitter
constructor: ->
@events = {}
on: (e, cb)->
@events[e] = [] unless @events[e]
@events[e].push cb
this
off: (e, cb)->
unless cb
@events[e] = []
@jaeschrich
jaeschrich / menu.php
Last active December 16, 2015 11:19
extensible PHP menu component
<ul class="nav nav-pills">
<?php
/*
$curPage = "current page";
include "menu.php";
*/
$links = array(
array('href'=>'/index.php', 'name'=>'Home'),
// add some more
);
@jaeschrich
jaeschrich / buttons.css
Last active December 16, 2015 08:39
Simple, flat buttons
/*
simple, flat buttons
http://jsbin.com/icozal/2
*/
.btn-blue {
border-style: none;
border-radius: 0px;
background-color: #2BF;
-webkit-transition: background-color 0.2s;
-moz-transition: background-color 0.2s;