Skip to content

Instantly share code, notes, and snippets.

@wycats
wycats / errors.md
Last active October 21, 2018 12:04
How I think about error handling in Rust
  • Option: "None is a totally valid result, usually found in data structures"
    • unwrap(): YOLO use in prototyping
    • expect(...): to indicate the reason you believe None is impossible (or a contract violation for the method)
  • Result: 😱 "Errors are unexpected but not bugs; the decision for how to handle them is up to the caller"
    • unwrap(): YOLO "I'm an app and don't know how to handle this error -- I'm fine if the whole process aborts"
    • try! / ?: "Leave the decision about how to handle this error to the caller; they have more information"
    • match / catch: "I'm going to handle the error right here right now"
  • panic!: ☠ "The error is a bug and can't be recovered from. Game over man. Rust is allowed to abort the process if it wants"
poem =
"My honeydew has flown from my hand
And my toast has gone to the
moon.
But when I saw it on television,
Planting our flag on Halley's
comet,
More still did I want to eat it.
"
@wycats
wycats / index.js
Created February 6, 2016 00:57
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var fs = require("fs");
bash-4.3# ./dev-environment.sh
tune2fs 1.42.13 (17-May-2015)
Setting maximal mount count to -1
Setting interval between checks to 0 seconds
Creating journal inode: done
which: no distccd in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
distccd pid 25684 port 9256
WARNING: Image format was not specified for 'toolchain.sqf' and probing guessed raw.
Automatically detecting the format is dangerous for raw images, write operations on block 0 will be restricted.
Specify the 'raw' format explicitly to remove the restrictions.
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
module Mst
def self.included(base)
base.extend(ClassMethods)
end
module ClassMethods
def before(method_name)
m = instance_method(method_name)
define_method method_name do |*args, &block|
@wycats
wycats / getter.js
Last active September 23, 2015 18:15
class Person {
@reader _first, _last;
constructor(first, last) {
this._first = first;
this._last = last;
}
}
class Person {
export default Ember.Controller.extend({
appName:'Ember Twiddle'
});
export default function ifHelper([value]) {
if (value) {
this.yield();
}
}
@wycats
wycats / equivalence.js
Last active August 29, 2015 14:14
Proposal for Stage 0 of a contextual 'super()' operation in ES7
class Parent extends Person {
constructor() {
super(arg1, arg2);
// desugars to
// InitializeThis(<activefunction>.__proto__.[[Construct]]([arg1, arg2], NewTarget);
}
someMethod() {
// these are equivalent