Skip to content

Instantly share code, notes, and snippets.

View jacwright's full-sized avatar
👨‍💻
Working on Dabble

Jacob Wright jacwright

👨‍💻
Working on Dabble
View GitHub Profile
// Required modules.
var cradle = require('cradle');
var util = require('util');
var http = require('http');
// Config.
var config = require('./config');
// Create a new HTTP server to accept Postmark POSTs.
http.createServer(function(req, res) {
@jacwright
jacwright / bindings.coffee
Created April 28, 2015 15:51
Aliases existing chip bindings to use [*], (*), and {*}
# Add aliases for the bindings to use brackets, e.g. bind-value becomes [value]
chip.Binding.bindings.slice().forEach (binding) ->
name = binding.name
return if name.indexOf('-*') >= 0
if binding.name.indexOf('bind-') is 0 || binding.name.indexOf('attr-') is 0
name = '[' + name.replace(/^(bind|attr)-/, '') + ']'
chip.binding name, binding.priority, binding.handler
else if binding.name.indexOf('on-') is 0
name = '(' + name.replace(/^on-/, '') + ')'
@jacwright
jacwright / class.js
Created November 19, 2015 20:51
Fix class.extend to support class.static and removes mixins
function Class() {}
Class.extend = extend;
module.exports = Class;
function extend(Subclass, prototype) {
// Support no constructor
if (typeof Subclass !== 'function') {
prototype = Subclass;
var SuperClass = this;
Subclass = function() {
@jacwright
jacwright / Model.js
Created December 10, 2015 17:56
Constructor that returns a new constructor
function Model() {
var constructor = function(props) {
Object.keys(props).forEach(function(key) {
this[key] = props[key];
}, this);
};
constructor.prototype = Object.create(Model.prototype);
constructor.prototype.constructor = constructor;
return constructor;
@jacwright
jacwright / post-commit
Created March 11, 2016 07:17
For Chip, copy docs to jekyll website
#!/bin/sh
#
# Copies the docs over to the website repository and commits it
folder_name=${PWD##*/}
LAYOUT_PREFIX='---\r\nlayout: default\r\n---\r\n\r\n'
mkdir -p "../chip-js.github.io/docs/$folder_name"
if [ -d "docs" ]; then
@jacwright
jacwright / link-accounts.js
Created May 8, 2017 15:40
Auth0: Link Accounts with Same Email Address while Merging Metadata
@jacwright
jacwright / userId.js
Created May 8, 2017 15:41
Auth0: Set unique ID for a user
function (user, context, callback) {
if (!user.app_metadata) {
user.app_metadata = {};
}
if (!user.app_metadata.userId || user.app_metadata.userId.length < 24) {
var idLength = 24;
var chars = (
'0123456789abcdefghijklmnopqrstuvwxyz'
).split('');
@jacwright
jacwright / svelte-observe.js
Last active September 19, 2018 17:08
One `observe` for all svelte needs.
export function observe(key, callback, opts) {
const single = !Array.isArray(key);
const keypaths = single ? [ key ] : key;
const parts = keypaths.map(keypath => keypath.replace(/\[(\d+)\]/g, '.$1').split('.'));
const keys = parts.map(parts => parts[0]);
const fn = callback.bind(this);
let last = parts.map(parts => getNestedValue(this.get(), parts));
if (!opts || opts.init !== false) {
@jacwright
jacwright / Route.html
Created February 5, 2019 22:50
How do I update stores from reactive declaration updates
{#if match !== null}
<slot></slot>
{/if}
<script>
import { getHistory, matchPath, ROUTING_CONTEXT } from './index.js';
import { writable } from 'svelte/store.js';
import { setContext, onDestroy } from 'svelte';
const history = getHistory();
const matchStore = writable(null);
@jacwright
jacwright / signals.ts
Created September 6, 2019 14:57
TypeScript Signals, A simple typed alternative to events.
/**
* Tiny. Compiled code for signals results in 15 lines of JS, < 500 bytes of uncompressed code.
*
* Usage:
*
* const clickedSave = createSignal<Doc>();
*
* clickedSave(doc => {
* // do something to save the doc, or when the doc is saved
* })