Skip to content

Instantly share code, notes, and snippets.

Ben Gotow bengotow

Block or report user

Report or block bengotow

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bengotow
bengotow / main.js
Created Jul 10, 2019
Mailspring plugin to assign a class to each thread list row
View main.js
// keep in mind this is a plain JavaScript file - the app won't "transpile" it
// in any way (Mailspring used to run Babel when it read plugin source code,
// but it became difficult to package up Babel as part of the application).
// We can still use most ES2016 language features because we use the latest Chrome.
// When you add this file to your theme also be sure to add a `main` entry to the
// package.json file to tell it that it should load this as the entrypoint of your plugin:
//
// {
// "main": "./main",
@bengotow
bengotow / deserialize.js
Created Jan 8, 2018
Slate HTML deserialize with nested block / inline handling
View deserialize.js
const DefaultParse = HtmlSerializer.parseHtml;
HtmlSerializer.parseHtml = html => {
const tree = DefaultParse.apply(HtmlSerializer, [html]);
const collapse = require('collapse-whitespace');
collapse(tree);
// ensure that no DIVs contain both element children and text node children. This is
// not allowed by Slate's core schema: blocks must contain inlines and text OR blocks.
// https://docs.slatejs.org/guides/data-model#documents-and-nodes
const treeWalker = document.createTreeWalker(tree, NodeFilter.SHOW_ELEMENT, {
@bengotow
bengotow / linkify-plugin.js
Last active Jul 7, 2019
A Linkify plugin for DraftJS that creates / syncs entities on the fly
View linkify-plugin.js
import React from 'react';
import { RichUtils, Modifier, EditorState, SelectionState } from 'draft-js';
function isURL(text) {
return text.startsWith('http://'); // insert your favorite library here
}
/*
Function you can call from your toolbar or "link button" to manually linkify
the selected text with an "explicit" flag that prevents autolinking from
changing the URL if the user changes the link text.
@bengotow
bengotow / spdlog-extensions.cpp
Created Aug 30, 2017
SPDLog Sink for "Flush Within Xmsec"
View spdlog-extensions.cpp
/*
The code below shows a custom SPDLog sink that uses a separate thread and a C++0x condition_variable
to ensure that a spdlog::sinks::rotating_file_sink_mt is flushed to disk within a second of a new
log message being emitted. When no messages are arriving, the helper thread has very low wake overhead
and sleeps for 30s.
*/
std::mutex spdFlushMtx;
std::condition_variable spdFlushCV;
int spdUnflushed = 0;
@bengotow
bengotow / Comparison.txt
Created Mar 17, 2016
Comparison of SQL Approaches for Counting Threads
View Comparison.txt
Option A: Two Subqueries
SELECT
`Thread-Category`.`value` as category_id,
COALESCE((SELECT unread FROM `Thread-Counts` WHERE category_id = `Thread-Category`.`value`), 0) + SUM(unread) as unread,
COALESCE((SELECT total FROM `Thread-Counts` WHERE category_id = `Thread-Category`.`value`), 0) + COUNT(*) as total
FROM `Thread`
INNER JOIN `Thread-Category` ON `Thread`.`id` = `Thread-Category`.`id`
WHERE
`Thread`.in_all_mail = 1
View Signature config.cson
*:
signatures:
"<ACCOUNT ID>": "<br>Test User<br>XXX-XXX-XXXX<br>test@example.com"
@bengotow
bengotow / app.js
Created Aug 7, 2015
concurrency - rolling average
View app.js
var Promise = require('bluebird');
var request = Promise.promisify(require('request'));
var fs = require('fs');
global.Nylas = require('nylas').config({
appId: '1',
appSecret: '2',
apiServer: 'https://api.nylas.com'
});
@bengotow
bengotow / pong.rb
Created Aug 22, 2014
Ping back and forth between two email accounts over and over forever using Inbox
View pong.rb
#!/usr/bin/env ruby
require 'inbox'
@inbox_careless = Inbox::API.new('xdfim6g4mbduytzjhn8ud490', '80q785tt4l6qn5g07c5ylwi6a', '<<token 1>>')
@inbox_emoink = Inbox::API.new('xdfim6g4mbduytzjhn8ud490', '80q785tt4l6qn5g07c5ylwi6a', '<<token 2>>')
emoink = @inbox_emoink.namespaces.first
careless = @inbox_careless.namespaces.first
while true do
View gist:131e51f30155efe5bd42
### Keybase proof
I hereby claim:
* I am bengotow on github.
* I am bengotow (https://keybase.io/bengotow) on keybase.
* I have a public key whose fingerprint is 74AB 1024 E78C 6F3A 12F1 D92C C034 F07C CC52 32D1
To claim this, I am signing this object:
@bengotow
bengotow / server.py
Last active Aug 29, 2015
A simple implementation of the authorization flow for Inbox. Presents a sign in page, and then displays the first message from the user's inbox once they've signed in.
View server.py
#!/usr/bin/env python
# NOTE: This sample app does NOT use SSL. Before deploying this code to a
# server environment, you should ENABLE SSL to avoid exposing your API
# access token in plaintext.
# To run this demo app:
# 1. Save this file to your computer as `server.py`
#
# 2. In the Inbox Developer Portal, create a new application. Replace the
You can’t perform that action at this time.