Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeffrey Wear wearhere

View GitHub Profile
@wearhere
wearhere / Playground.swift
Last active May 29, 2020
Apply skin tone modifiers to emojis per the Unicode spec.
View Playground.swift
import Foundation
import UIKit
import CoreText
// You can run this by copying this file into a Swift playground.
extension String {
// Returns the number of glyphs used to render the string. If this string
// should behave like a single emoji character (regardless of whether it is,
@wearhere
wearhere / Playground.swift
Created May 28, 2020
Trying to figure out how to apply skin tone modifiers to gemoji
View Playground.swift
import Foundation
// Each pair below is a "base" emoji copied from gemoji's emoji.json,
// followed by a modified emoji copied from OS X' "Emoji & Symbols" menu.
// You can run this by copying this file into a Swift playground.
// For readers' convenience, I've printed the output inline below.
// 1.
"🖐️".unicodeScalars.forEach { (c) in
@wearhere
wearhere / TextDocumentProxy.swift
Last active Apr 29, 2020
A generic implementation of the `UITextDocumentProxy` protocol that should work for anything that conforms to `UIResponder` and `UITextInput`. Useful to put text fields inside custom keyboards and then reuse your keyboard's regular handling logic with this text field. See https://github.com/danielsaidi/KeyboardKit/issues/45 for more info.
View TextDocumentProxy.swift
//
// documentProxy.swift
// KeyboardKitDemoKeyboard
//
// Created by Jeffrey Wear on 4/28/20.
//
import UIKit
class TextDocumentProxy<TextDocument: UIResponder & UITextInput>: NSObject, UITextDocumentProxy {
@wearhere
wearhere / client.js
Last active Jun 8, 2018
Making SSE easy
View client.js
import _ from 'underscore';
import $ from 'jquery';
import Backbone from 'backbone';
const DataCollection = Backbone.Collection.extend({
url() {
return '/api/data';
},
fetch() {
@wearhere
wearhere / main.js
Created Dec 3, 2017
Minimal Babel setup for use with React "hello world". External dependencies purposefully not handled—see https://mixmax.com/blog/rollup-externals for solutions.
View main.js
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
@wearhere
wearhere / actual.js
Last active Jul 28, 2017
Draft of module for adding custom helpers as well as a bind operator that caches. Solution for https://github.com/tc39/proposal-bind-operator/issues/46.
View actual.js
var f = ctx::ns.obj.func;
var g = ::ns.obj.func;
var h = new X::y;
@wearhere
wearhere / promisify.js
Created Mar 21, 2017
Simple promisify.
View promisify.js
function promisify(fn) {
return function(...args) {
return new Promise((resolve, reject) => {
fn.call(this, ...args, (err, res) => {
if (err) reject(err);
else resolve(res);
});
});
};
};
@wearhere
wearhere / test.js
Last active Jul 31, 2020
Using async/await with Bluebird in Node 7.6.0.
View test.js
/* eslint no-console: false */
const bluebird = require('bluebird');
function isBluebirdPromise(promise) {
return promise.constructor === bluebird;
}
function respond() {
return new bluebird((resolve) => {
setTimeout(() => resolve('hi'), 2000);
@wearhere
wearhere / link.css
Created Mar 1, 2017
Mostly put's GitHub's link color to back to how it was before 03.01.2017, i.e. not stabbing your eyes. Credit to https://userstyles.org/styles/139584/github-return-link-color. Load using a Chrome extension like Stylebot.
View link.css
@wearhere
wearhere / unstick.fish
Last active Feb 10, 2017
Shell functions for killing rogue servers. Assumes that touching `src/server/router.js` will restart the server.
View unstick.fish
# Put this in ~/.config/fish/functions/.
function unstick
kill -9 (lsof -ti :$argv[1]); and touch src/server/router.js
end