Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View martinctc's full-sized avatar
🔥
Packaging up my workflows

Martin Chan martinctc

🔥
Packaging up my workflows
View GitHub Profile
@martinctc
martinctc / DArrayCreator.vb
Created October 23, 2016 21:01
Use this snippet for creating dynamic arrays from rows of data in Excel.
Sub DArrayCreator()
Dim wb As Workbook
Dim ws As Worksheet
Dim i, j, k As Integer
'Use this snippet for creating dynamic arrays from rows of data in Excel.
'Current snippet only allows for two columns of data.
'Enter source workbook location here
'Set wb = Workbooks.Open("C:\Users\Martin\Desktop\ArrayReplacer.xlsx")
Set wb = ActiveWorkbook
@martinctc
martinctc / PivotTableFilterer.vb
Created October 24, 2016 11:57
Filter all pivot tables on the same worksheet
Private Sub CommandButton1_Click()
Dim month_a, month_b, month_c, j As Integer
Dim currentm, defaultm As Long
Dim pvt As PivotTable
Dim coll As Collection
Dim PivotRefs, i As Variant
Application.ScreenUpdating = False
@martinctc
martinctc / check_update.R
Created November 5, 2016 17:15
Check and Update R
# installing/loading the package:
if(!require(installr)) {
install.packages("installr"); require(installr)} #load / install+load installr
# using the package:
updateR() # this will start the updating process of your R installation. It will check for newer versions, and if one is available, will guide you through the decisions you'd need to make.
@martinctc
martinctc / NPS_OE.R
Last active November 15, 2016 17:47
Basic Text Analytics for NPS Open-Ended Responses
library("tm")
library("wordcloud")
library("SnowballC")
library("RColorBrewer")
library("tcltk2")
tk_choose.dir(getwd(),"Choose a suitable folder")
db = file.choose()
data <-read.csv(db,stringsAsFactors = FALSE)
#Create text corpuses for Promoters and Detractors
@martinctc
martinctc / 0_reuse_code.js
Created November 28, 2016 14:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@martinctc
martinctc / tablescraper.r
Last active November 28, 2016 22:59
Scraper for tables on websites
library("rvest")
url <- "https://bank.hangseng.com/1/2/rates/foreign-currency-tt-exchange-rates"
#Replace xpath with bits highlighting whole table on website using 'Inspect'
forex <- url %>%
html() %>%
html_nodes(xpath='//*[@id="viewns_7_0G3UNU10SD0MHTI7BJ91000000_:Display"]/div[1]/table') %>%
html_table()
forex <- forex[[1]]
@martinctc
martinctc / Format differences.vbs
Last active March 15, 2017 09:59
Simple formatter for calculating pairwise % differences on set of tables - not general purpose at all May cut and paste as appropriate to suit purpose
Sub FormatHero()
Dim x As Integer
x = InputBox("Bottom Row number please")
Columns("B:B").Select
ActiveWindow.FreezePanes = True
Columns("D:D").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Columns("G:G").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
circle <- function(xorig, yorig, radius, add, ...){
x <- seq(-radius, radius, length.out = 1000)
y <- sapply(x, function(z) sqrt(radius^2 - z^2))
if(add == TRUE){
lines(xorig + c(x, rev(x)), c(yorig + y, yorig + rev(-y)),
type = "l", ...)
@martinctc
martinctc / Excel scatter points colour.vbs
Created April 25, 2017 10:52
Format all scatter points for Excel chart
Sub FormatScatterPointsColour()
Dim i, j As Integer
j = ActiveChart.SeriesCollection.Count
Debug.Print j
For i = 1 To j
ActiveChart.FullSeriesCollection(i).Format.Fill.Visible = msoTrue
@martinctc
martinctc / SheetsFormatter.vbs
Created April 27, 2017 11:17
Perform the same action on every sheet. Edit the second Subroutine to customise
Sub SheetsFormatter()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
Call action(ws)
Next ws
End Sub
Sub action(ws As Worksheet)