Skip to content

Instantly share code, notes, and snippets.

@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
# Created 2016-03-04 Fri 20:20
#+TITLE: R
#+AUTHOR: Ross Donaldson
* Object Oriented, Functional, and Imperative Programming
Right OK: what are these three things? What do they do and how are they
different?
@naupaka
naupaka / reimbursement-template.org
Last active September 4, 2015 17:34
Org-mode reimbursement template for emacs. If you have org-mode installed, C-c C-c on the formula updates the table calculation to sum the expenses column. C-c C-e l o to generate the TeX and pdf and open it in your pdf viewer app.

Reimbursement Request

Expenses (receipts or other documentation attached):

Cost ($)Item(s)

Starting at the beginning:

Let's just assume you're using an Ubuntu-ish distro of Linux. In some ways that makes this a little more complicated, but on the other hand, it lets me assume you have experience with other package managers. So the big thing here is that conda is it's own little scientific apt-get (python packages, GIS tools, R + R packages, gcc, etc) that goes off and builds sandboxes contained in individual rooms. Then there's pip. Pip is specifically for python packages only and in my opinion, should only be used when the conda package isn't available.

Back to conda: conda is a package manager that depends on python, but is not per se an installation of python. So:

@jennybc
jennybc / 2014-08-22_rbind-and-store-as-var.Rmd
Last active August 8, 2016 03:26
Row bind a list of data.frames with a key
---
title: "Row bind a list of data.frames with a key"
author: "Jenny Bryan"
date: "22 August, 2014"
output:
html_document:
keep_md: TRUE
---
I posed a question on Twitter (click to see the figure!):
@aammd
aammd / ListToDf.md
Last active March 26, 2024 23:31
turning a named list into a dataframe using dplyr

Is there an easy way to convert a named list into a dataframe, preserving the elements of the list in a "list-column"?

    library(dplyr)
    library(magrittr)

    ## make a random matrix
    rand_mat <- function() {
@MrFlick
MrFlick / coalesce.R
Created April 8, 2014 22:59
Coalesce.R: A coalesce function for R (returns first non-NA value from a list of vectors)
coalesce<-function(...) {
x<-lapply(list(...), function(z) {if (is.factor(z)) as.character(z) else z})
m<-is.na(x[[1]])
i<-2
while(any(m) & i<=length(x)) {
if ( length(x[[i]])==length(x[[1]])) {
x[[1]][m]<-x[[i]][m]
} else if (length(x[[i]])==1) {
x[[1]][m]<-x[[i]]
} else {
@jebyrnes
jebyrnes / addZeroes.R
Last active August 29, 2015 13:56
A demonstration of how to add rows with zeroes using melt and dcast. There are other ways, but this is pretty simple.
################################
# Problem: You have a ragged
# data frame where species that have not
# been seen as a site simply don't have a
# line in your data frame. You have a long
# data frame, but you want a long data frame
# where missing species have proper zeroes
#
# Solution: a combination of dcast and melt
# from the reshape2 package
@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

@wch
wch / server.r
Last active September 8, 2023 20:25
Shiny example: dynamic input fields
data_sets <- c("mtcars", "morley", "rock")
shinyServer(function(input, output) {
# Drop-down selection box for which data set
output$choose_dataset <- renderUI({
selectInput("dataset", "Data set", as.list(data_sets))
})
# Check boxes