Skip to content

Instantly share code, notes, and snippets.

@pat-s
pat-s / addins.json
Last active March 2, 2020 09:58
Apply RStudio Desktop Settings
{
"styler::style_active_file": "Ctrl+Y",
"addmins::insert_dashes": "Ctrl+8",
"xaringan::inf_mr": "Ctrl+M",
"drake::rs_addin_loadd": "Ctrl+K",
"browse::browse": "Ctrl+B"
}
library(emo)
library(stringr)
library(purrr)
emoji_name <- emo:::emoji_name
emoji_keyword <- emo:::emoji_keyword
maybe_emoji <- function( keyword ){
if (keyword %in% names(emoji_name)) {
@HenrikBengtsson
HenrikBengtsson / ascii-mandelbrot.R
Last active July 10, 2017 18:05
ASCII Mandelbrot renderer (One-to-one R interpretation of C implementation)
## A one-to-one R interpretation of the minimalist C implementation
## of the ASCII Mandelbrot renderer in http://codepad.org/nINhbWVy:
##
## main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x
## =0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0;
## j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}
main <- function(k = 0) {
y <- -16
while({ cat("\n"); y <- y + 1L } < 16) {
@sjewo
sjewo / InsertLatex2RtfEps.bas
Last active March 16, 2017 12:09
Replace Latex2rtf marker with actual images (Linux only, as the path is modified to remove the missing figure folder)
' Replace Latex2rtf marker with actual images in LibreOffice
' Linux only, as the path is modified to remove the missing figure folder
Sub InsertLatex2RtfEps
oText = ThisComponent.Text
RDescrip = ThisComponent.createReplaceDescriptor
RDescrip.searchRegularExpression = True
RDescrip.searchString = "\[###([^\]]*)###\]"
rngs = ThisComponent.findAll(RDescrip)
# somewhat hackish solution to:
# https://twitter.com/EamonCaddigan/status/646759751242620928
# based mostly on copy/pasting from ggplot2 geom_violin source:
# https://github.com/hadley/ggplot2/blob/master/R/geom-violin.r
library(ggplot2)
library(dplyr)
"%||%" <- function(a, b) {
@christophergandrud
christophergandrud / source_lines.R
Created December 1, 2014 14:08
Source specific lines from a file in R
#' Source specific lines in an R file
#'
#' @param file character string with the path to the file to source.
#' @param lines numeric vector of lines to source in \code{file}.
source_lines <- function(file, lines){
source(textConnection(readLines(file)[lines]))
}
@vitkin
vitkin / README.md
Last active August 5, 2021 19:19
Backport WebSocket to Apache 2.2 that doesn't modify the 'mod_utils.c' and the 'mod_proxy.h'. See the 'README.md' for details and instructions.

Backport WebSocket to Apache 2.2

This is my variation from the original patch and that also includes the suggested correction for the bug with secure websocket 'wss://'.

The difference is that I avoid modifying the mod_utils.c and the mod_proxy.h so that if the mod_proxy module has been embedded in the main httpd binary then it will work and you won't get the

@schaunwheeler
schaunwheeler / xlsxToR.r
Last active December 11, 2020 16:41
Import an xlsx file into R by parsing the file's XML structure.
# The MIT License (MIT)
#
# Copyright (c) 2012 Schaun Jacob Wheeler
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
@AlexandreAbraham
AlexandreAbraham / unsupervised_alt.py
Last active July 1, 2024 12:26
These are two implementations of the silhouette score. They are compatible with the scikit learn implementation but offers different drawbacks in term of complexity and memory usage. The slow version needs no memory but is painfully slow and should, I think, not be used. The second one is based on a block strategy: distance between samples and c…
""" Unsupervised evaluation metrics. """
# License: BSD Style.
from itertools import combinations
import numpy as np
from sklearn.utils import check_random_state
from sklearn.metrics.pairwise import distance_metrics
from sklearn.metrics.pairwise import pairwise_distances
@hadley
hadley / s3.r
Created May 7, 2013 13:16
Implementation of request signing for Amazon's S3 in R.
library(httr)
library(digest)
library(XML)
s3_request <- function(verb, bucket, path = "/", query = NULL,
content = NULL, date = NULL) {
list(
verb = verb,
bucket = bucket,
path = path,