View pandas-json-yaml.py
import yaml
import json
import pandas as pd
df = pd.DataFrame({'one': [1.0, 2.1, 3.2], 'two': [4.3, 5.4, 6.5]})
with open('df.yml', 'w') as file:
yaml.dump({'result': json.loads(df.to_json(orient='records'))}, file, default_flow_style=False)
View one_liners.sh
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
docker rmi $(docker images --format "{{.Repository}}:{{.Tag}}")
# or
docker rmi $(docker images -a -q)
View search-term-parse.js
// Beautiful regex patterns that parse and validate complex querystring parameter of search terms
const searchSyntaxValidationRegex = /^([^:]+:[^:]+(?:,|$))+$/;
const searchSyntaxParseRegex = /([^:]+):\(([^(]+)\)(?:,|$)/g;
/**
* Parses comma separated list of key values into an object.
*
* IN:
* title:(bar bar),content_stripped:(baz, and qux),other:(beep boop)
*
View green-on-selection.js
export default function statelessRadio(React) {
return function StatelessRadio({ baseId, defaultValue, titleText, inputs = [], onSelection = () => {}} = {}) {
function handleSelectionChange(event) {
onSelection(event.target.value);
}
return (
<div id={baseId}>
<p id={`${baseId}__title`}>{titleText}</p>
{inputs.map((inputItem) => {
View on-selection-callback-test.js
// ...
import { spy } from 'sinon';
// ...
it('should take an onSelection callback prop', () => {
// "Arrange"
const props = {
inputs: [{}],
onSelection: spy()
};
View green-default-checked.js
return function StatelessRadio({ baseId, defaultValue, titleText, inputs = [] } = {}) {
// ...
{inputs.map((inputItem) => {
const defaultChecked = (defaultValue === inputItem.value);
return (
<div>
<input type="radio" name={baseId} value={inputItem.value} defaultChecked={defaultChecked} />
<label>{inputItem.label}</label>
</div>
);
View default-value-test.js
it('should check a default input by using the defaultValue prop', () => {
const props = {
defaultValue: 'bravo.value',
inputs: [
{ value: 'alpha.value', label: 'alpha.label' },
{ value: 'bravo.value', label: 'bravo.label' },
{ value: 'charlie.value', label: 'charlie.label' }
]
};
const component = createComponent(props);
View default-inputs-prop.js
export default function statelessRadio(React) {
return function StatelessRadio({ baseId, titleText, inputs = [] } = {}) {
return (
<div id={baseId}>
<p id={`${baseId}__title`}>{titleText}</p>
{inputs.map((inputItem) => {
return (
<div>
<input name={baseId} value={inputItem.value} />
<label>{inputItem.label}</label>
View unexpected-failure.js
export default function statelessRadio(React) {
return function StatelessRadio(props) {
return (
<div id={props.baseId}>
<p id={`${props.baseId}__title`}>{props.titleText}</p>
{props.inputs.map((inputItem) => {
return (
<div>
<input name={props.baseId} value={inputItem.value} />
<label>{inputItem.label}</label>
View create-component-helper.js
// ...
function createComponent(customProps = {}) {
const props = Object.assign({ baseId: 'test-baseId' }, customProps);
const StatelessRadio = statelessRadio(React);
return <StatelessRadio {...props} />;
}
describe('statelessRadio', () => {
// ...