Skip to content

Instantly share code, notes, and snippets.

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*')})
import {
getBasketContents,
getIsAuthenticated,
getIsEligibleForPromo,
} from 'selectors/user'
const mapStateToProps = state => ({
basketContents: getBasketContents(state),
isAuthenticated: getIsAuthenticated(state),
isEligibleForPromo: getIsEligibleForPromo(state),
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)
})
const areStatesEqual = (nextStore, previousStore) => (
nextStore.basketContents === previousStore.basketContents
)
export default connect(mapStateToProps, null, null, { areStatesEqual })(WrappedComponent)
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],
const myReduxStore = Immutable.fromJS({
myNumbers: [1, 2, 3]
})
const mapStateToProps = state => ({
numbers: state.myNumbers.toJS()
})
export default connect(mapStateToProps)(NumbersComponent)
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]
)
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
)
// 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)
import produce from 'immer'
const initialState = {
todos: {
'a': { id: 'a', description: '...', isComplete: false },
'b': { id: 'b', description: '...', isComplete: false }
}
}
const reducer = (state, action) => (