Skip to content

Instantly share code, notes, and snippets.

@dmohs
dmohs / error
Last active July 26, 2022 18:10
Executable to run extensionless scripts as a Node module
#!nodem
// vim: set syntax=javascript :
foo // undefined, check reported line number
@dmohs
dmohs / init.lua
Created May 10, 2022 17:22
Hammerspoon function to set default browser
function setDefaultBrowser(appFileName, notify)
local logger = hs.logger.new('defbr', 5)
local app = hs.application.open('com.apple.systempreferences')
local axapp = hs.axuielement.applicationElement(app)
-- Attempt to open the menu until it successfully opens (returns true)
hs.timer.waitUntil(function()
return app:selectMenuItem({'View', 'General'})
end, function()
print('General group opened.')
@dmohs
dmohs / README.adoc
Last active June 5, 2021 00:00
Contract tests for NodeJs streams.

NodeJs Streams Contract Tests

These tests make assertions about some of the details regarding streams when they are connected to files and used within an async/await context. These details help me produce better error messages.

Synopsis

  1. Clone the gist repo.

  2. npm install

  3. npm test

@dmohs
dmohs / boot.sh
Last active March 13, 2020 13:51
Mob programming bootstrap
function pullandextract() {
curl 'https://www.googleapis.com/storage/v1/b/broad-dmohs-public/o/test.tbz?alt=media' \
| tar -xv
}
function tarandpush() {
tar -cy . | \
curl 'https://www.googleapis.com/upload/storage/v1/b/broad-dmohs-public/o?uploadType=media&name=test.tbz' \
--data-binary @-
}
@dmohs
dmohs / hiringprocess.ad
Last active April 4, 2019 19:33
Hiring Process
= Hiring Process
== Candidate Selection
=== Levels
For associate engineers, the candidate must have done something outside of schoolwork. This could be a personal project, a contribution to an open-source project, or an internship or other part-time work.
For software engineers, I expect proficiency in at least one language and one technology. For example, JavaScript and React, Java and Postgres, etc.
= Engineering Philosophy
David Mohs <dmohs@broadinstitute.org>
:toc: macro
== My Core Principles
* Choose technologies where the creators share your engineering philosophy.
* Treat developer usability with the same reverence as product usability.
* Every choice has tradeoffs. If I have a good understanding of the benefits, but not the drawbacks, I'm making a poorly-informed choice.
@dmohs
dmohs / popup.cljs
Last active February 10, 2018 01:18
[:div {:style {:backgroundColor "rgba(210, 210, 210, 0.4)"
:position "absolute" :top 0 :bottom 0 :right 0 :left 0 :zIndex 9999
:display "flex" :justifyContent "center" :alignItems "center"}}
[:div {:style {:backgroundColor "#fff" :padding "2em"}}
[:span {:data-test-id "spinner"
:style {:margin "1em" :whiteSpace "nowrap" :display "inline-block"}}
[:span {:className "fa-spinner fa fa-pulse fa-fw"
:style {:marginRight "0.5rem"}}]
[:span {:data-test-id "spinner-text"} "Please wait..."]]]]
@dmohs
dmohs / index.js
Created September 26, 2017 02:56
Minimal HTTP and Websocket proxy server in Node
const http = require('http');
const httpProxy = require('http-proxy');
const proxy = new httpProxy.createProxyServer({
target: {
host: 'notebook',
port: 8888
}
});
var proxyServer = http.createServer(function (req, res) {
@dmohs
dmohs / cannot_anon.py
Last active July 27, 2017 19:57
Python does not have anonymous procedures.
foo = range(10)
foo.sort(key=lambda x: -x); print 'foo: '+str(foo)
# Suppose something isn't working. Let's try debugging this:
foo.sort(key=lambda x: print 'x: '+str(x); -x) # -> Syntax error
@dmohs
dmohs / do_i_suck_at_scoping.py
Last active July 27, 2017 16:14
Python does not always scope variables correctly.
def do_i_suck_at_scoping():
try:
import gc
y = [x for x in range(5)]
gc.collect() # Just to prove this isn't a garbage collection issue.
x # Should throw a NameError since it is undefined.
assert False, '''Sorry, I don't know how to properly scope variables.'''
except NameError:
pass