Skip to content

Instantly share code, notes, and snippets.

@wearhere
wearhere / Playground.swift
Last active October 4, 2023 17:27
Apply skin tone modifiers to emojis per the Unicode spec.
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 09:45
Trying to figure out how to apply skin tone modifiers to gemoji
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 April 11, 2024 19:47
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.
//
// 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 June 8, 2018 01:15
Making SSE easy
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 December 3, 2017 05:23
Minimal Babel setup for use with React "hello world". External dependencies purposefully not handled—see https://mixmax.com/blog/rollup-externals for solutions.
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<h1>Hello, world!</h1>,
document.getElementById('root')
);
@wearhere
wearhere / actual.js
Last active July 28, 2017 03:45
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.
var f = ctx::ns.obj.func;
var g = ::ns.obj.func;
var h = new X::y;
@wearhere
wearhere / promisify.js
Created March 21, 2017 18:06
Simple promisify.
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 July 31, 2020 01:25
Using async/await with Bluebird in Node 7.6.0.
/* 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 March 1, 2017 19:57
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.
@wearhere
wearhere / unstick.fish
Last active February 10, 2017 01:20
Shell functions for killing rogue servers. Assumes that touching `src/server/router.js` will restart the server.
# Put this in ~/.config/fish/functions/.
function unstick
kill -9 (lsof -ti :$argv[1]); and touch src/server/router.js
end