Skip to content

Instantly share code, notes, and snippets.

@donpark
donpark / FramePort.js
Last active Jun 29, 2020
Frame postMessage helper with request/response support
View FramePort.js
/**
* Create port to an iframe element:
*
* const iframePort = new FramePort(iframeEl);
*
* Create port to parent window:
*
* const parentPort = new FramePort(window.parent);
*
* Post a message:
View scriptBaseUrl.js
// This needs to run when script loads.
const scriptUrl = new URL(document.currentScript.src, document.baseURI).toString();
const scriptBaseUrl = scriptUrl.substr(0, scriptUrl.lastIndexOf('/'));
// To build URL relative to script file.
const wasm = `${scriptBaseUrl}/wasm/my.wasm`
@donpark
donpark / merge-example.ts
Last active Mar 3, 2020
Neat deep merge using TypeScript generics
View merge-example.ts
import { mergeObjects } from "./merge";
const defaultOptions = {
userMedia: {
audio: true,
video: false,
channelCount: 1,
autoGainControl: true,
echoCancellation: true,
noiseSuppression: true
@donpark
donpark / VIA Porting Info.md
Created May 23, 2019 — forked from nooges/VIA Porting Info.md
Info on adding VIA Configurator support to a board using QMK
View VIA Porting Info.md

Making a board compatible with VIA Configurator

💥NOTE💥: Don't do this yet, all of this stuff is still 🚑💣BLEEDING EDGE💣🚑, and you will 🔪cut yourself🔪 badly if you choose to do it. Please wait for 🗿Wilba's QMK code to be refactored prior to pushing anything to QMK, as we don't want to end up with a bunch of different forks of the code.

So you've seen VIA Configurator in action, and you want to get this magic supported for your board?

There's two main steps:

  1. Add dynamic keymap support to keyboard in QMK
  2. Add layout to VIA
View ztype.js
// Built with IMPACT - impactjs.org
(function (window) {
"use strict";
Number.prototype.map = function (istart, istop, ostart, ostop) {
return ostart + (ostop - ostart) * ((this - istart) / (istop - istart));
};
Number.prototype.limit = function (min, max) {
return Math.min(max, Math.max(min, this));
};
Number.prototype.round = function (precision) {
@donpark
donpark / hdlines.js
Created Aug 11, 2017 — forked from srt19170/hdlines.js
Hand-Drawn Lines Code (Javascript)
View hdlines.js
//
// Draw a line with the given curve, and then resample it
// to a new set of points. <step> is the distance to step
// along the line when taking a new point.
//
function drawInterpolate(svg, points, step, curve) {
curve = curve || d3.curveCatmullRom.alpha(1.0);
step = step || 1;
var lineFunc = d3.line()
.curve(curve)
@donpark
donpark / JSONFeed.ts
Last active Mar 16, 2021
Rough first cut of JSON Feed types and interfaces
View JSONFeed.ts
/** JSON Feed TypeScript Declaration
* Spec Version: 1
*/
declare namespace JSONFeed {
const MIME_TYPE = 'application/json'
type DATEstring = RFC3339string
type IDstring = string
@donpark
donpark / PaperSetup.tsx
Created May 6, 2017
Setup Paper.js for use in React.js
View PaperSetup.tsx
import * as React from 'react'
import { Component } from 'react'
import { PaperScope } from 'paper'
export class PaperSetup extends Component<any, any> {
constructor(props) {
super(props)
window['paper'] = new PaperScope()
}
@donpark
donpark / NotificationEnum.swift
Created Dec 2, 2016
How to use enum of Notification.Name
View NotificationEnum.swift
import Foundation
// Extension allowing enum of Notification.Names.
#if swift(>=3.0)
extension Notification.Name: ExpressibleByStringLiteral {
public init(stringLiteral value: String) {
self.init(value)
}
@donpark
donpark / README.md
Created Nov 22, 2016
Visible Touch support for demos and ReplayKit uses
View README.md

Integration

Add VisibleTouch.swift to your project then replace window instance variable declaration in AppDelegate.swift file:

var window: UIWindow?

with:

var window: UIWindow? = VisibleTouch.Window(frame: UIScreen.main.bounds)