Skip to content

Instantly share code, notes, and snippets.

View jmcastagnetto's full-sized avatar
🇵🇪
Focusing

Jesus M. Castagnetto jmcastagnetto

🇵🇪
Focusing
View GitHub Profile
@jmcastagnetto
jmcastagnetto / sjt.xtab-bug.Rmd
Last active August 29, 2015 13:57
Code that illustrates the sj.xtab() bug when rendering to HTML with knitr (ref: https://github.com/sjPlot/devel/issues/1)
# bug in sjt.xtab()
```{r}
require(sjPlot)
set.seed(12345)
var1 <- as.factor(sample(c("ok", "not ok"), 1000, replace=TRUE, prob=c(0.2, 0.8)))
var2 <- as.factor(sample(c("foo", "bar", "boing", "kaboom", "plonk"), 1000, replace=TRUE))
var3 <- sample(2:20, 1000, replace=TRUE)
xtab1 <- sjt.xtab(var2, var3, var1, variableLabels=c("var2", "var3", "var1"),
showSummary=FALSE, showLegend=FALSE, no.output=TRUE)
@jmcastagnetto
jmcastagnetto / peru-presidents.Rmd
Last active August 29, 2015 14:00
A simple document showing the use of XML to get data from an HTML table, dplyr for data manipulation, lubridate for some simple date mangling, and ggplot2 and googleVis to generate nice charts (interactive in the case of googleVis)
---
title: "Analysis of the data on Presidents of Peru"
author: Jesus M. Castagnetto
output:
html_document:
toc: true
theme: readable
highlight: tango
---
@jmcastagnetto
jmcastagnetto / README.md
Last active August 29, 2015 14:04
Script to use Pingdom's custom HTTP check, inspired by the one described in: http://jonsview.com/how-i-use-pingdoms-http-custom-feature

Script to be used with Pingdom's custom HTTP check.

Inspired by the code described in http://jonsview.com/how-i-use-pingdoms-http-custom-feature

Warning:

As of 20114-08-07, if you are using gzip compression in your server, creating a check pointing to an URL with the output of this script will fail, as the code been used by Pingdom does not yet grok compression.

The solution (at least for Apache), is to explicitly exclude from compression the path to the script in your server config, e.g.:

@jmcastagnetto
jmcastagnetto / kahansum.php
Last active August 29, 2015 14:11
Implementation in PHP of the Kahan summation algorithm
<?php
// ref: http://rosettacode.org/wiki/Kahan_summation
// 1. Do all arithmetic in decimal to a precision of six digits.
// PHP does not have a way of restricting overall precision
// 2. Write a function/method/procedure/subroutine/... to perform Kahan
// summation on an ordered collection of numbers, (such as a list of numbers). )
function kahansum($input) {
$sum = $c = 0;
@jmcastagnetto
jmcastagnetto / nist-beacon-response.R
Last active August 29, 2015 14:12
A simple and naive example of using the NIST Randomness Beacon in R (https://beacon.nist.gov/home)
require(RCurl)
require(XML)
# Let's make a special class
NISTBeaconResponse <- function (ts) {
if(!is.integer(ts) &
!inherits(ts, "POSIXct") &
!inherits(ts, "POSIXlt")) {
stop("We expected a unix timestamp as an integer or a POSIXct or POSIXlt value")
}
@jmcastagnetto
jmcastagnetto / who_immunization_tables.R
Created February 6, 2015 15:05
Code to cleanup and read WHO immunization monitoring tables into R data frames.
require(XML)
require(reshape2)
# node content cleanup
cleanup <- function(node) {
val <- xmlValue(node)
if(is.character(val) | is.factor(val)) {
out <- gsub("'","", val, fixed=TRUE)
} else {
out <- val
@jmcastagnetto
jmcastagnetto / kahansum.R
Last active November 26, 2015 05:56
Implementation in R of the Kahan summation algorithm
# Kahan summation
# ref: http://rosettacode.org/wiki/Kahan_summation
# Try using the task rules
# 1. Do all arithmetic in decimal to a precision of six digits.
options(digits=6)
# 2. Write a function/method/procedure/subroutine/... to perform Kahan summation
# on an ordered collection of numbers, (such as a list of numbers).
kahansum <- function(x) {
# Inspired by http://xkcd.com/1609/
set.seed(1609)
food <- c("ice cream", "ham", "relish",
"pancakes", "ketchup", "cheese",
"eggs", "cupcakes", "sour cream",
"hot chocolate", "avocado", "skittles",
"wasabi", "tofu", "steak", "sweet potatoes")
nfood <- length(food)
@jmcastagnetto
jmcastagnetto / brexitchart.R
Last active June 27, 2016 20:02
GBP to USD exchange rate and BREXIT events (2016-06-27)
# BREXIT events and exchange rate of GBP -> USD
library(quantmod)
pd <- getFX("GBP/USD",
from="2016-01-01",
to="2016-06-30")
plot(GBPUSD, ylim=c(1.35,1.5), main="British Pounds per USD")
df <- data.frame(
date = index(GBPUSD),
rate = as.numeric(GBPUSD)

Keybase proof

I hereby claim:

  • I am jmcastagnetto on github.
  • I am jmcastagnetto (https://keybase.io/jmcastagnetto) on keybase.
  • I have a public key whose fingerprint is 73A9 891B 6BAB 0D95 75AF 3759 03B2 0193 CD42 79DF

To claim this, I am signing this object: