Skip to content

Instantly share code, notes, and snippets.

sample-pres
========================================================
```{r setup, include=FALSE}
# set global chunk options
opts_knit$set(upload.fun = image_uri)
```
Image
========
import sys
def main():
grade = input('Please enter a grade between 0-100, 999 to exit. ')
while grade <> 999:
validatedGrade = validate(grade)
displayGrade(validatedGrade)
window = figure('units', 'normalized', 'OuterPosition', [0 0 .5 .5], ...
'Name', 'My Gui', 'NumberTitle', 'off', 'MenuBar', 'none', ...
'Toolbar', 'none', 'HandleVisibility', 'off');
% Main panel.
mainpanel = uix.Panel('Parent', window, 'Padding', 2, ...
'BorderType', 'none');
tabgroup = uitabgroup('Parent', mainpanel);
% Make the tabs.
tab1 = uitab('Parent', tabgroup, 'Title', 'Tab1');
tab2 = uitab('Parent', tabgroup, 'Title', 'Tab2');
Hello there, this is some plain text.
x <- 0.7
y <- 0.23
x + y # 0.93
LSE <- function(x, y){
exp(log(x) + log(1+exp(log(y) - log(x))))
}
LSE(x, y) # 0.93
@alexperrone
alexperrone / remove-false.R
Created November 11, 2016 18:14
Remove all-FALSE columns
# How to batch-remove columns which are all FALSE in data.table
library(data.table)
dt <- data.table(x = c(TRUE, FALSE, FALSE),
y = c(FALSE, FALSE, FALSE), # all FALSE
z = c(FALSE, FALSE, TRUE),
a = c(FALSE, FALSE, FALSE) # all FALSE
)
dt
all_false_cols <- apply(dt, MARGIN = 2, function(x){ all(x == FALSE)})

Keybase proof

I hereby claim:

  • I am alexperrone on github.
  • I am alexperrone (https://keybase.io/alexperrone) on keybase.
  • I have a public key ASDei6dS5IW6XfUaowNAJNTb7lgUjeLEVjF0YFUiEfXjSQo

To claim this, I am signing this object:

@alexperrone
alexperrone / benchmark-vectorization.R
Created April 25, 2018 21:30
Benchmark vectorization
library(microbenchmark)
options(digits = 3)
# Initialize variables.
vec <- 1:1e7 # initialize input vector, change size here
range <- seq_along(vec) # for bare for-loop
sum_unallocated <- function(x){
result <- c()
for (i in seq_along(x)){