This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
ARRAY = (1..10).to_a | |
Benchmark.ips do |x| | |
x.report('each') { sum = 0; ARRAY.each { |n| sum += n }; sum } | |
x.report('reduce') { ARRAY.reduce(0, :+) } | |
end | |
Calculating ------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def honorific(klass): | |
class HonorificClass(klass): | |
def full_name(self): | |
return 'Dr. ' + super(HonorificClass, self).full_name() | |
return HonorificClass | |
@honorific | |
class Person(object): | |
def __init__(self, first, last): | |
self.first = first |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function extend(destination, source) { | |
for (var meth in source) { | |
if (source.hasOwnProperty(meth)) { | |
destination[meth] = source[meth]; | |
} | |
} | |
return destination; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function list() { | |
return [].slice.call(arguments, 0); | |
} | |
var list = list(1, 2, 3); // [1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react" | |
import { render } from "react-dom" | |
const mountNode = document.createElement("div") | |
mountNode.id = "container" | |
document.body.appendChild(mountNode) | |
const name = "David" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User { | |
// ... | |
handleChange = e => { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
beforeAll(() => { | |
console.error = error => ( | |
throw new Error(error); | |
); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from "React"; | |
export const Enhance = ComposedComponent => class extends Component { | |
constructor() { | |
super() | |
this.state = { data: null }; | |
} | |
componentDidMount() { | |
this.setState({ data: 'Hello' }); | |
} |