Skip to content

Instantly share code, notes, and snippets.

💭
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.
Block or report user

Report or block ptoche

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View benchmark-diffs.R
# benchmark computing time differences
n = 1e6
set.seed(1)
Date = sort(replicate(n, paste0(Sys.Date(), " ",
sample(0:23, 1), ":", sample(0:59, 1), ":", sample(0:59, 1))))
Date <- as.POSIXct(Date, format="%Y-%m-%d %H:%M:%S", tz = "Europe/Paris")
diff_seq_along <- function(x) {
x[seq_along(x)+1]-x[seq_along(x)]
View pgfplots-animation-normal-distribution.tex
%\documentclass[border=12pt]{standalone}
\documentclass{article}
\usepackage[active,tightpage]{preview}
\usepackage{tikz}
\usetikzlibrary{calc}
\PreviewEnvironment{tikzpicture}
\usepackage{pgfplots}
\usepackage{fourier}
@ptoche
ptoche / convert.rb
Last active Jun 7, 2016 — forked from jdudek/convert.rb
Convert Opera's .adr address book to CSV
View convert.rb
#!/usr/bin/env ruby
require "csv"
File.open("contacts.adr", "r") do |f|
contacts = []
f.read.split("#CONTACT").each do |entry|
unless entry.empty?
contact = {}
entry.each_line do |line|
@ptoche
ptoche / annual_breaks.R
Last active Oct 17, 2015
Convenience function to create 'nice' breaks with ggplot2
View annual_breaks.R
## 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 / BibSecretaryProblem.bib
Last active Oct 6, 2015
A bibliography on the Secretary Problem in bibtex / bibtopic format (by nature incomplete)
View BibSecretaryProblem.bib
% Bibliography on the Secretary Problem and Related Games (Dynkin's game, Poisson search games, etc.)
@Article{Abdelaziz:Krichen:2005,
author = {Ben Abdelaziz, F. and Krichen, S.},
title = {An Interactive Method for the Optimal Selection Problem with Two Decision Makers},
journal = {European Journal of Operational Research},
volume = {162},
number = {3},
year = {2005},
@ptoche
ptoche / ps-income-shares.csv
Last active Aug 29, 2015
Piketty & Saez, Top Incomes in the U.S., 1913-2012
View ps-income-shares.csv
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 / global.R
Last active Aug 29, 2015
demo of a shiny survey
View global.R
# 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 / chatJava.js
Last active Aug 29, 2015
Adapted Jeff Allen's "Chat Room"
View chatJava.js
// 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 / make-and-crop.tex
Last active Aug 29, 2015
compile a latex image with pdflatex, convert to png, crop it, and clean up the temp files.
View make-and-crop.tex
% !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 / server.R
Created Jan 29, 2014
Demo on submit button with pop-up (IN PROGRESS)
View server.R
# 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?");'
You can’t perform that action at this time.