Skip to content

Instantly share code, notes, and snippets.

Avatar

Steph Locke stephlocke

View GitHub Profile
@stephlocke
stephlocke / sqlbitsRcode.R
Last active Aug 29, 2015
Initial R code for looking at sqlbits tracks
View sqlbitsRcode.R
# get html from url
library(RCurl)
library(XML)
library(data.table)
library(ggplot2)
url <- "http://sqlbits.com/information/PublicSessions.aspx"
src<-getURL(url)
# transform html
@stephlocke
stephlocke / FunctionComparison
Created Sep 10, 2014
Provides indicative view of what I'm trying to achieve by changing functions and testing the before and after results
View FunctionComparison
# Example functions that would be in seperate files in the R directory of the package
simpleFn1 <- function(a){
myConst <- 10
a*myConst
}
simpleFn2 <- function(a){
myConst <- 5
a/myConst
}
@stephlocke
stephlocke / C++rate
Created Sep 17, 2014
internally used rate function from optiRum::RATE written in C++
View C++rate
library(Rcpp)
cppFunction('double rate(double nper, double pmt, double pv){
float rate1 = 0.01 ;
float rate2 = 0.05 ;
float newrate = 0 ;
int n = 10;
for (int i = 0; i < n; ++i) {
double pv1 = floor((-pmt/rate1 * (1 - 1/pow((1 + rate1),nper)))*100+0.5)/100 - pv ;
double pv2 = floor((-pmt/rate2 * (1 - 1/pow((1 + rate2),nper)))*100+0.5)/100 - pv ;
if (pv1 != pv2) {
@stephlocke
stephlocke / postcodetrim
Last active Aug 29, 2015
Overcoming file limitations and frustrations of using Excel & data import wizard
View postcodetrim
# Source of origpostcodedata data: https://geoportal.statistics.gov.uk/geoportal/catalog/search/resource/details.page?uuid=%7BD14C75CE-95C6-4E9F-8753-ECDD88BC2B7D%7D
# Source of postcodefiles data:https://www.ordnancesurvey.co.uk/opendatadownload/products.html
library(foreach)
library(data.table)
setwd("~")
postcodefiles<-dir("../Downloads/codepo_gb/Data//CSV/",full.names = TRUE)
# Slim load of 2.5m records into memory with f(ast)Read function
origpostcodedata<-fread("../Downloads/ONSPD_MAY_2013_csv/Data//ONSPD_MAY_2013_UK_O.csv",
select=c("pcd","pcd2","pcds","dointr",
@stephlocke
stephlocke / ExeterCode.R
Last active Aug 29, 2015
SQLSaturday Exeter Submissions
View ExeterCode.R
# This script will work for any SQL Saturday where schedule has not been confirmed (not tested on others!) just change the URL
library(rvest)
library(data.table)
library(ggplot2)
#wordcloud only required packages
library(wordcloud)
library(tm)
library(foreach)
@stephlocke
stephlocke / DNRvba
Created Jan 13, 2015
Dynamic named range generator
View DNRvba
#Const LateBind = True
Function RegExpSubstitute(ReplaceIn, _
ReplaceWhat As String, ReplaceWith As String)
#If Not LateBind Then
Dim RE As RegExp
Set RE = New RegExp
#Else
Dim RE As Object
Set RE = CreateObject("vbscript.regexp")
#End If
@stephlocke
stephlocke / iris
Created Jan 15, 2015
Iris transformation file
View iris
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Iris</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th style="text-align:left">Sepal.Length</th>
@stephlocke
stephlocke / abstract
Last active Aug 29, 2015
My abstract template
View abstract
Title (max 60 characters)
------
Short description (Quick sell! max 135 characters)
------
Medium description (Sell & outline some content. max 100 words)
------
@stephlocke
stephlocke / AggLookup
Last active Aug 29, 2015
Custom aggregate function for use with Lookup joined datasets in SSRS
View AggLookup
'Allows aggregation of a multilookup cell and can be configured by the user
'To use add this expression to a cell's expression window:
'=code.AggLookup([aggregate choice as string], LookupSet([Local Column], [Match Column], [Return Column], [Dataset as string]))
'
'Available aggregate choices are count, sum, min, max and avg
Function AggLookup(ByVal choice as String, ByVal items as Object)
'Ensure the LookupSet array provided is not empty
If items is Nothing then
Return Nothing
@stephlocke
stephlocke / 1st method
Last active Aug 29, 2015
Exploring program flow with magrittr
View 1st method
library(data.table)
orig_subset<-function(workingdata){
workingdata[["inputs"]][Species!='virginica']
}
orig_mult<-function(workingdata){
workingdata[["subset"]][,.SD*1.1,by=Species]
}