Skip to content

Instantly share code, notes, and snippets.

View jeroen's full-sized avatar

Jeroen Ooms jeroen

View GitHub Profile
@jeroen
jeroen / sqljs.R
Last active August 29, 2015 14:14
Simple example of running sql.js in R with V8
# Requires recent version of V8:
if( ! require(V8) || packageVersion("V8") < "0.5"){
install.packages("V8")
}
# Create JavaScript context and load sql.js
ct <- new_context()
ct$source("https://raw.githubusercontent.com/kripken/sql.js/master/js/sql.js")
# Evaluate JavaScript code
@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)
@jeroen
jeroen / katex.R
Last active August 29, 2015 14:15
KaTeX proof of concept
library(V8)
ct <- new_context()
ct$source("http://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.js")
html <- ct$call("katex.renderToString", "f(x, \\mu, \\sigma) = \\frac{1}{\\sigma \\sqrt{2\\pi} } e^{ -\\frac{(x-\\mu)^2}{2\\sigma^2}}");
tmp <- tempfile(fileext = ".html")
writeLines(c('<html><head><meta charset="UTF-8"><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.1.1/katex.min.css"></head><body>', html, '</body></html>'), tmp)
browseURL(tmp)
@jeroen
jeroen / simplified.geojson
Last active August 29, 2015 14:15 — forked from timelyportfolio/code.R
V8 example with turf.js
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jeroen
jeroen / lm.R
Last active August 29, 2015 14:15 — forked from timelyportfolio/Readme.md
Linear regression in JavaScript using simple statistics
# Load in simple statistics
library(V8)
ct <- new_context("window")
ct$source("https://raw.githubusercontent.com/tmcw/simple-statistics/master/src/simple_statistics.js")
# Run Regression
ct$assign("mydata", cbind(mtcars$wt, mtcars$mpg))
ct$eval("var lm = ss.linear_regression().data(mydata)")
ct$get("[ lm.b(), lm.m() ]")
@jeroen
jeroen / index.html
Last active August 29, 2015 14:15
Example of full screen iframe
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Example of embedded iframe</title>
<style type="text/css">
body {
margin: 0;
overflow: hidden;
@jeroen
jeroen / cc.sh
Created February 23, 2015 04:35
# This uses the Debian (or Ubuntu) cross compiler to a native gcc for win32 with multilib support
#
# Based on: http://sourceforge.net/p/mingw-w64/wiki2/Native%20Win64%20compiler/
#
# Cross compiling notes:
# - The minor version of gcc must match that of our cross compiler (4.9 in this case)
# - Important parameters: http://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
# Prepare system
@jeroen
jeroen / curl-symbols.h
Created March 4, 2015 06:20
Curl 7.41.0 symbols
#include <curl/curl.h>
#define LIBCURL_HAS(x) \
(defined(x ## _FIRST) && (x ## _FIRST <= LIBCURL_VERSION_NUM) && \
(!defined(x ## _LAST) || ( x ## _LAST >= LIBCURL_VERSION_NUM)))
#define CURLAUTH_ANY_FIRST 0x070a06 /* Added in 7.10.6 */
#define CURLAUTH_ANYSAFE_FIRST 0x070a06 /* Added in 7.10.6 */
#define CURLAUTH_BASIC_FIRST 0x070a06 /* Added in 7.10.6 */
#define CURLAUTH_DIGEST_FIRST 0x070a06 /* Added in 7.10.6 */
@jeroen
jeroen / examples.R
Last active August 29, 2015 14:17
How to do stuff in curl
library(curl)
# Verbose
h <- new_handle()
handle_setopt(h, verbose = TRUE)
req <- curl_perform("http://httpbin.org/get", handle = h)
# Parsing headers
parse_headers(req$headers)
@jeroen
jeroen / closures.R
Last active August 29, 2015 14:18
Closures in R
# Creating closures in R is actually very fast:
data("diamonds", package = "ggplot2")
diamonds$get <- lapply(seq_len(nrow(diamonds)), function(i){
k <- i
function(what){
diamonds[k,what]
}
})
# Execute: