Skip to content

Instantly share code, notes, and snippets.

View sckott's full-sized avatar
😸

Scott Chamberlain sckott

😸
View GitHub Profile
@max-mapper
max-mapper / bikethefts.topojson
Last active August 29, 2015 14:16
portland bike theft data, 2007-2014 (from https://github.com/oregonian/bikethefts)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@richfitz
richfitz / gist:f949282560ee78c581c3
Last active August 29, 2015 14:16
libjq / R musings

Installation on OSX is currently a PITA if you don't have brew (I don't so that my system stays more similar to users of things, and because I'm a masochist apparently). See this issue as this will be fixed in jq 1.5. So, create an executable shell script sheep in the jq directory containing

#!/bin/sh
echo "baa"

and run YACC=./sheep ./configure - make should run fine after that.

There is a library target for jq, which is great because now we only have to wrap a library, rather than write one. Further, there is a set of Python bindings that we can use as a starting point. The repo is here.

Ruby bindings here

@Stebalien
Stebalien / rust-update-docs-hook
Last active September 21, 2017 22:34
A post-commit hook to update a rust project's gh-pages.
#!/bin/bash
set -e
[[ "$(git symbolic-ref --short HEAD)" == "master" ]] || exit 0
msg() {
echo "> $@"
}
dir="$(pwd)"
tmp="$(mktemp -d)"
#Based on https://github.com/robotlolita/fuck-you
# and https://en.wikipedia.org/wiki/Transformation_of_text
screw_you = function(x){
chars = strsplit(paste0(c(" ", rev(letters), rev(LETTERS), 0, 9:1, "&_?!\".';'"), collapse = ""), "")[[1]]
flipped = strsplit(
" zʎxʍʌnʇsɹbdouɯlʞɾıɥɓɟǝpɔqɐZ⅄XMΛ∩⊥SᴚΌԀONW⅂⋊ſIH⅁ℲƎᗡƆ𐐒∀068ㄥ9ގㄣƐᘔ⇂⅋‾¿¡„,˙'؛",
"")[[1]]
split = strsplit(as.character(substitute(x)), "")[[1]]
## convert back and forth between -180/180 and 0/360 systems
to_lon_360 <- function(lon_180) {
(lon_180 + 360) %% 360
}
to_lon_180 <- function(lon_360) {
((lon_360 + 180) %% 360) - 180
}
@gadenbuie
gadenbuie / getCiteCounts.R
Last active November 1, 2015 05:24
Look up citation counts with rcrossref
getCiteCounts <- function(citekeys, bibtex){
## This function takes a list of citation keys, for ex. from lit review notes
## and a master bibtex file with citekeys and DOIs
## Returns a vector of number of times each article was cited from CrossRef
# Check for and load/install required packages
# --> stringr, rcrossref
if (!'stringr' %in% installed.packages()) install.packages('stringr')
require(stringr, quietly=TRUE)
options(show.signif.stars=FALSE, scipen=10, htmlhelp=TRUE)
options(width=115, repos="http://cran.rstudio.com",
CRAN = "http://cran.rstudio.com",
browserNLdisabled = TRUE,
deparse.max.lines = 2)
if (interactive()) {
suppressMessages(require(devtools))
}
options(error= function() cat(" \\\ \n \\\
@pkoppstein
pkoppstein / combine.jq
Last active August 5, 2021 02:13
a commutative and associative operator for combining two JSON objects
# This gist defines a jq filter for combining two JSON objects by resolving conflicts
# in a way that is appropriate for mapping relational tables to objects.
# "combine" as defined here is both commutative and associative.
# Example:
# { "id": 123, "son": "Son1", "surname": "S"}
# | combine({ "id": 123, "son": "Son2", "surname": "S"})
# produces: { "id": 123, "son": ["Son1",Son2], "surname": "S"}
# Combine two entities in an array-oriented fashion.
@tpoisot
tpoisot / credentials.json
Last active August 29, 2015 14:05
Use with ./get_tweets.py 10 3 test.json openscience opendata
{
"c_key": "ConsumerKey",
"c_sec": "ConsumerSecret",
"t_key": "TokenKey",
"t_sec": "TokenSecret"
}
@noamross
noamross / slowGET.R
Created June 26, 2014 20:15
slowGET - A throttled version of GET
throttle = new.env(parent = emptyenv())
throttle$recent = data.frame(domain = character(), last_visit = character())
#' A throttled version of GET
#'
#' This uses \code{httr::GET} to fetch a web page, but throttles based on domains.
#'
#' \code{slowGET} keeps a list of domains recently accessed by itself in a
#' separate environment. If a domain has been accessed since \code{pause}
#' seconds ago, it will delay execution until that time has passed