Skip to content

Instantly share code, notes, and snippets.

@dskecse
dskecse / no_double_raisable.rb
Last active November 8, 2015 06:23
Disallowing double-raise
require 'English'
module NoDoubleRaisable
def error_handled!
$ERROR_INFO = nil
end
def raise(*args)
if $ERROR_INFO && args.first != $ERROR_INFO
warn "Double raise at #{caller.first}, aborting."
@dskecse
dskecse / config.ru
Last active December 11, 2015 19:19 — forked from mattetti/rack_example.ru
#########################################
# Very basic rack application showing how to use a router based on the uri
# and how to process requests based on the HTTP method used.
#
# Usage:
# $ rackup config.ru
#
# $ curl -X POST -d 'title=retire&body=I should retire in a nice island' localhost:9292/ideas
# $ curl -X POST -d 'title=ask Satish for a gift&body=Find a way to get Satish to send me a gift' localhost:9292/ideas
# $ curl localhost:9292/ideas
// suggested shell cmd line to run this:
//
// mongo --shell example2.js
//
// Note: the { out : … } parameter is for mongodb 1.8+
db.things.insert( { _id : 1, tags : ['dog', 'cat'] } );
db.things.insert( { _id : 2, tags : ['cat'] } );
db.things.insert( { _id : 3, tags : ['mouse', 'cat', 'dog'] } );
db.things.insert( { _id : 4, tags : [] } );
@dskecse
dskecse / gist:2db57dcba0ff27305daa54eb3f42a6b1
Created May 11, 2016 15:47
extend function (aka augment)
function extend(destination, source) {
for (var meth in source) {
if (source.hasOwnProperty(meth)) {
destination[meth] = source[meth];
}
}
return destination;
}
function list() {
return [].slice.call(arguments, 0);
}
var list = list(1, 2, 3); // [1, 2, 3]
@dskecse
dskecse / sample.js
Created May 19, 2016 14:49
es.next single-argument class method
class User {
// ...
handleChange = e => {
}
}
@dskecse
dskecse / gist:65da8e6ea849aade7c7f39c96adf96f1
Last active May 19, 2016 16:02
stateless React component
import React from "react"
import { render } from "react-dom"
const mountNode = document.createElement("div")
mountNode.id = "container"
document.body.appendChild(mountNode)
const name = "David"
diff --git a/src/components/Article.js b/src/components/Article.js
new file mode 100644
index 0000000..fef5d8a
--- /dev/null
+++ b/src/components/Article.js
@@ -0,0 +1,55 @@
+import React, { PropTypes, Component } from 'react'
+
+// stateful component (w/ state)
+class Article extends Component {
@dskecse
dskecse / propTypesFailure.js
Created May 21, 2016 15:45
make your tests fail on any propTypes errors
beforeAll(() => {
console.error = error => (
throw new Error(error);
);
});
@dskecse
dskecse / Enhance.js
Last active May 28, 2016 12:46 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export const Enhance = ComposedComponent => class extends Component {
constructor() {
super()
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}