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 CustomersController < ApplicationController | |
| # … | |
| def create | |
| if auto_create_request? | |
| @customer = Customer.auto_create(customer_params) | |
| else | |
| @customer = Customer.register(customer_params) | |
| end | |
| respond_to do |format| |
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
| // Here are objects that provides use case and ports: | |
| import ProcessingCustomerCart from "./ProcessingCustomerCart"; | |
| import RequestingCustomerCare from "./RequestingCustomerCare"; | |
| // Adapters: | |
| import ProductsListUI from "./ProductsListUI"; | |
| import AppRouter from "./AppRouter"; | |
| import ErrorsUI from "./ErrorsUI"; | |
| import CartBackend from "./CartBackend"; | |
| import CustomerCareBackend from "./CustomerCareBackend" |
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
| const ProcessingCustomerPorts = (useCase, userInterface, router, eventBus, errorHandler) => { | |
| // inbound messages - here event bus approach is used. | |
| eventBus.on('addItemToCart', item => { | |
| useCase.addItemToCart(item); | |
| }); | |
| eventBus.on('cartLoaded', items => { | |
| items.forEach(item => { | |
| useCase.addItemToCart(item); | |
| }); |
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
| const MAX_TOTAL_ITEMS_IN_CART = 10; | |
| const ProcessingCustomerCart = ports => { | |
| let cartItems = []; | |
| return { | |
| addItemToCart(item) { | |
| const cartItemsWithAddedItem = cartItems.concat([item]); | |
| if (MAX_TOTAL_ITEMS_IN_CART < cartItemsWithAddedItem.length) { | |
| ports.cartErrorHappened("Too many items in cart. Please proceed to checkout."); |
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
| 1. Download the schema: http://jsonapi.org/schema | |
| Disclaimer: Validation will not yield false negatives, but could yield false positives for the sake of flexibility. | |
| 2. Enter: http://jsonschemalint.com/draft4/# | |
| 3. Paste the schema on the left side, your response on the right side. | |
| You should have your response validated. |
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 ConferenceSerializer < BaseSerializer | |
| extend Forwardable | |
| def_delegators :@url_adapter, :conferences_url, | |
| :conference_url, | |
| :conference_days_url | |
| def initialize(url_adapter) | |
| @url_adapter = url_adapter | |
| end |
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 BaseSerializer | |
| def serialize_relationship(name, collection) | |
| collection.map do |rel| | |
| { id: rel.id, type: name } | |
| end | |
| end | |
| end |
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 fix_similarity_symmetricity(vertices_map): | |
| fixed_records = 0 | |
| unequal_records = 0 | |
| for v1key in vertices_map: | |
| v1 = vertices_map[v1key] | |
| for v1index, v1similar in enumerate(v1['similars']): | |
| v2key, v1v2similar = v1similar | |
| if v2key not in vertices_map: | |
| continue |
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
| view.instance().populateSubnavigation(secondaryURLMapOne); | |
| const secondaryNav = view.find(".navbar-rt-secondary"); | |
| const navItems = secondaryNav.find(NavItem); | |
| assert.equal(1, navItems.length); |
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
| svc = SGDClassifier(loss='squared_hinge', verbose=1, n_jobs=8, n_iter=100) | |
| svc.fit(train_data, train_labels) | |
| predictions = svc.predict(validation_data) | |
| wrong = np.nonzero(validation_labels - predictions)[0].astype(np.float).shape[0] | |
| print (float(wrong) / predictions.shape[0]) |