Skip to content

Instantly share code, notes, and snippets.

View mattpolicastro's full-sized avatar

Matt Policastro mattpolicastro

View GitHub Profile
@mattpolicastro
mattpolicastro / dockswitch.sh
Created August 22, 2022 00:14
Quick script for switching Dock orientation based on a target process running or not. (In this case, Rstudio.)
#!/bin/bash
PROCESS_NAME=RStudio
if pgrep $PROCESS_NAME; then
echo running
defaults write com.apple.dock orientation left
else
echo not running
defaults write com.apple.dock orientation bottom
@mattpolicastro
mattpolicastro / brewfile
Last active August 14, 2017 17:53
Homebrew app manifest.
tap "caskroom/cask"
tap "caskroom/drivers"
tap "caskroom/versions"
tap "homebrew/bundle"
tap "homebrew/core"
tap "homebrew/science"
brew "readline"
brew "python"
brew "ansible"
brew "arp-scan"
################################################################
# This script is a rough hack at the Apriori algorithm for IS 7036, Homework 1, Problem 1.
# The first section uses no validity checking or subsetting which effectively ignores Apriori
# but brute-forces an answer. Following that, there is a semi-validated section which confirms
# the results of the first approach.
#
# Matt Policastro, 2017-01-18 00:21 EST
################################################################
Class Alcohol Malic.acid Ash Alcalinity.of.ash Magnesium Total.phenols Flavanoids Nonflavanoid.phenols Proanthocyanins Color.intensity Hue OD.of.diluted.wines Proline
1 14.23 1.71 2.43 15.6 127 2.8 3.06 0.28 2.29 5.64 1.04 3.92 1065
1 13.2 1.78 2.14 11.2 100 2.65 2.76 0.26 1.28 4.38 1.05 3.4 1050
1 13.16 2.36 2.67 18.6 101 2.8 3.24 0.3 2.81 5.68 1.03 3.17 1185
1 14.37 1.95 2.5 16.8 113 3.85 3.49 0.24 2.18 7.8 0.86 3.45 1480
1 13.24 2.59 2.87 21 118 2.8 2.69 0.39 1.82 4.32 1.04 2.93 735
1 14.2 1.76 2.45 15.2 112 3.27 3.39 0.34 1.97 6.75 1.05 2.85 1450
1 14.39 1.87 2.45 14.6 96 2.5 2.52 0.3 1.98 5.25 1.02 3.58 1290
1 14.06 2.15 2.61 17.6 121 2.6 2.51 0.31 1.25 5.05 1.06 3.58 1295
1 14.83 1.64 2.17 14 97 2.8 2.98 0.29 1.98 5.2 1.08 2.85 1045
@mattpolicastro
mattpolicastro / rpt_converter.R
Created March 17, 2016 22:17
A quick-and-dirty .rpt-to-.csv file converter. No safety for escapes. ¯\_(ツ)_/¯
text <- readLines("file.rpt")
col_lengths <- unlist(lapply(strsplit(text[2], " "), nchar))
new_cols <- list()
for(col in 1:length(col_lengths)) {
current_len <- col_lengths[col]
new_cols[[col]] <- as.character(gsub("^\\s+|\\s+$", "", strtrim(text, current_len)))
text <- substring(text, current_len + 2)
}
@mattpolicastro
mattpolicastro / pre-commit
Last active October 20, 2015 20:32
Pre-commit git hook to run `lintr` on R files as they are committed, and block commit if `lintr` finds problems. Inspired by: https://gist.github.com/geuis/1489bbd1a8e47e86db38
#!/bin/sh
staged=$(git diff --staged --name-only | grep ".R$")
if [ "$staged" = '' ]; then
printf "\e[0;32mDidn't find any staged R files to lint.\n\e[0m"
exit 0
fi
printf "\e[0;32mLinting staged R files...\n\e[0m"
linter="
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@mattpolicastro
mattpolicastro / regexLookup.R
Created July 9, 2015 23:08
Regex-ified Lookup Table in R
test <- data.frame(
url = c(
'google.com/testing/duck',
'google.com/testing/dog',
'google.com/testing/cat',
'google.com/evaluating/duck',
'google.com/evaluating/dog',
'google.com/evaluating/cat',
'google.com/analyzing/duck',
'google.com/analyzing/dog',
@mattpolicastro
mattpolicastro / blindsControlFlow.js
Last active August 29, 2015 14:21
Window Blinds Control Flow
var raspi = require('raspi-io');
var five = require('johnny-five');
var board = new five.Board({
io: new raspi()
});
board.on('ready', function(){
var stopButton = new five.Button('GPIO22');
var controlButton = new five.Button('GPIO17');

Keybase proof

I hereby claim:

  • I am mattpolicastro on github.
  • I am mattpolicastro (https://keybase.io/mattpolicastro) on keybase.
  • I have a public key whose fingerprint is 86BE D49A 8860 5877 179F 76C3 665B 63C7 E280 3D4C

To claim this, I am signing this object: