Skip to content

Instantly share code, notes, and snippets.

View ameliabradley's full-sized avatar

Amelia Bradley ameliabradley

  • Minneapolis, MN
View GitHub Profile
@ameliabradley
ameliabradley / constparse.rs
Last active July 20, 2020 17:48
Parse string to number (usize) in a constant function in Rust
// 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)]
# 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
@ameliabradley
ameliabradley / .do.cfg
Created March 7, 2018 21:44 — forked from alexander-alegre/.do.cfg
Sublime Settings
[
{
"repository": "",
"project": "",
"login": "",
"host": "",
"engine": "http",
"password": "",
"disabled": "remove to enable"
},
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}>
@ameliabradley
ameliabradley / medium-unbound.tsx
Last active January 14, 2018 00:13
Medium - Bound and Unbound Methods
class App extends Component {
constructor() {
super();
this.state = {
clicked: false
};
}
onButtonPress() {
// Will error out if "this" is not accessible

Keybase proof

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:

@ameliabradley
ameliabradley / getcolor.js
Last active January 5, 2017 21:20
Given a hex color, finds the optimal font color (black or white)
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';
}
@ameliabradley
ameliabradley / 0_reuse_code.js
Created November 3, 2016 21:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console