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
Dependency injection is effective in these situations: | |
You need to inject configuration data into one or more components. | |
You need to inject the same dependency into multiple components. | |
You need to inject different implementations of the same dependency. | |
You need to inject the same implementation in different configurations. | |
You need some of the services provided by the container. | |
Dependency injection is not effective if: | |
You will never need a different implementation. | |
You will never need a different configuration. | |
If you know you will never change the implementation or configuration of some dependency, there is no benefit in using dependency injection. |
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
// Stateful is a simple implementation of the state pattern for javascript. | |
// | |
// Read more on this design pattern here: | |
// -> http://sourcemaking.com/design_patterns/state | |
// | |
// Initialize Stateful by passing it an object, the name of the initial state | |
// (defaults to "default"), and an optional hash of interfaces that will be | |
// applied for each state. If these interfaces are not passed, they default to | |
// the object's constructor's States property. So, for example: | |
// |
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
var parent = function() { | |
var spawn = require('child_process').spawn; | |
var child = spawn(process.execPath, [process.argv[1], 123]); | |
var stdout = ''; | |
var stderr = ''; | |
child.stdout.on('data', function(buf) { | |
console.log('[STR] stdout "%s"', String(buf)); | |
stdout += buf; | |
}); | |
child.stderr.on('data', function(buf) { |
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
var data = [ | |
{ lastName: 'Bishop', | |
firstName: 'Timothy', | |
gender: 'Male', | |
favoriteColor: 'Yellow', | |
dateOfBirth: '4/23/1967' }, | |
{ lastName: 'Bonk', | |
firstName: 'Radek', | |
middleInitial: 'S', | |
gender: 'Male', |
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
[re-frame.core :as re-frame] | |
[ajax.core :as ajax] | |
[day8.re-frame.http-fx :as reg-fx] | |
(defn newpage [ratom] | |
(println "new page") | |
[:div | |
[:h2 (:api-result ratom)]]) | |
(defn page [ratom] | |
(let [on-click (fn [] (re-frame/dispatch [:handler-with-http app-state]) (reagent/render [newpage app-state] |
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 construct_concept(concept) | |
h = {} | |
c = Hash[*concept.to_a.first] | |
c['paths'] = [[Hash[*concept.to_a.first]]] | |
h[concept['id']] = c | |
h | |
end | |
def parent_child_concepts(concepts) | |
pc = {} |
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
describe Thing do | |
def given_thing_with(options) | |
yield Thing.new do |thing| | |
thing.set_status(options[:status]) | |
end | |
end | |
it "should do something when ok" do | |
given_thing_with(:status => 'ok') do |thing| | |
thing.do_fancy_stuff(1, true, :move => 'left', :obstacles => nil) |
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
(defn accum1 | |
[h pair-arry] | |
(if (contains? h (get pair-arry 1)) | |
(merge-with conj h (hash-map (get pair-arry 1) (get pair-arry 0))) | |
(merge-with conj h (hash-map (get pair-arry 1) [(get pair-arry 0)])))) | |
;; short version of accum | |
(defn accum2 | |
[h pair-arry] | |
(merge-with conj h (hash-map (keyword (get pair-arry 1)) (if (contains? h (keyword (get pair-arry 1))) (get pair-arry 0) [(get pair-arry 0)])))) |
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
--- | |
# ^^^ YAML documents must begin with the document separator "---" | |
# | |
#### Example docblock, I like to put a descriptive comment at the top of my | |
#### playbooks. | |
# | |
# Overview: Playbook to bootstrap a new host for configuration management. | |
# Applies to: production | |
# Description: | |
# Ensures that a host is configured for management with Ansible. |
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
Object.defineProperty(newObject,"name", { | |
value: "Kwame", | |
writable: false, | |
enumerable: true, | |
configurable: true | |
}); | |
var defineProp = function (obj, key, value) { | |
var config = { | |
value: value, |