Skip to content

Instantly share code, notes, and snippets.

View dpastoor's full-sized avatar

Devin Pastoor dpastoor

  • A2-Ai
  • Rockville, MD
View GitHub Profile
@dpastoor
dpastoor / async-await.js
Last active February 7, 2016 07:00
example of async await for reading multiple files
let Promise = require('bluebird');
let fs = Promise.promisifyAll(require('fs')); // adds Async() versions that return promises
let path = require('path');
let _ = require('lodash');
/** Returns the number of files in the given directory. */
let countFiles = async function(dir) {
let files = await fs.readdirAsync(dir);
console.log(files);
let paths = _.map(files, (file) => path.join(dir, file));
@dpastoor
dpastoor / test.json
Created January 22, 2016 17:32
test-data
{
"name": "myCoolPlot",
data: [{x: 1, y:0}, {x: 2, y: 4}]
}
@dpastoor
dpastoor / ref.js
Created January 18, 2016 04:12
getting ref values in react
const AddTodo = ({
onAddClick
}) => {
let input;
return (
<div>
<input ref={node => {
input = node;
}} />
import { domain } from 'config'
export default {
signup: async function (body, cb) {
let response = await fetch(`${domain}:8080/signup`, {
method: `POST`,
headers: {
'Content-Type': `application/json`
},
body: JSON.stringify(body)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import gmail
import yagmail
from hackerutils import get_dotenv
@dpastoor
dpastoor / missing_files.R
Created August 27, 2015 02:00
check for missing column names
gather_idx <- match(gather_cols, names(data))
if (anyNA(gather_idx)) {
missing_cols <- paste(gather_cols[is.na(gather_idx)], collapse = ", ")
stop("Unknown column names: ", missing_cols, call. = FALSE)
}
@dpastoor
dpastoor / folder_comparison.py
Last active August 29, 2015 14:25
compare files between folders python
*******************
import os
file_list1 = []
file_list2 = []
for top, dirs, files in os.walk('./'):
for nm in files:
file_list1.append(nm)
for top, dirs, files in os.walk('/Users/<user>/Music/iTunes/iTunes Media/Music/'):
for nm in files:
file_list2.append(nm)
@dpastoor
dpastoor / gist:eac7bd90fb5ccb50024d
Created April 22, 2015 16:22
R snippets for vim
snippet bp "Expand the shebang and add boilerplate text." b
###############################################################################
# Purpose: ${1:...}
# Author: ${2:...}
# Dependencies: ${3:...}
# Created: `date +%c`
###############################################################################
${0}
endsnippet
if headerrow .== -99
for (i, x) in enumerate(rawdat)
if any([contains(x, s) for s in ["ID", "DV"]])
headerrow = i
break
else
continue
end
end
end
@dpastoor
dpastoor / 2 annotations
Created April 20, 2015 03:58
geom annotate examples for labels in top left corners
annotate("text", x = -Inf, y = Inf, label = paste0("PredP =", 0.57), hjust = -0.1, vjust = 2, size = 5) +
annotate("text", x = -Inf, y = Inf, label = paste0("EqCrit =", 1), hjust = -0.1, vjust = 4, size = 5)