Skip to content

Instantly share code, notes, and snippets.

@dracodoc
dracodoc / gg_zoom.R
Last active November 22, 2023 21:02
Launch a Shiny app with your `ggplot2` object, zoom control added: `gg_zoom(g)`
# Launch a Shiny app with your ggplot object, zoom control added: gg_zoom(g)
# Shiny brush event always return numerical values for the zoom box. If the x or y axis is in date, date-time, the zoom box coordinates need to be converted before taken by ggplot.
# https://github.com/hadley/scales/blob/38f81a7b79d98c06edd7d0b624c77b7834db508f/R/trans-date.r
# this will convert date, datetime axes automatically, though it need lubridate to work because the base R equivalent are more cumbersome to use.
library(shiny)
library(ggplot2)
library(lubridate)
ui <- fluidPage(
@dracodoc
dracodoc / clip_generic.R
Last active June 19, 2023 14:24
R function for reading and writing to windows/mac clipboard
#' Read windows/mac clipboard into lines
#'
#' If windows, call \code{utils::readClipboard()}. If mac os, use
#' \code{pipe("pbpaste")}.
#'
#' @return character vector
#' @export
#' @examples
#' clip_read_lines()
clip_read_lines <- function(){
@dracodoc
dracodoc / splitStates.py
Last active November 19, 2015 04:10
python script to split the multiple states loader script generated by PostGIS Tiger Geocoder into separate script for each state
__author__ = 'draco'
# split all states loader script into separate scripts by states.
# replace all the "set TMPDIR=..." line with ":: ---- end state ----\nset TMPDIR=..."
# then delete the first line of ":: ---- end state ----\n"
# modify the base file path and output file folder by your case.
text_file = open("e:\\Data\\all_states.bat","r")
lines = text_file.readlines()
text_file.close()
print len(lines)
@dracodoc
dracodoc / times.py
Last active October 24, 2015 00:39
Simple Python performance timing by checkpoints. http://dracodoc.github.io
import time
__author__ = 'dracodoc' # http://dracodoc.github.io/
# measure script time duration in segments.
# the clock value list: start, segments, end
# usage: import times, put times.start, seg_start, end etc in line.
T = []
Digit = [7]