Skip to content

Instantly share code, notes, and snippets.

Avatar
🦑
Tappity tap tap

Mark MarkEdmondson1234

🦑
Tappity tap tap
View GitHub Profile
@MarkEdmondson1234
MarkEdmondson1234 / processTweets.r
Last active Aug 29, 2015
A couple of functions used to process Tweets after fetching
View processTweets.r
### tweetdata.r
### Fetch Twitter data and Data Transformations
### Requires you have authenticated in auth.R
### 15th June 2014
### Mark Edmondson @HoloMarkeD
###
### For use with Twitter API, processTweets() takes the df$tweetDF data.frame as input
### And calculates/transforms data for the plots
processTweets <- function(tweetDF,
View plotTweets.R
### plotTweets.r
### Plot out tweets
### Requires you have authenticated in auth.R and processed in tweetdata.R
### 15th June 2014
### Mark Edmondson @HoloMarkeD
###
library(ggplot2)
######################################################################
@MarkEdmondson1234
MarkEdmondson1234 / grabCSVColumn.sh
Created Oct 15, 2014
Input in a csv and a column, get out another file with just that column
View grabCSVColumn.sh
#!/bin/bash
INPUT=
OUTPUT="output.txt"
COL=1
while [ $# -gt 0 ]
do
case "$1" in
-f) INPUT="$2"; shift;;
@MarkEdmondson1234
MarkEdmondson1234 / setup.R
Created Nov 2, 2014
Setup rga() and CausalImpact() packages
View setup.R
## Setup
## below only needed first time if you haven't the packages installed
# install.packages("devtools")
# library(devtools)
# devtools::install_github("google/CausalImpact")
## load the libraries
library(CausalImpact)
library(rga)
@MarkEdmondson1234
MarkEdmondson1234 / getGAdata.R
Last active Aug 29, 2015
Get the GA data for a profile
View getGAdata.R
## pull in the GA data
# get list of profiles
profiles <- ga$getProfiles()
# View the profiles table, and pick the profile you want and put in the profile ID below
UA <- "XXXXXXX"
# choose the dates you want to pull in data for
date_before = "2014-09-01"
@MarkEdmondson1234
MarkEdmondson1234 / causalImpactOnGA.R
Last active Aug 29, 2015
Apply CausalImpact package to the GA output.
View causalImpactOnGA.R
## do the causalImpact
# here the effect took place on the 200th day of the data imported, so the pre.period = 200
# Data is examined and compared in the post perid to day 244
impact <- CausalImpact(data = gadata$visits,
pre.period = c(1,200),
post.period = c(201,244),
model.args = NULL,
bsts.model = NULL,
post.period.response = NULL,
alpha = 0.05)
View landingpageJS.js
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXX-X', 'auto', {'clientId': '{{clientId}}' });
ga('send', 'pageview');
ga('send', 'event','email','visit','email_content')
View homepage.py
class MainPage(webapp2.RequestHandler):
"""Get a URL, POST a GA hit"""
def get(self):
template_values = {}
template = JINJA_ENVIRONMENT.get_template('main.html')
self.response.write(template.render(template_values))
View imageRequest.py
def getUniqueClientId(seed=''):
"""Function to create the cid from the parameter passed in. Change this as needed """
if seed: random.seed(seed)
## make this so its always unique by referring to a set or using md5 or something
theID = str(random.randint(1,9999)).zfill(4) + "-" + str(random.randint(1,9999)).zfill(4) + "-" + str(random.randint(1,9999)).zfill(4) + "-" + str(random.randint(1,9999)).zfill(4)
return theID
class ImageRequest(blobstore_handlers.BlobstoreDownloadHandler):
View landingpage.py
class LandingPage(webapp2.RequestHandler):
"""Example page where content is - utm parameters should be used plus cid which will link the impression and visit """
def get(self):
cid = cgi.escape(self.request.get('cid'))
clientId = getUniqueClientId(cid)
print clientId