Skip to content

Instantly share code, notes, and snippets.

View stephlocke's full-sized avatar

Steph Locke stephlocke

View GitHub Profile
@stephlocke
stephlocke / sqlbitsRcode.R
Last active July 18, 2023 01:43
Initial R code for looking at sqlbits tracks
# 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 September 10, 2014 09:16
Provides indicative view of what I'm trying to achieve by changing functions and testing the before and after results
# 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 September 17, 2014 18:58
internally used rate function from optiRum::RATE written in C++
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 August 29, 2015 14:09
Overcoming file limitations and frustrations of using Excel & data import wizard
# 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 August 29, 2015 14:13
SQLSaturday Exeter Submissions
# 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 January 13, 2015 10:32
Dynamic named range generator
#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 January 15, 2015 14:25
Iris transformation file
<?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 August 29, 2015 14:13
My abstract template
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 November 15, 2022 05:20
Custom aggregate function for use with Lookup joined datasets in SSRS
'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 August 29, 2015 14:14
Exploring program flow with magrittr
library(data.table)
orig_subset<-function(workingdata){
workingdata[["inputs"]][Species!='virginica']
}
orig_mult<-function(workingdata){
workingdata[["subset"]][,.SD*1.1,by=Species]
}