Skip to content

Instantly share code, notes, and snippets.

Peter Lyons focusaurus

Block or report user

Report or block focusaurus

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
View promises-are-always-async.js
Promise.resolve('foo').then(console.log)
console.log('bar')
// outputs:
// bar
// foo
@focusaurus
focusaurus / gist:6905035
Last active Dec 25, 2015
helper function to reduce mongoose/REST boilerplate. Could also monkey patch into OutgoingMessage.prototype perhaps.
View gist:6905035
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 Jul 31, 2013
There's got to be something alongs these lines that actually works...the snippet below does not work.
View .zshrc
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 Dec 6, 2012
Emit events directly from a node module while also exporting functions
View emitter_demo.js
var emitterModule = require('./emitter_module');
emitterModule.on("e1", function () {
console.log("emitterModule.e1 handler invoked", arguments);
});
emitterModule.func1();
@focusaurus
focusaurus / prefs.sh
Created Dec 4, 2012
How I keep OSX plist prefs in my dotfiles repo
View prefs.sh
#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 Oct 17, 2012
Transfer clipboard text from one mac to another via netcat
View ncsend.sh
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 Sep 13, 2012
Make backbone.js friendly for use with async.js
View gist:3717688
//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 Jul 23, 2012
Syntax for comments/docs vs. disabling code blocks
View gist:3165384
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
@focusaurus
focusaurus / Model.coffee
Created Jul 19, 2012
Add named get/set methods to backbone models
View Model.coffee
addConvenienceMethods = ->
for prop, value of this.attributes
((prop) ->
#Define a setter/getter function
this[prop] = (newValue...) ->
if newValue.length
this.set prop, newValue[0]
return this
else
return this.get prop
@focusaurus
focusaurus / tipper.js
Created Mar 14, 2012
Clearest example of closures ever?
View tipper.js
var tipper = function (percentage) {
return function tip(total) {
return total + (total * (percentage / 100));
};
};
var generous = tipper(20);
var normal = tipper(18);
var stingy = tipper(8);
You can’t perform that action at this time.