Skip to content

Instantly share code, notes, and snippets.

View wtfaremyinitials's full-sized avatar

Will Franzen wtfaremyinitials

View GitHub Profile
{
"name": "Spaghett"
}
{
"message": "Hello, world!"
}
let asyncawait = true;
try {
new Function('async function test(){await 1}');
} catch (error) {
asyncawait = false;
}
if (asyncawait)
module.exports = require('./lib/Puppeteer');
else
@wtfaremyinitials
wtfaremyinitials / pouch.js
Last active January 7, 2018 19:50
Meteor-style client-side database + Redux
// Meteor-style client-side database + Redux
// kind of a hack. not idiomatic Redux
// might become an npm module at some point idk
import PouchDB from 'pouchdb'
export function databaseReducer(state = {}, action) {
if (action.type === 'DATABASE_UPDATE') {
return Object.assign({}, state, { [action.db]: action.docs })
}
return state
// http://slides.com/sdrasner/svg-can-do-that#/38
var shape = document.getElementById("shape");
// media query event handler
if (matchMedia) {
var mq = window.matchMedia("(min-width: 500px)");
mq.addListener(WidthChange);
WidthChange(mq);
}
@wtfaremyinitials
wtfaremyinitials / MailURLDropView.swift
Created July 29, 2017 04:23
Accept deep-links to Mail.app messages through macOS drag and drop
// Accept deep-links to Mail.app messages through macOS drag and drop
class MailURLDropView: NSView {
var filePath: String?
required init?(coder: NSCoder) {
super.init(coder: coder)
self.wantsLayer = true
self.layer?.backgroundColor = NSColor.gray.cgColor
$ sqlite3 chat.db '.schema message' | tr ',' '\n'
CREATE TABLE message (ROWID INTEGER PRIMARY KEY AUTOINCREMENT
guid TEXT UNIQUE NOT NULL
text TEXT
replace INTEGER DEFAULT 0
service_center TEXT
handle_id INTEGER DEFAULT 0
subject TEXT
country TEXT
attributedBody BLOB
@wtfaremyinitials
wtfaremyinitials / yr.sh
Last active May 18, 2017 03:53
Alternative to `yarn run` that doesn't spin up a node process
#!/bin/bash
CMD=$(jq -r .scripts.$1 < package.json)
echo -e '\033[37m$ '$CMD'\033[39m'
PATH=$PATH:./node_modules/.bin eval "$CMD"
echo -e '\xe2\x9c\xa8 Done.'
@wtfaremyinitials
wtfaremyinitials / enum_str_repr.rs
Created January 17, 2017 15:30
Rust enum with str representation
macro_rules! enum_with_str_representation {
(enum $enum_name:ident {
$($variant:ident => $nice_name:expr,)+
}) => {
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
enum $enum_name {
$($variant),+
}
impl ::std::fmt::Display for $enum_name {
#[cfg(test)]
mod tests {
fn counter() -> Box<FnMut() -> i32 + 'static> {
let mut b = 0;
let ret = move || { b += 1; b };
Box::new(ret)
}
#[test]