This is a collection of information on PostgreSQL and PostGIS for what I tend to use most often.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| enumerate <- function(X, FUN, ...) { | |
| result <- vector("list", length(X)) | |
| for (i in seq_along(result)) { | |
| tmp <- FUN(X[[i]], i, ...) | |
| if (is.null(tmp)) | |
| result[i] <- list(NULL) | |
| else | |
| result[[i]] <- tmp | |
| } | |
| result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #linux commands basics | |
| #http://software-carpentry.org/v5/novice/shell/index.html | |
| # practise, practise, practise, google, google, google and you will get it :) | |
| pwd # print working directory | |
| cd # change directory | |
| sudo # super user privilege | |
| chmod 775 # change the privileges http://en.wikipedia.org/wiki/Chmod | |
| git clone # version control! get to know git and github! http://git-scm.com/ | |
| sudo bash # bad habit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| `derivSimulCI` <- function(mod, n = 200, eps = 1e-7, newdata, term, | |
| samples = 10000) { | |
| stopifnot(require("MASS")) | |
| if(inherits(mod, "gamm")) | |
| mod <- mod$gam | |
| m.terms <- attr(terms(mod), "term.labels") | |
| if(missing(newdata)) { | |
| newD <- sapply(model.frame(mod)[, m.terms, drop = FALSE], | |
| function(x) seq(min(x), max(x) - (2*eps), length = n)) | |
| names(newD) <- m.terms |
Magic words:
psql -U postgresSome interesting flags (to see all, use -h or --help depending on your psql version):
-E: will describe the underlaying queries of the\commands (cool for learning!)-l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## | |
| # Creates an alias called "git hist" that outputs a nicely formatted git log. | |
| # Usage is just like "git log" | |
| # Examples: | |
| # git hist | |
| # git hist -5 | |
| # git hist <branch_name> | |
| # git hist <tag_name> -10 | |
| ## | |
| git config --global alias.hist "log --pretty=format:'%C(yellow)[%ad]%C(reset) %C(green)[%h]%C(reset) | %C(red)%s %C(bold red){{%an}}%C(reset) %C(blue)%d%C(reset)' --graph --date=short" |
This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.
The script is here:
#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require(ggplot2) | |
| set.seed(42) | |
| df <- data.frame(x=1:50, y=rnorm(50, 10, 2), int=rbinom(50,1,0.3)) | |
| ggplot(df, aes(x=x, y=y)) + | |
| geom_ribbon(aes(ymin=0, ymax=y, fill='#1E90FF'), alpha=0.3) + | |
| geom_abline(intercept=10, slope=-0.1 | |
| , aes(colour='Linear')) + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| notify <- function(msg="Operation complete") { | |
| in.osx <- (Sys.info()['sysname'] == "Darwin") | |
| in.rstudio <- (Sys.getenv("RSTUDIO") == "1") | |
| in.rgui <- (Sys.getenv("R_GUI_APP_REVISION") != "") | |
| if (in.rstudio) { # hack to see if running in RStudio | |
| title <- "RStudio" | |
| sender <- activate <- "org.rstudio.RStudio" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # download docx2txt by Sandeep Kumar | |
| wget -O docx2txt.pl http://www.cs.indiana.edu/~kinzler/home/binp/docx2txt | |
| # make a wrapper | |
| echo '#!/bin/bash | |
| docx2txt.pl $1 -' > docx2txt | |
| chmod +x docx2txt | |
| # make sure docx2txt.pl and docx2txt are your current PATH. Here's a guide | |
| http://shapeshed.com/using_custom_shell_scripts_on_osx_or_linux/ |