Skip to content

Instantly share code, notes, and snippets.

View sboysel's full-sized avatar

Sam Boysel sboysel

View GitHub Profile
@sboysel
sboysel / commandlinefu.jl
Last active August 29, 2015 14:13
Simple commandlinefu.com API functions with Julia
# Quick wrapper for the awesome commandlinefu.com API
# http://www.commandlinefu.com/site/api
using Requests
using JSON
BASE_URL = "http://www.commandlinefu.com/commands/"
function bestfu()
q = BASE_URL * "browse/sort-by-votes/json"
return JSON.parse(IOBuffer(Requests.get(q).data))
# Prepare SpatialPolygonsDataFrame for plotting with ggplot2
# Follows https://github.com/hadley/ggplot2/wiki/plotting-polygon-shapefiles
# Assumes you are in Hadleyverse and already have dplyr loaded.
prepare_spdf <- function(spdf) {
require(dplyr)
reguire(ggplot2)
spdf@data$id <- rownames(spdf@data)
spdf.points <- ggplot2::fortify(spdf, region = "id")
if (sum(is.na(spdf.points$hole))) {
@sboysel
sboysel / load_mnist.R
Last active January 13, 2016 01:34 — forked from brendano/gist:39760
load the MNIST data set in R
# Load the MNIST digit recognition dataset into R
# http://yann.lecun.com/exdb/mnist/
# assume you have all 4 files and gunzip'd them
# creates train$n, train$x, train$y and test$n, test$x, test$y
# e.g. train$x is a 60000 x 784 matrix, each row is one digit (28x28)
# call: show_digit(train$x[5,]) to see a digit.
# brendan o'connor - gist.github.com/39760 - anyall.org
load_mnist <- function(path = "mnist") {
# Usage:
@sboysel
sboysel / sumstats.R
Last active March 4, 2016 19:53
Grouped Summary Statistics
#' Grouped summary statistics
#'
#' Wraps \code{\link{aggregate}} to generate common summary statistics over
#' subsets.
#'
#' @param data A data.frame to be summarized.
#' @param by Grouping variables specified by a formula as used in
#' \code{\link{aggregate}}.
#' @param stats A character vector of statistical functions. Default is c("n",
#' "mean", "sd", "min", "max"). More functions can be added by modifying the
@sboysel
sboysel / spatialutils.R
Created June 7, 2016 01:38
Convenience functions for loading spatial data.
# TODO: (1) What if I want to keep the remote zipfile after downloading? [x]
# (2) Other common formats: - GeoJSON [x]
# - KML [ ]
library(rgdal)
# Functions to check filenames
is_remote <- function(x) grepl("(ht|f)tp(s)?://", x)
is_zip <- function(x) grepl("\\.zip$", basename(x))
is_shp <- function(x) grepl("\\.shp$", basename(x))
is_json <- function(x) grepl("\\.(geo)?json$", basename(x))
@sboysel
sboysel / ggplot2_map.R
Created June 17, 2016 16:01
Notes on mapping sp objects with ggplot2
library(ggplot2)
library(maptools)
library(mapproj)
library(ggthemes)
library(sp)
library(raster)
library(rgeos)
library(RColorBrewer)
# Get administrative boundaries as SpatialPolygonsDataFrame
@sboysel
sboysel / query.sql
Created February 1, 2019 20:15
Most popular Stack Overflow tags (Stack Exchange Data Explorer query)
select
num.TagName as Tag,
row_number() over (order by num.Num desc) as TotalRank,
rate.Rate as QuestionsInMay,
num.Num as QuestionsTotal
from
(select count(PostId) as Rate, TagName
from
@sboysel
sboysel / ght-restore-psql
Created February 13, 2019 03:18 — forked from etcwilde/ght-restore-psql
Restore the GHTorrent database to postgres instead of mysql (based on mysql-2017-01-19 image)
#!/usr/bin/env bash
# Evan Wilde <etcwilde@uvic.ca>
# July 20, 2017
# defaults
user="postgres"
passwd=""
host="localhost"
db="ghtorrent"
tmpdir='/tmp'
@sboysel
sboysel / keybase.md
Created December 2, 2019 06:39
keybase.io proof of GitHub identity

Keybase proof

I hereby claim:

  • I am sboysel on github.
  • I am sboysel (https://keybase.io/sboysel) on keybase.
  • I have a public key whose fingerprint is F0BB B0B8 886D 1CDB 392D E755 2E8D EF7C 3554 032D

To claim this, I am signing this object:

@sboysel
sboysel / xtable.decimal.r
Last active November 21, 2020 19:50 — forked from jbryer/xtable.decimal.r
Prints a LaTeX table with numeric columns aligned on their decimal points. This function wraps the xtable and print.xtable functions in the xtable package so that numeric columns are aligned on their decimal place.
#' Prints a LaTeX table with numeric columns aligned on their decimal points.
#'
#' This function wraps the \code{\link{xtable}} and \code{\link{print.xtable}}
#' functions in the \code{xtable} package so that numeric columns are aligned
#' on their decimal place.
#'
#' See \url{http://jason.bryer.org/posts/2013-01-04/xtable_with_aligned_decimals.html}
#' for more information.
#'
#' @author Jason Bryer <jason@@bryer.org>