Skip to content

Instantly share code, notes, and snippets.

Avatar

Brian A. Danielak briandk

View GitHub Profile
View renderPropsInReact.jsx
class WrapperComponent extends React.Component {
render() {
const style = { border: "solid 1px " + this.props.color };
return <div style={style}>{this.props.children}</div>;
}
}
class HelloMessage extends React.Component {
render() {
var Wrapper = this.props.wrapper;
@briandk
briandk / one-liners.fish
Created Apr 23, 2018
Shell one-liner commands
View one-liners.fish
# Remove untagged docker images
docker rmi (docker images | awk '/<none>/ {print $3}')
@briandk
briandk / TypeScriptExamples.md
Last active Jul 19, 2018
Example functions (and arrow functions) in Typescript with target `es2017`
View TypeScriptExamples.md

Defining an Object Type

const myObject: { [key: string]: string } = {foo: 'bar'}

Annotating Function Types

With target=es2017 and TypeScript 2.8

@briandk
briandk / git-shortcuts.sh
Last active Apr 17, 2018
Useful git shortcuts
View git-shortcuts.sh
# via https://stackoverflow.com/questions/7726949/remove-local-branches-no-longer-on-remote#28464339
# prunes tracking branches not on the remote.
git remote prune origin
# lists branches that have been merged into the current branch.
git branch --merged
# deletes branches listed on standard input.
xargs git branch -d
@briandk
briandk / QuillDeltaToString.js
Created Sep 28, 2017
Converting a quill delta into a string
View QuillDeltaToString.js
// Assuming the delta is entirely insert operations,
// this example wouuld convert bolded text to html bolded text.
// The key logic here is mapping over the insert ops,
// then joining the resulting array on the empty string
html = delta.slice(0, 500).ops.map(function(op) {
if (typeof op.insert !== 'string') return '';
let html = op.insert;
if (op.attributes.bold) {
html = '<strong>' + html + '</strong>';
}
@briandk
briandk / extendingClassesInJavaScript.js
Created Jun 30, 2017
Extending classes in Quill to create a Timestamp Class
View extendingClassesInJavaScript.js
const Quill = require('quill');
// https://github.com/quilljs/quill/blob/develop/formats/link.js
const Link = Quill.import('formats/link');
class Timestamp extends Link {
static create(value) {
let node = super.create(value);
value = this.sanitize(value);
node.setAttribute('href', value);
@briandk
briandk / college-majors.ipynb
Created Apr 17, 2017
Beginning analysis of 538's college majors data
View college-majors.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@briandk
briandk / create_and_plot_forest.py
Last active Apr 10, 2017
Basic plotting and forest creation functions for the forest fire model in CMSE 201 Spring 2017
View create_and_plot_forest.py
```python
import matplotlib.pyplot as plt
from matplotlib import colors
import numpy as np
def make_forest( height, width, density ):
'''
This function will take in a width, height, and density specified by the user and use those values
to generate a forest (2-d numpy array) matching those characteristics. A 0 will represent an empty
space, a 1 will represent a tree
@briandk
briandk / generate_package_citations.R
Created Apr 9, 2017
Wil Doane's system for automatically generating bibliography entries for the R packages you're using
View generate_package_citations.R
# Early in the script
pkgs_pre_script <- try(devtools::loaded_packages(), silent = TRUE)
# Late in the script
pkgs_used_during_script <- try(devtools::loaded_packages(), silent = TRUE)
cat("* ")
print(citation(), style="text") # or Bibtex or LaTeX
@briandk
briandk / uninstall-r-on-osx.sh
Created Mar 27, 2017
Completely (or as completely as I can) uninstalling R on OS X
View uninstall-r-on-osx.sh
sudo rm -rf /Library/Frameworks/R.framework \
/Applications/R.app \
/usr/bin/R /usr/bin/Rscript
pkgutil --regexp --forget org\.r-project*