Skip to content

Instantly share code, notes, and snippets.

@datalove
datalove / ROracle_OSX.md
Last active December 2, 2017 02:01
ROracle on OS X

Running ROracle on OSX

Installing Oracle Instant Client

Go to http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html and look for something like this:

Instant Client Package - Basic: All files required to run OCI, OCCI, and JDBC-OCI applications Download instantclient-basic-macos.x64-11.2.0.4.0.zip (62,794,903 bytes)

Once the file is downloaded, follow the instructions at the bottom of the download page (reproduced below)

@datalove
datalove / preso.R
Created September 9, 2015 22:54
R preso for WARG
```{r, echo = FALSE}
library(knitr)
library(plyr)
library(data.table)
library(dplyr)
gears <- mtcars$gear
mtcars <- mtcars[,1:6]
mtcars$gear <- gears
@datalove
datalove / xpath_selection.md
Last active August 26, 2015 00:03
XPath to select parent where children meet certain criteria

For the code below, if we want to select records have a field with colour = Red and length > 30...

<root>
<record id="1">
  <field id="colour" value="Red" />
  <field id="size"   value="Small" />
  <field id="length" value=25 />
</record>
@datalove
datalove / vectorised_hash_tables.R
Created August 25, 2015 03:21
Fast lookups using R's evironments, which are implemented using hash tables (vectorised)
# inspired by https://stackoverflow.com/questions/16782518/is-this-a-good-way-to-make-a-multi-dimensional-dictionary-in-r/16782745#16782745
# and http://broadcast.oreilly.com/2010/03/lookup-performance-in-r.html
hash <- function( ) {
new.env( hash = TRUE, parent = emptyenv() )
}
set <- function(key, val, hash) {
invisible(mapply(assign, key, val, MoreArgs = list(envir = hash)))
}
@datalove
datalove / xl_col_to_num.R
Last active August 29, 2015 14:28
R function to convert excel column names ('Q','AD', etc) to numbers
xl_col_to_num <- function(column) {
# calc value for a letter given its position i
# eg for'CZ', C's contrib is 26^(1-1)*3 and Z's contrib is 26^(2-1)*26
calc_pos_val <- function(x,i) 26^(i-1) * which(LETTERS == x)
# for a single column like 'CZ', calc each positional value and sum the total
single_col <- function(x) calc_pos_val %>% mapply(x, rev(seq_along(x)) ) %>% sum()
column %>%
@datalove
datalove / xlsxToR.r
Last active August 29, 2015 14:27 — forked from schaunwheeler/xlsxToR.r
Import an xlsx file into R by parsing the file's XML structure.
# The MIT License (MIT)
#
# Copyright (c) 2012 Schaun Jacob Wheeler
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@datalove
datalove / in_place_sub.R
Last active August 29, 2015 14:25
In-place string substitution in R. Example: s("my name is $x and time is $y")
s <- function(str) {
require(stringr)
require(magrittr)
# helper functions
get_vars <- function(str) str %>% str_extract_all("\\$[a-zA-Z0-9_\\.]+") %>% unlist %>% str_replace_all("\\$","")
eval_var <- function(var) eval(parse(text = var)))
add_token <- function(var) paste0("\\$", var)
@datalove
datalove / caret_nnet_ANN
Last active August 29, 2015 14:23
Basic usage of 'caret' package with artificial neural net from 'nnet' package
#########################
# find and load packages
#########################
install.packages(c("nnet","caret"))
library(caret)
###################
# Build neural net
@datalove
datalove / spark_pi_cluster.md
Last active September 16, 2020 09:49
Getting Spark up and running on RPi

Before starting

  • Download Spark 1.4 to your local machine (laptop, or PC)
  • Go to 192.168.1.1 to get local IPs for newly connected RPis

Configure each Raspberry Pi

Log into the new Raspberry Pi from your machine

  • ssh pi@192.168.1.XXX (default password for pi user is raspberry)