Skip to content

Instantly share code, notes, and snippets.

View limscoder's full-sized avatar

Dave Thompson limscoder

  • workday
  • Boulder, CO
View GitHub Profile
@limscoder
limscoder / reactD3.js
Last active November 20, 2017 19:21
D3 rendering within a React component.
export default class Hexagons extends Component {
constructor(props) {
super(props);
// initialize array of hexData in state
this.state = { hexData: hexData() };
}
componentDidMount() {
// draw grid of hexagons with D3
@limscoder
limscoder / hexInteraction.js
Last active November 20, 2017 19:24
Responding to D3 user interactions
// toggles the color of a hexagon and all of it's surrounding hexagons.
function toggleHex(target, hex) {
const firstColIdx = target.row % 2 ? 0 : -1;
const secondColIdx = target.row % 2 ? 1 : 0;
const isNeighbor =
(hex.col === target.col && hex.row === target.row) || // target
(hex.row === target.row - 1 && (hex.col === target.col + firstColIdx || hex.col === target.col + secondColIdx)) || // above row
(hex.row === target.row && (hex.col === target.col - 1 || hex.col === target.col + 1)) || // same row
(hex.row === target.row + 1 && (hex.col === target.col + firstColIdx || hex.col === target.col + secondColIdx)); // below row
if (isNeighbor) {
@limscoder
limscoder / props.js
Created November 20, 2017 19:48
Component using props instead of state
type Hexagon = {
active: bool,
col: number,
row: number
};
type Props = {
hexData: Array<Hexagon>,
onClick: (Array<Hexagon>) => void
};
@limscoder
limscoder / dep.yml
Last active January 12, 2018 18:25
secret initialization via init-container
initContainers:
- name: init-config
image: quay.io/prometheus/alertmanager:v0.12.0
env:
- name: SMTP_AUTH_USERNAME
valueFrom:
secretKeyRef:
name: alert-email-secret
key: username
- name: SMTP_AUTH_PASSWORD
link(scope, elem) {
this.elem = elem;
setTimeout(() => {
this.resizePanel();
this.renderViewBox();
}, 50);
}
resizePanel() {
// set height and width of panel
updateHeight(height = 500 // dynamically calculated height) {
const rowHeight = GRID_CELL_HEIGHT + GRID_CELL_VMARGIN;
this.panel.updateGridPos({
...this.panel.gridPos,
h: Math.ceil(height / rowHeight)
});
this.dashboard.events.emit('row-expanded');
}