Skip to content

Instantly share code, notes, and snippets.

View ptoche's full-sized avatar
💭
fooling around

Patrick Toche ptoche

💭
fooling around
  • strange indentations
  • I live in Hong Kong in the U.S. time zone, but my heart is still in Europe.
View GitHub Profile
@ptoche
ptoche / server.R
Created January 29, 2014 17:58
Demo on submit button with pop-up (IN PROGRESS)
# server.R
library("shiny")
shinyServer(
function(session, input, output) {
observe({
if (is.null(input$submit) || input$submit == 0){return()}
js_string <- 'alert("Do you want to submit now?");'
@ptoche
ptoche / make-and-crop.tex
Last active August 29, 2015 13:56
compile a latex image with pdflatex, convert to png, crop it, and clean up the temp files.
% !TeX document-id = {cf6594ac-97a2-46b5-af4f-f9d9c8aaa47d}
% !TeX TXS-program:compile = txs:///pdflatex/[--shell-escape]
\documentclass{article}%
\usepackage{filecontents}%
\begin{filecontents*}{tmp.tex}%
\input{tikz-board}%
\end{filecontents*}
%%
%% compile pdf
\immediate\write18{pdflatex tmp}
@ptoche
ptoche / chatJava.js
Last active August 29, 2015 13:56
Adapted Jeff Allen's "Chat Room"
// This script just listens for "enter"s on the text input and simulates
// clicking the "send" button when that occurs. Totally optional.
jQuery(document).ready(function(){
jQuery('#entry').keypress(function(evt){
if (evt.keyCode == 13){
// Enter, simulate clicking send
jQuery('#send').click();
}
});
})
@ptoche
ptoche / global.R
Last active August 29, 2015 13:56
demo of a shiny survey
# global.R
# Static Non-Reactive Area
# Read Survey Questions & Suggested Answers
Q <- read.csv("survey.csv", 'header' = FALSE)
# column 1 : questions
# column 2+: several answers
# Store Survey Questions & User Answers in a dataframe
@ptoche
ptoche / ps-income-shares.csv
Last active August 29, 2015 14:00
Piketty & Saez, Top Incomes in the U.S., 1913-2012
Year Fractile value
1 1913-01-01 Top 0.01% 0.0275501620545077
2 1914-01-01 Top 0.01% 0.0272920847365446
3 1915-01-01 Top 0.01% 0.0436035
4 1916-01-01 Top 0.01% 0.0440493410443468
5 1917-01-01 Top 0.01% 0.0333076913805183
6 1918-01-01 Top 0.01% 0.0244816293043196
7 1919-01-01 Top 0.01% 0.0222020659211262
8 1920-01-01 Top 0.01% 0.0167163862642264
9 1921-01-01 Top 0.01% 0.0168921038823408
@ptoche
ptoche / annual_breaks.R
Last active October 17, 2015 13:15
Convenience function to create 'nice' breaks with ggplot2
## create 'nice' annual breaks for use with ggplot
## because sometimes it's tedious to 'manually' set the minimum and maximum of the date range,
## when the data starts on odd years, like 1927, but you really want the labels to start at 1925
## x denotes the date variable, e.g. x = df$date
## for m = 5, the breaks will be multiples of 5 years
## breaks below min and above max
## replace floor and ceiling with round, if desired
annual_breaks <- function(x, m = 5) {
require('scales')
@ptoche
ptoche / server.R
Last active January 2, 2016 12:19 — forked from jknowles/server.R
# server.R
library("shiny")
library("ggplot2") # Grammar of Graphics for plots
library("VGAM") # Vector Generalized Linear and Additive Models
library("eeptools") # Convenience functions for education data
shinyServer(
function(input,output){
@ptoche
ptoche / server.R
Created January 7, 2014 16:47 — forked from jknowles/server.R
# Script to demonstrate distributions
library(VGAM)
library(eeptools)
library(shiny)
library(ggplot2)
shinyServer(function(input,output){
@ptoche
ptoche / server.R
Last active January 2, 2016 12:29 — forked from jknowles/server.R
# server.R
library("shiny")
library("ggplot2") # Grammar of Graphics for plots
library("eeptools") # Convenience functions for education data
# static function
rnormcor <- function(x,rho) {rnorm(1,rho*x,sqrt(1-rho^2))}
shinyServer(
@ptoche
ptoche / server.R
Last active January 2, 2016 12:29 — forked from jknowles/server.R
# server.R
library("shiny")
library("ggplot2") # Grammar of Graphics for plots
library("eeptools") # Convenience functions for education data
library("plyr") # Convenience functions to manipulate data
shinyServer(
function(input,output){