Skip to content

Instantly share code, notes, and snippets.

@multidis
multidis / BibTexCiteKeyForMarkdown.js
Created November 29, 2013 22:27 — forked from liob/BibTexCiteKeyForMarkdown.js
Pandoc markdown BibTex key export from Zotero Firefox add-on, as described in the [forum](https://forums.zotero.org/discussion/30875/bibtex-key-translator-for-markdown-pandoc/) entry.
{
"translatorID": "7cb70025-a888-4a29-a210-93ec52da40d5",
"translatorType": 3,
"label": "BibTeX key for Markdown",
"creator": "created by liob based on the works of Peter O'Brien, Simon Kornblith and Richard Karnesky",
"target": "bib",
"minVersion": "2.1.9",
"maxVersion": null,
"priority": 200,
"inRepository": true,
@multidis
multidis / zim_wiki.md
Created November 29, 2013 23:05
[Zim wiki](http://zim-wiki.org/) on Ubuntu machine.

Zim wiki setup

Add Ubuntu repository: sudo add-apt-repository ppa:jaap.karssenberg/zim and install zim package.

Settings

  • remember tray icon
  • can enable attachment panel if needed depeonding on a wiki
@multidis
multidis / duplicity_backup_restore.sh
Created November 30, 2013 20:25
Duplicity (incremental backups based on rsync) backup and restore commands. NOTE: Powerful tool for remote backup e.g. with Amazon S3 and encryption; commands below are however mostly about backing up and restoring on locally mounted drives without encryption.
### duplicity command examples
### http://www.nongnu.org/duplicity/duplicity.1.html
## backup home dir to remote drive
## NOTE: can use GUI for that
## list of files backed up on a mounted drive
duplicity list-current-files --no-encryption file:///media/USB300G/full-backup-dir-with-archives > /home/user/restore/list.txt
## NOTE: may run really long and create hundreds of Mb file if a lot was backed up
@multidis
multidis / regex_misc.sh
Created November 30, 2013 23:48
Regex-related commonly used tasks with shell scripting.
## extract part of a string with grep
echo "12 BBQ ,45 rofl, 89 lol"|grep -P '\d+ (?=rofl)' -o
## -P means Perl-style regex, -o means match only not the full line
## extract part of a line from every line in a file $FILE
grep -P 'home.*' -o "$FILE" | while read -r line ; do
echo "$line"
## do something with extracted string
## e.g. capture part of it into another variable
VARNAME=$(echo "$line"|grep -P "$DIR.*" -o)
@multidis
multidis / R_RStudio_ubuntu.sh
Created December 2, 2013 20:13
R and RStudio setup on Ubuntu 12.04.
### R setup from specific CRAN mirror: cran.cnr.berkeley.edu
## make sure backports is checked in software sources/updates tab
## add repository instructions http://cran.r-project.org/bin/linux/ubuntu/README
sudo gedit /etc/apt/sources.list ## or better from GUI-Synaptic to check correct URL
## add:
## deb http://cran.cnr.berkeley.edu/bin/linux/ubuntu precise/
## add secure key required for mirror reporitories
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E084DAB9
@multidis
multidis / wget_flags.sh
Created December 3, 2013 07:38
wget command options for commonly needed operations.
## recursively grab web-directory content
wget -r --no-parent http://mysite.com/dir/
## NOTE: no-parent option to avoid following links that lead higher than the directory we want
@multidis
multidis / R_xml_read_excel.r
Created December 9, 2013 01:51
Reading xml file of Excel shcema `xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml"` using xml-package (Omegahat) functions. NOTE: this is not newer Excel doc format, but older xml. Used as [Surveygizmo](http://www.surveygizmo.com/) export for example.
library(XML)
#file.xml <- # assign it
## list of row-nodes
lsrows <- xmlChildren(xmlRoot(xmlTreeParse(file.xml))[["Worksheet"]][["Table"]])
## row names are lsrows[[1]]
nms.rows <- xmlSApply(lsrows[[1]], xmlValue)
@multidis
multidis / FP_closure.jl
Last active December 30, 2015 20:29
Closure simple example in selected technical computing languages. NOTE: performance checks are recommended, particularly in Julia and Python. In R on the other hand functional programming is nearly-native, and does not seem to slow down already slow code.
power(expon) = x -> x^expon
square = power(2)
square(2)
cube = power(3)
cube(2)
@multidis
multidis / string_split.r
Created December 12, 2013 19:46
String manipulations in R.
## split on any punctuation or space, common in web form submissions/survey text answers
unlist(strsplit(s, split="[[:punct:][:space:]]"))
@multidis
multidis / ggplot_bar_stack.r
Created December 13, 2013 20:59
Bar graphs of counts. Stacked bar charts to compare their factor-fill in ggplot2.
## simplest case of counts-based bar graph
gpb <- ggplot(dfstr, aes(x=factor(age)))
gpb + geom_bar(stat="bin")
## add bar fill by another factor: add fill aes
gpb <- ggplot(dfstr, aes(x=factor(age), fill=factor(gender)))
gpb + geom_bar(stat="bin")
## when bar composition comes from different dataframe columns
gp <- ggplot(dfnum)