This Gist was automatically created by Carbide, a free online programming environment.
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
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
function getFontColorFromBackgroundColor (bgColor) { | |
if (!bgColor.match(/#[0-9a-z]{6}/i)) { | |
return 'white'; | |
} | |
const [r, g, b] = [1, 3, 5].map((o) => parseInt(bgColor.slice(o, o + 2), 16)); | |
const greyscale = (0.2125 * r) + (0.7154 * g) + (0.0721 * b); | |
return (greyscale > 127) ? 'black' : 'white'; | |
} |
I hereby claim:
- I am leebradley on github.
- I am carelessgenie (https://keybase.io/carelessgenie) on keybase.
- I have a public key ASB7XfbJUZwPr4cNn2Twz692kIKxCLCD3dq1o8qgMgMzMgo
To claim this, I am signing this object:
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
class App extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
clicked: false | |
}; | |
} | |
onButtonPress() { | |
// Will error out if "this" is not accessible |
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
class LoggingButton extends React.Component { | |
// This syntax ensures `this` is bound within handleClick. | |
// Warning: this is *experimental* syntax. | |
handleClick = () => { | |
console.log('this is:', this); | |
} | |
render() { | |
return ( | |
<button onClick={this.handleClick}> |
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
[ | |
{ | |
"repository": "", | |
"project": "", | |
"login": "", | |
"host": "", | |
"engine": "http", | |
"password": "", | |
"disabled": "remove to enable" | |
}, |
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
# Useful helper script to ensure you're always double-checking your commands | |
cat <<EndOfMessage >> ~/.git-sure.sh | |
#!/bin/bash | |
read -r -p "Are you sure? [y/n] " response; | |
if [[ "$response" =~ ^(yes|y)$ ]]; then git $@; fi; | |
EndOfMessage | |
chmod +x ~/.git-sure.sh | |
if [ -f ~/.zshrc ]; then |
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
// Based on Gist by DutchGhost | |
// https://gist.github.com/DutchGhost/d8604a3c796479777fe9f5e25d855cfd | |
// Changes: | |
// - Conditional compilation to support either 64 or 32-bit | |
// - Added panic error message | |
// - Added convenience function parse_unwrap | |
// - Added tests | |
#![feature(const_if_match)] | |
#![feature(const_panic)] |