Skip to content

Instantly share code, notes, and snippets.

View abresler's full-sized avatar

Alex Bresler abresler

View GitHub Profile

geojsonio has two ways to validate geojson (specifically geojson, not json structure itself). Via a web API from geojsonlint, or locally using the Mapbox's javascript geojsonhint library (included in the package).

Both can act directly on many different inputs, including character strings, lists, data.frame's, all the sp class spatial objects.

Install and load

@rich-iannone
rich-iannone / chromatography.R
Last active August 29, 2015 14:16
R function that loads in chromatography.js, constructs a string of JS code, passes that code for evaluation (using the 'V8' package), and returns a palette of visually different colors.
library(V8)
# Create function to generate palette of visually different colors
hex_palette <- function(no_colors,
hue_range = NULL,
chroma_range = NULL,
lightness_range = NULL){
pal <- function(col, border = "light gray", ...){
n <- length(col)
@abresler
abresler / dogs.R
Last active December 18, 2015 15:37
# Reading in 'dogs.csv'
# Created by Alex Bresler, available at:
# https://github.com/abresler/abresler.github.io/blob/master/blog/2015/february/exploring_agility_show/data/dogs.csv
dogs <- read.csv("dogs.csv", header = TRUE, stringsAsFactors = FALSE)
# Setting a numeric id
node_id <- 1:nrow(dogs)
# Getting unique values for the 'breed' column
unique_node_2 <- unique(dogs$breed)
category value sector
UK production emissions 632 UK
Carbon flows from EU 88 EU
Carbon flows to EU -61 EU
Carbon flows from other Annex 1 82 Annex 1
Carbon flows to other Annex 1 -39 Annex 1
Carbon flows from non-Annex 1 104 Other non-Annex 1
Carbon flows from non-Annex 1 64 China
Carbon flows to non-Annex 1 -25 Non-Annex 1
UK consumption emissions 845 UK
@timelyportfolio
timelyportfolio / code.R
Last active September 6, 2015 12:17
make a pdf in R with hpdf.js - emscripten port of libharu
# run these hpdf.js examples
# http://manuels.github.io/hpdf.js/
# in R with V8
library(V8)
library(pipeR)
library(htmltools)
ct = new_context("window")
ct$source("https://raw.githubusercontent.com/manuels/hpdf.js/master/hpdf.min.js")
@abresler
abresler / pagerank.R
Last active December 18, 2015 15:37 — forked from andrie/pagerank.R
## Analyze R packages for popularity, using pagerank algorithm
# Inspired by Antonio Piccolboni, http://piccolboni.info/2012/05/essential-r-packages.html
library(miniCRAN)
library(igraph)
library(magrittr)
# Download matrix of available packages at specific date ------------------
@jeroen
jeroen / viz.js.R
Last active August 29, 2015 14:15
library(V8)
stopifnot(packageVersion("V8") >= "0.5")
# Create V8 context and load viz.js
ct <- new_context("window")
invisible(ct$source('http://mdaines.github.io/viz.js/viz.js'))
# This runs: Viz("digraph { a -> b; }", "svg")
svg <- ct$call("Viz", "digraph { a -> b; }", "svg")
cat(svg)
@timelyportfolio
timelyportfolio / code.R
Last active July 9, 2021 18:52
R | Turf.js with V8
#devtools::install("jeroenooms/V8")
library("V8")
library(pipeR)
ct = new_context("window")
# min.js gives me a call stack size error but non-min works fine
ct$source(
"https://raw.githubusercontent.com/morganherlocker/turf/master/turf.js"
)
# one of the examples from turf API docs
@timelyportfolio
timelyportfolio / Readme.md
Last active August 29, 2015 14:14
R finance charts with the svgPanZoom htmlwidget
library(mgcv)
library(ggplot2)
library(dplyr)
library(XML)
library(weatherData)
us.airports.url <- 'http://www.world-airport-codes.com/us-top-40-airports.html'
us.airports <- readHTMLTable(us.airports.url)[[1]] %>%
filter(!is.na(IATA)) %>%