Skip to content

Instantly share code, notes, and snippets.

View nistara's full-sized avatar

Nistara Randhawa nistara

View GitHub Profile
@nistara
nistara / fix_notes.applescript
Created November 27, 2018 00:16 — forked from derickfay/fix_notes.applescript
Change Keynote Presenter Notes Font and Size for All Slides
tell application "Keynote"
tell document 1
set theSlides to slides
repeat with s in the slides
tell presenter notes of s
set font to "Helvetica"
set size to 24
end tell
end repeat
end tell
## GOAL:
## re-create a figure similar to Fig. 2 in Wilson et al. (2018),
## Nature 554: 183-188. Available from:
## https://www.nature.com/articles/nature25479#s1
##
## combines a boxplot (or violin) with the raw data, by splitting each
## category location in two (box on left, raw data on right)
# initial set-up ----------------------------------------------------------
@nistara
nistara / migrate_postgresql_database.md
Created May 22, 2017 19:21 — forked from olivierlacan/migrate_postgresql_database.md
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

# Download elevation tif from eg http://www.eea.europa.eu/data-and-maps/data/digital-elevation-model-of-europe
# First, convert elevation tif to a space delimited xyz (lng lat elevation) file
# $ gdal_translate -of XYZ elevation3x3.tif /tmp/file.xyz
df <- read_delim('/tmp/file.xyz', delim=' ', col_names=FALSE)
df %>%
mutate(X3 = na_if(X3, 0)) %>%
ggplot(aes(X1, -X2 + 20 * X3/max(X3, na.rm=TRUE), group=X2)) +
geom_line(size=0.05) +
@nistara
nistara / europe.R
Created April 25, 2017 22:01 — forked from halhen/europe.R
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)
@nistara
nistara / ipython_notebook_in_git.md
Created April 17, 2017 02:20 — forked from pbugnion/ ipython_notebook_in_git.md
Keeping IPython notebooks under Git version control

This gist lets you keep IPython notebooks in git repositories. It tells git to ignore prompt numbers and program outputs when checking that a file has changed.

To use the script, follow the instructions given in the script's docstring.

For further details, read this blogpost.

The procedure outlined here is inspired by this answer on Stack Overflow.

@nistara
nistara / fix-homebrew-npm.md
Created February 21, 2017 14:10 — forked from DanHerbert/fix-homebrew-npm.md
Instructions on how to fix npm if you've installed Node through Homebrew on Mac OS X or Linuxbrew

Fixing npm On Mac OS X for Homebrew Users

Installing node through Homebrew can cause problems with npm for globally installed packages. To fix it quickly, use the solution below. An explanation is also included at the end of this document.

Solution

This solution fixes the error caused by trying to run npm update npm -g. Once you're finished, you also won't need to use sudo to install npm modules globally.

Before you start, make a note of any globally installed npm packages. These instructions will have you remove all of those packages. After you're finished you'll need to re-install them.

@nistara
nistara / logistic_regression.R
Created February 14, 2017 01:03 — forked from mick001/logistic_regression.R
Logistic regression tutorial code. Full article available at http://datascienceplus.com/perform-logistic-regression-in-r/
# Load the raw training data and replace missing values with NA
training.data.raw <- read.csv('train.csv',header=T,na.strings=c(""))
# Output the number of missing values for each column
sapply(training.data.raw,function(x) sum(is.na(x)))
# Quick check for how many different values for each feature
sapply(training.data.raw, function(x) length(unique(x)))
# A visual way to check for missing data
@nistara
nistara / base_r_plotting_tutorial_koontz_d-rug.r
Created April 21, 2016 16:42 — forked from noamross/base_r_plotting_tutorial_koontz_d-rug.r
Back to basics: High quality plots using base R graphics
### Title: Back to basics: High quality plots using base R graphics
### An interactive tutorial for the Davis R Users Group meeting on April 24, 2015
###
### Date created: 20150418
### Last updated: 20150423
###
### Author: Michael Koontz
### Email: [email protected]
### Twitter: @michaeljkoontz
###
require(igraph)
# generate a social graph
node_number = 100
g = barabasi.game(node_number) ; plot(g)
seeds_num = 1
set.seed(2014); diffusers = sample(V(g),seeds_num) ; diffusers
infected =list()
infected[[1]]= diffusers