Skip to content

Instantly share code, notes, and snippets.

@focusaurus
focusaurus / package.json
Created October 10, 2016 16:50
atom-format-shell package.json
{
"activationHooks": [
"language-shellscript:grammar-used"
],
"author": "Peter Lyons <pete@peterlyons.com> (http://peterlyons.com)",
"bugs": {
"url": "https://github.com/focusaurus/atom-format-shell/issues"
},
"configSchema": {
"shfmtPath": {
function listUsers (req, callback) {
// use req as immutable input
// standard node error-first callback API
// success value of callback is a response-shaped object with properties: statusCode, headers, body
}
// I haven't built one of these, just riffing.
// Look at clojure and other functional languages for examples that might
// have reasonable counterparts in "functional-light" JS
// Thinking more along the lines of react/redux reducer style
@focusaurus
focusaurus / promises-are-always-async.js
Created January 29, 2016 16:52
Promises are always async
Promise.resolve('foo').then(console.log)
console.log('bar')
// outputs:
// bar
// foo
@focusaurus
focusaurus / gist:6905035
Last active December 25, 2015 02:49
helper function to reduce mongoose/REST boilerplate. Could also monkey patch into OutgoingMessage.prototype perhaps.
function oopsAPI(res, error, model) {
if (error) {
logger.error('Unexpected mongoose error during API query', error);
res.status(500).send(error);
return true;
}
if (!model) {
res.status(404).send();
return true;
}
@focusaurus
focusaurus / .zshrc
Created July 31, 2013 03:59
There's got to be something alongs these lines that actually works...the snippet below does not work.
alias screenunlock='defaults write com.apple.screensaver askForPassword 0 && defaults write com.apple.screensaver askForPasswordDelay 0'
alias screenlock='defaults write com.apple.screensaver askForPassword 1 && defaults write com.apple.screensaver askForPasswordDelay 60'
@focusaurus
focusaurus / emitter_demo.js
Created December 6, 2012 20:30
Emit events directly from a node module while also exporting functions
var emitterModule = require('./emitter_module');
emitterModule.on("e1", function () {
console.log("emitterModule.e1 handler invoked", arguments);
});
emitterModule.func1();
@focusaurus
focusaurus / prefs.sh
Created December 4, 2012 16:55
How I keep OSX plist prefs in my dotfiles repo
#Export like this: prefs export iterm
#import like this: prefs import iterm
prefs() {
local OP="${1}"
shift
case "${OP}" in
export|import);
;;
*)
@focusaurus
focusaurus / ncsend.sh
Created October 17, 2012 19:05
Transfer clipboard text from one mac to another via netcat
NCSEND_PORT=6666
ncsend() {
local DEST_HOST="${1-smair}"
pbpaste | nc "${DEST_HOST}" "${NCSEND_PORT}"
}
ncreceive() {
while true
do
nc -l "${NCSEND_PORT}" | tee /dev/tty | pbcopy
@focusaurus
focusaurus / gist:3717688
Created September 13, 2012 21:12
Make backbone.js friendly for use with async.js
//Note, works with either Backbone.Model or Backbone.Collection
//Returns a function that will fetch the provided model and works with
//async's callback API
function asyncFetch(model) {
return function (callback) {
model.fetch({
success: function (model) {callback(null, model);},
error: function (model, response) {callback(response);}
});
};
@focusaurus
focusaurus / gist:3165384
Created July 23, 2012 18:50
Syntax for comments/docs vs. disabling code blocks
So the question was: should programming languages use a different syntax (or character) for comments intended to be read by developer vs comments whose purpose is to disable code. For example, in my mind, these two scenarios are semantically entirely different intents:
# Add 2 px to account for border
width += 2
vs ......
#def someFunc():
# pass