Skip to content

Instantly share code, notes, and snippets.

View christopherlovell's full-sized avatar
🍊

Chris Lovell christopherlovell

🍊
View GitHub Profile
@christopherlovell
christopherlovell / gist:c2e210b1d8d758a4f0e7
Created May 29, 2015 17:36
powershell pdf/word parser
$pyscript = "C:\Users\324240\Desktop\pdfminer-master\tools\pdf2txt.py"
$input_folder = "C:\Users\324240\Desktop\Markets Surveillance Meetings\"
$output_folder = ($input_folder+"test\")
## Python pdf converter
## Uses the python library here https://github.com/euske/pdfminer/tree/master/tools
#Get-ChildItem $folder -Filter *.pdf | `
#Foreach-Object{
# print ($input_folder+$_.BaseName)
http://regexr.com/3ahpo
@christopherlovell
christopherlovell / gist:d5bc6a9f3f6da06e6580
Created June 15, 2015 20:05
How to... make RMarkdown generated HTML work in the strange_case Jekyll template
  1. copy the HTML to a new markdown script
  2. delete the following line from the <header>
<!--link href="data:text/css,%2F%2A%21%0A%20%2A%20Bootstrap%20v3%2E3%2E1%20%28http%3A%2F%2 .......
.....
.....
.....
...... 21important%7D%7D%40media%20print%7B%2Ehidden%2Dprint%7Bdisplay%3Anone%21important%7D%7D" rel="stylesheet" /-->
To make a function written in Rcpp hidden, add the following 'name; attribute to the export header line with a period prefix
// [[Rcpp::export(name=".ngram_generator")]]
std::vector<std::string> ngram_generator(std::string sentence, unsigned int n){
std::istringstream iss(sentence);
std::vector<std::string> tokens;
std::vector<std::string> bigrams;
std::string str;
copy(std::istream_iterator<std::string>(iss),
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,big,cite,code,del,dfn,em,img,ins,kbd,q,s,samp,small,strike,strong,sub,sup,tt,var,b,u,i,center,dl,dt,dd,ol,ul,li,fieldset,form,label,legend,table,caption,tbody,tfoot,thead,tr,th,td,article,aside,canvas,details,embed,figure,figcaption,footer,header,hgroup,menu,nav,output,ruby,section,summary,time,mark,audio,video
{
border: 0;
font: inherit;
font-size: 100%;
margin: 0;
padding: 0;
vertical-align: baseline;
}
html
@christopherlovell
christopherlovell / places.R
Created August 11, 2015 11:40
Google places API intro
## Google places API script
library(rjson)
postcode = "EC2R8AH"
API_request <- "https://maps.googleapis.com/maps/api/geocode/json?address="
API_request <- paste(API_request,postcode,sep="")
address <- rjson::fromJSON(file=API_request)
@christopherlovell
christopherlovell / miniCRANdemo.R
Created August 12, 2015 18:27
miniCRAN package dependencies
setwd("C:/DJB/Data Sandpit/miniCRAN")
library(miniCRAN)
options(repos = c(CRAN = "http://cran.at.r-project.org/"))
pkgs <- c("data.table", "dplyr", "ggplot2","shiny", "shinydashboard", "shinyBS","reshape2","png","shinyTree","igraph","tm","caret")
pkgDep(pkgs, enhances=TRUE)
p <- makeDepGraph(pkgs, enhances = TRUE)
@christopherlovell
christopherlovell / ngrams.R
Created August 12, 2015 18:27
Google ngrams demo
if(!require(rvest)){
install.packages("rvest")
}
library(stringr)
Sys.setenv(http_proxy="http.boe.bankofengland.co.uk:8080");
term = 'Germany';
start = 1800;
end = 2000;
`chartSeries3d0` <-
function(Z, theta=30, r=10, col=c("yellow","red"), smoother=1, border=NA, shade=.3, ltheta=20, x.cex=.75, srt=0,...) {
cnames <- colnames(Z)
yred <- colorRampPalette(col)
par(mar=c(3,1,1,1))
time.axis <- axTicksByTime(Z)
if(smoother > 1)
Z <- as.xts(t(apply(Z,1,function(x) spline(as.vector(coredata(x)), n=smoother*length(x))$y)))
pm <- persp(z=Z,
x=(1:NROW(Z))/length(time.axis),
@christopherlovell
christopherlovell / app.R
Last active September 7, 2023 11:51
Shiny dynamic UI elements
library(shiny)
server <- function(input, output) {
output$input_ui <- renderUI({
num <- as.integer(input$num)
lapply(1:num, function(i) {
numericInput(paste0("n_input_", i), label = paste0("n_input", i), value = 0)
})
})