Skip to content

Instantly share code, notes, and snippets.

View jeremyyeo's full-sized avatar

Jeremy Yeo jeremyyeo

View GitHub Profile
@jeremyyeo
jeremyyeo / Canonical Redirect
Last active August 29, 2015 14:07
Non-www to www
# Only use either one: non-www to www or www to non-www.
# Redirecting non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirecting www to non-www
RewriteEngine On
RewriteBase /
@jeremyyeo
jeremyyeo / eventrackinguniversalanalytics
Last active August 29, 2015 14:24
Google Universal Analytics Event Tracking Example
<a href="http://www.cmee.co.nz/blog" onClick="ga('send', 'event', 'Contact Form', 'Submit');">Submit Button</a>
// Be sure to add event tracking with category = Contact Form and action = Submit on Google Analytics itself.
@jeremyyeo
jeremyyeo / sqlzoo-answers.sql
Last active March 7, 2020 03:42
Answers for sqlzoo.net tutorials
--http://sqlzoo.net/wiki/SELECT_from_Nobel_Tutorial
--1.
SELECT * FROM nobel WHERE yr = 1950
--2.
SELECT winner FROM nobel WHERE yr = 1962 AND subject = 'Literature'
--3.
SELECT yr, subject FROM nobel WHERE winner = 'Albert Einstein'
x <- 1
for (i in 1:10) {
while (x < 5) {
print(x)
x <- x + i
if (x >= 5) {
break
}
}
if (i >= 5) {
from datetime import datetime, timedelta
first_half = datetime(2016, 11, 18)
second_half = first_half + timedelta(days=1)
print("http://www.facebook.com/download?file={}".format(first_half.strftime("%d-%m-%Y")))
print("E:/Work/file_{}-{}.csv".format(first_half.strftime("%d_%B_%Y"), second_half.strftime("%d_%B_%Y")))
@jeremyyeo
jeremyyeo / R-NAs-to-SQL-NULLs.R
Created November 27, 2016 20:46
For inserting SQL NULLs for variables in R that are NA
require(RODBC)
con <- odbcConnect("dsn")
clean <- function(x) {
if (is.character(x)) {
out <- paste0("'", x, "'")
} else if (is.na(x)) {
out <- "NULL"
} else {
@jeremyyeo
jeremyyeo / knit2pdf.R
Created March 29, 2017 01:54
Knitting a LaTeX file to pdf with R.
knitr::knit2pdf("document.Rtex")
@jeremyyeo
jeremyyeo / plot_config.js
Created April 12, 2017 03:43
Plotly Configuration Options
/*
Copied from https://github.com/plotly/plotly.js/blob/master/src/plot_api/plot_config.js
*/
/**
* Copyright 2012-2017, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
@jeremyyeo
jeremyyeo / get_ga_client_id.js
Created November 12, 2017 20:19
Extracts google analytics client id from _ga cookie
// For use as custom variable in Google Tag Manager.
function() {
try {
var tracker = ga.getAll()[0];
return tracker.get('clientId');
} catch(e) {
return 'N/A';
}
}
# rbind uneven columns
# dummy data
x <- data.frame(name = "alice",
date = 1,
time = 3)
y <- data.frame(name = "bob",
time = 2)
print(x)
print(y)