Skip to content

Instantly share code, notes, and snippets.

@klikstermkd
klikstermkd / main.py
Created March 22, 2018 10:53
Gracefully kill Python process
from time import sleep
import signal
import sys
def on_stop_handler(signum, frame):
print 'Exiting application...'
sys.exit(0)
@klikstermkd
klikstermkd / player.js
Last active February 8, 2023 12:11
Compare two ways of getting previous state from a React component, when setting its new state.
class Player extends React.Component {
constructor() {
super()
this.state = { score: 0 }
}
increaseScore() {
// 1. Get previous state from this.state
this.setState({ score: this.state.score + 1 })
const arr = [
() => this.setState({moveCircleToMiddle: true}),
1000,
() => this.setState({showGrayCircle: true}),
() => this.setState({showMicrophone: true}),
500,
() => this.setState({moveCircleToTop: true}),
1000,
() => this.setState({pulseGrayCircle: true}),
500,
@klikstermkd
klikstermkd / binaryTree.js
Last active September 14, 2015 15:08
Traverse binary tree using a generator function and an iterator.
class BinaryTree {
constructor(value, left = null, right = null) {
this.value = value;
this.left = left;
this.right = right;
}
* [Symbol.iterator]() {
yield this.value;