Skip to content

Instantly share code, notes, and snippets.

library(sf)
library(ggplot2)
# Data
nc = st_read(system.file("shape/nc.shp", package="sf"))
map = nc
dat = nc[5, ]
# Plot 1
ggplot() +
@noamross
noamross / find_local_tweeps.R
Created August 14, 2017 23:43
A visit to Durham
library(rtweet) #rtweet API creds should already be set up
library(stringi)
library(dplyr)
friends = get_friends(user="noamross")
followers = get_followers("noamross")
tweeps_id = distinct(bind_rows(friends, followers))
tweeps_info = lookup_users(tweeps_id$user_id)
# A regex for a visit to Durham
#' Title
#'
#' @param lonlatheight matrix or data.frame of lon,lat,height values
#' @param rad radius of sphere
#' @param exag exaggeration to apply to height values (added to radius)
#'
#' @return matrix
#' @export
llh2xyz <- function(lonlatheight, rad = 6378137.0, exag = 1) {
cosLat = cos(lonlatheight[,2] * pi / 180.0)
@tpoisot
tpoisot / icanhazpdf.py
Created February 14, 2016 15:53
#ICanHazPDF
#! /usr/bin/env python
import re
import requests
import tempfile
import urllib.request
import random
import sys
import os
@dill
dill / ffmpeg.txt
Last active October 4, 2022 14:44
imagemagick and ffmpeg cheatsheet
# convert mp4 to gif
# converts in.mp4 to out.gif, using 0-20s of the mp4 at resolution 640x480
ffmpeg -ss 00:00:00.000 -i in.mp4 -pix_fmt rgb24 -r 10 -s 640x480 -t 00:00:20.000 out.gif
# alternative mp4 to gif (using imagemagick for the second step)
ffmpeg -i input.mp4 -r 10 output%05d.png
convert output*.png output.gif
# strip audio out of a video file (to aac)
@hadley
hadley / advise.md
Created February 13, 2015 21:32
Advise for teaching an R workshop

I think the two most important messages that people can get from a short course are:

a) the material is important and worthwhile to learn (even if it's challenging), and b) it's possible to learn it!

For those reasons, I usually start by diving as quickly as possible into visualisation. I think it's a bad idea to start by explicitly teaching programming concepts (like data structures), because the pay off isn't obvious. If you start with visualisation, the pay off is really obvious and people are more motivated to push past any initial teething problems. In stat405, I used to start with some very basic templates that got people up and running with scatterplots and histograms - they wouldn't necessary understand the code, but they'd know which bits could be varied for different effects.

Apart from visualisation, I think the two most important topics to cover are tidy data (i.e. http://www.jstatsoft.org/v59/i10/ + tidyr) and data manipulation (dplyr). These are both important for when people go off and apply

The Natural History Museum just came out with a new data portal, including API access via CKAN! Turns out we already have a CKAN R client in development. Examples? I thought you'd never ask:

Installation

Install latest dev version of taxize

@sckott
sckott / erddap_data.md
Last active August 29, 2015 14:01
NOAA ERDDAP data in R

NOAA oceanographic data (ERDDAP) data in R

NOAA ERDDAP server gives access to apparently 802 datasets

Install and load rnoaa

install_github("ropensci/rnoaa")
@mywarr
mywarr / AccessDump.py
Last active April 18, 2024 19:14
use mdbtools to convert .mdb to .sqlite and .csv
#!/usr/bin/env python
#
# AccessDump.py
# A simple script to dump the contents of a Microsoft Access Database.
# It depends upon the mdbtools suite:
# http://sourceforge.net/projects/mdbtools/
import sys, subprocess, os
DATABASE = sys.argv[1]
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active June 16, 2024 13:44
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

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"

Results