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
//
// FlycutOperator.m
// Flycut
//
// Flycut by Gennadiy Potapov and contributors. Based on Jumpcut by Steve Cook.
// Copyright 2011 General Arcade. All rights reserved.
//
// This code is open-source software subject to the MIT License; see the homepage
// at <https://github.com/TermiT/Flycut> for details.
//
@ptoche
ptoche / spyder-hacks
Last active May 28, 2020 11:28
Spyder hacks: backup and edit config files for each environment (Upcoming release Spyder 5 will hopefully offer something better than this soon)
"""
Spyder hacks: backup and edit config files for each environment.
Upcoming release Spyder 5 will hopefully offer something better than this soon.
Created 28 May 2020
@author: Patrick Toche
"""
# import common packages here, otherwise import inside each function (helps me understand which packages are needed where and how much they are needed)
import os
# 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)]
%\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 June 7, 2016 07:09 — forked from jdudek/convert.rb
Convert Opera's .adr address book to CSV
#!/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 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 / BibSecretaryProblem.bib
Last active April 16, 2022 21:27
A bibliography on the Secretary Problem in bibtex / bibtopic format (by nature incomplete)
% 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 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 / 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 / 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();
}
});
})