This file contains 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 requests | |
import re | |
from bs4 import BeautifulSoup as bs | |
def test_urls_on_page(initial_page_url): | |
r = requests.get(initial_page_url) | |
assert r.status_code == 200 | |
content = r.content | |
html_soup = bs(content, "html.parser") | |
urls_found = html_soup.find_all("a", {"href": re.compile('http*')}) |
This file contains 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 { | |
getBasketContents, | |
getIsAuthenticated, | |
getIsEligibleForPromo, | |
} from 'selectors/user' | |
const mapStateToProps = state => ({ | |
basketContents: getBasketContents(state), | |
isAuthenticated: getIsAuthenticated(state), | |
isEligibleForPromo: getIsEligibleForPromo(state), |
This file contains 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 mapStateToProps = state => ({ | |
basketContent: state.user.basket.filter(item => item.id !== null), | |
authetication: { isAuthenticated: state.user.isAuthenticated, ...state.user.adminRoles }, | |
promoCodes: state.user.promoCodes.slice(0, 1) | |
}) |
This file contains 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 areStatesEqual = (nextStore, previousStore) => ( | |
nextStore.basketContents === previousStore.basketContents | |
) | |
export default connect(mapStateToProps, null, null, { areStatesEqual })(WrappedComponent) |
This file contains 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 { createSelector } from 'reselect' | |
export const getIsAuthenticated = state => state.isAuthenticated | |
export const getIsEligibleForPromo = state => state.isEligibleForPromo | |
const getBasket = state => state.basket | |
const getLatestOrderItems = state => state.orders.latest.items | |
export const getBasketContents = createSelector( | |
[getBasket, getLatestOrderItems], |
This file contains 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 myReduxStore = Immutable.fromJS({ | |
myNumbers: [1, 2, 3] | |
}) | |
const mapStateToProps = state => ({ | |
numbers: state.myNumbers.toJS() | |
}) | |
export default connect(mapStateToProps)(NumbersComponent) |
This file contains 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 { Iterable } from 'immutable' | |
export const toJS = WrappedComponent => wrappedComponentProps => { | |
const KEY = 0 | |
const VALUE = 1 | |
const propsJS = Object.entries(wrappedComponentProps).reduce( | |
(newProps, wrappedComponentProp) => { | |
newProps[wrappedComponentProp[KEY]] = Iterable.isIterable( | |
wrappedComponentProp[VALUE] | |
) |
This file contains 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 getImmutableTodosByCategory = (todos, categoryId) => ( | |
todos.filter(todo => ( | |
todo.get('categories').filter(category => category.get('id') === categoryId).size > 0 | |
) | |
) | |
const getTodosByCategory = (todos, categoryId) => ( | |
todos.filter(todo => ( | |
todo.categories.filter(category => category.id === categoryId).length > 0 | |
) |
This file contains 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
// Immutable() when using seamless-immutable; Immutable.fromJS() when using ImmutableJS | |
const initialState = Immutable({ | |
todos: { | |
'a': { id: 'a', description: '...', isComplete: false }, | |
'b': { id: 'b', description: '...', isComplete: false } | |
} | |
}) | |
const reducer = (state, action) => ( | |
state.setIn(['todos', action.todoId, 'isComplete'], action.payload) |
This file contains 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 produce from 'immer' | |
const initialState = { | |
todos: { | |
'a': { id: 'a', description: '...', isComplete: false }, | |
'b': { id: 'b', description: '...', isComplete: false } | |
} | |
} | |
const reducer = (state, action) => ( |
OlderNewer