Skip to content

Instantly share code, notes, and snippets.

@multidis
multidis / archives_misc.sh
Created February 9, 2014 21:48
Misc commands dealing with archives.
## compress a directory (-c flag creates archive)
tar -zcvf archive.tar.gz dirname
## extract selected directory from a tarball
tar -xzf name.tar.gz dir1/path/dir2
library("ellipse")
## Function to plot colored correlation ellipses
## http://is-r.tumblr.com/post/34352513559/plotting-correlation-ellipses
correlationEllipses <- function(cor){
require(ellipse)
ToRGB <- function(x){rgb(x[1]/255, x[2]/255, x[3]/255)}
C1 <- ToRGB(c(178, 24, 43))
C2 <- ToRGB(c(214, 96, 77))
C3 <- ToRGB(c(244, 165, 130))
@multidis
multidis / 00_julia_ubuntu_setup.sh
Last active August 29, 2015 13:57
Julia language and JuliaStudio on Ubuntu machine. NOTE: using Ubuntu repositories for convenience of update management. Alternatively, there is a nightly build repository on Launchpad as well, and also another option is to git clone from github and build (not doing that here).
## Julia: latest stable release from Launchpad repositories (makes updates easier)
## https://github.com/forio/julia-studio/blob/master/linux-build.md
## https://github.com/JuliaLang/julia/blob/master/.travis.yml
sudo apt-get install zlib1g-dev
sudo apt-get install patchelf gfortran llvm-3.3-dev libsuitesparse-dev libncurses5-dev libopenblas-dev liblapack-dev libarpack2-dev libfftw3-dev libgmp-dev libpcre3-dev libunwind7-dev libreadline-dev libdouble-conversion-dev libopenlibm-dev librmath-dev libmpfr-dev
sudo add-apt-repository ppa:staticfloat/juliareleases
sudo add-apt-repository ppa:staticfloat/julia-deps
sudo apt-get update
sudo apt-get install julia
@multidis
multidis / 00_IPython_IJulia_setup.sh
Last active August 29, 2015 13:57
Scientific computing tools along with IPython and IJulia: setup on Ubuntu machine.
## numpy, scipy, etc.
sudo apt-get install libblas-dev liblapack-dev gfortran
sudo apt-get install python-numpy
sudo apt-get install python-scipy
sudo apt-get install python-matplotlib python-pandas python-sympy python-nose
## IPython notebook: use up-to-date repository
sudo add-apt-repository ppa:jtaylor/ipython
sudo apt-get update
sudo apt-get install ipython ipython-notebook ipython-qtconsole
@multidis
multidis / julia_basics.jl
Last active August 29, 2015 13:58
Julia language basic elements and aspects to keep in mind (from a MATLAB and R user perspective).
# mutating functions (modify arguments passed to them): end with ! (e.g. push! below)
# arguments are passed by reference
# just as e.g. mutable lists in Python, arrays are assigned by reference
# CAUTION here as in Python
A = zeros(2,3);
B = A;
# to avoid that use copying as in Python
C = A[:,:];
A[2,3] = 5;
@multidis
multidis / ts_from_date_dataframe.r
Created April 22, 2014 19:47
Time series object from dataframe with date-class column: via zoo-class.
library(zoo)
## as time series object
fx.zoo <- zoo(x=fxsum[,-1], order.by=fxsum$Date)
head(fx.zoo)
fx.ts <- as.ts(fx.zoo)
head(fx.ts)
plot(fx.ts)
@multidis
multidis / 10_web_json.r
Created May 21, 2014 12:07
Query web address and get json or csv data in R.
library(RJSONIO)
## url <- "http://www....."
dat.ls <- fromJSON(url)[[1]] ## verify list structure - element edit as needed
dat.df <- data.frame(do.call(rbind, dat.ls))
@multidis
multidis / docs_publ_tools_ubuntu_install.sh
Last active August 29, 2015 14:06
Tools for creating documentation: LaTeX, pandoc, Jekyll and related; setup for Ubuntu 12.04.
## Jekyll: first setup ruby, gem (see ubuntu workstation setup notes);
## also need Javascript runtime: Node.js works
sudo apt-get install nodejs
sudo gem install json
sudo gem install rdoc
sudo gem install pygments.rb
sudo gem install jekyll
## LaTeX
sudo apt-get install texlive-full
@multidis
multidis / julia_LightTable_Juno.md
Last active August 29, 2015 14:07
LightTable IDE for Julia language with JunoLT plugin. Gadfly graphics built-in! Ubuntu 12.04 and 14.04 setup.

Simplified setup (14.04)

Simply download the complete 64 bit Juno bundle and run the executable after unpacking.

Previously used procedure (12.04)

  1. LightTable https://github.com/LightTable/LightTable download Linux 64bit here, unpack and run LightTable bash script
  2. In Julia console: Pkg.add("Jewel"), Pkg.add("Gadfly"), Pkg.update()
  3. Proceed with Juno plugin installation instructions
@multidis
multidis / 00_julia_TDD_workflow.md
Last active August 29, 2015 14:07
TDD workflow in Julia language (NOTE: mostly personal preferences).

Structure, naming, setup

In the project directory, open in LightTable:

  • ModuleName.jl with functions under development (Capitalize jl-file names containing modules, match file and module names)
  • usingfile.jl that does include("ModuleName.jl") (which allows reloading without Julia restart, see FAQ)

In the ./test/ sub-directory, put the file with FactCheck tests for ModuleName functions: collect all tests into one file named modulename.jl, i.e. the same as source but without capitalization and residing in the testing sub-directory. Open it in LightTable as well.

Test-driven development steps