Skip to content

Instantly share code, notes, and snippets.

@mplourde
mplourde / git setup
Created October 1, 2014 20:58
git setup
git config --global http.proxy http://webproxy.phila.gov:8080
git config --global user.name "Firstname Lastname"
git config --global user.email "[email protected]"
git config --global github.user mplourde
git config --global github.token 2332424your3232442
@mplourde
mplourde / git commit steps
Created October 1, 2014 21:26
git commit steps
# after making a series of changes to a file or files, open git bash and use the following commands to commit and sync
# if you've added files to the repository, call 'git add' to add them to the repo
git add /path/to/file
# to commit all your changes, open git bash and change directory to the project folder. Use "pushd //28-arajohnsmit/myproject"
# to change to a directory on someone else's machine. Then enter the following command
git commit -a
# this will open a vim session for you to enter a message about your changes.
# In vim hit the 'i' key to go into insert mode. Type a brief explanation of your changes, then hit esc
@mplourde
mplourde / get current script directory in python
Created November 4, 2014 18:30
get current script directory in python
import os
import sys
def script_dir():
if '__file__' in globals():
return os.path.abspath(os.path.dirname(__file__))
elif sys.argv[0]:
return os.path.abspath(os.path.dirname(sys.argv[0]))
else:
os.path.abspath(os.curdir)
@mplourde
mplourde / Working with layouts in grid
Created December 9, 2014 19:00
Working with layouts in grid
# example1 (using grobs instead of grid.*)
vp <- vpTree(
parent=viewport(layout=grid.layout(nrow=2, ncol=2), name='parent'),
children=vpList(
viewport(layout.pos.row=1, layout.pos.col=1, name='vp1'),
viewport(layout.pos.row=1, layout.pos.col=2, name='vp2')
)
)
pushViewport(vp)
seekViewport('parent')
@mplourde
mplourde / R shiny dynamic outputs
Created December 12, 2014 15:08
R shiny dynamic outputs
ui <- fluidPage(
selectInput('plot_type', 'Plot type', choices=c('point', 'line')),
sliderInput('n', 'N plots', value=1, min=1, max=100),
uiOutput('plots')
)
server <- function(input, output, session) {
output$plots <- renderUI({
ptype <- input$plot_type
@mplourde
mplourde / ggplot top Y-axis
Created February 25, 2015 19:00
ggplot top Y-axis
x <- ggplot(mtcars, aes(x=mpg, y=disp, label=carb)) +
geom_point() +
geom_text(y=Inf, vjust=-.3)
g <- ggplotGrob(x)
g$layout$clip[g$layout$name == "panel"] = "off"
grid.draw(g)
@mplourde
mplourde / gist:f068ee466f5b7af906f8
Last active March 10, 2016 20:27
0 to cluster with notebook
# create instance, create key, install awscli, do awscli configure,
export AWS_ACCESS_KEY_ID=XX
export AWS_SECRET_ACCESS_KEY=XX
export SPARK_HOME=~/spark-1.4.1-bin-hadoop2.6
$SPARK_HOME/ec2/spark-ec2 --key-pair=XX \
--instance-type=m1.large \
--zone us-east-1a \
--identity-file=XX.pem \
@mplourde
mplourde / varsel.R
Created August 22, 2015 23:22
VARselect
vsel <- function (y, lag.max = 10, type = c("const", "trend", "both",
"none"), season = NULL, exogen = NULL)
{
browser()
y <- as.matrix(y)
if (any(is.na(y)))
stop("\nNAs in y.\n")
colnames(y) <- make.names(colnames(y))
K <- ncol(y)
lag.max <- abs(as.integer(lag.max))
get_p_id <- function(p_id, connection) {
sqlQuery(connection, sprintf(
"select p.id 'proposal_id',
pd.id 'proposal_detail_id',
mm.media_month,
b.name 'MVPD',
n.code 'network',
mpi.post_log_recieved_date 'log_date',
pd.start_date 'detail_start',
pd.end_date 'detail_end',
#' @export
add_time_sig <- function(D) {
daypart_cols <- names(D)[grepl('hour_', names(D))]
# NOT CURRENTLY USED
#D <- D %>%
# mutate_(
# week_sig = ~ifelse(get_media_month(log_date) != get_media_month(detail_start),
# get_media_week(detail_end),