Skip to content

Instantly share code, notes, and snippets.

View benchmark-vectorization.R
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)){
View keybase.md

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 / remove-false.R
Created Nov 11, 2016
Remove all-FALSE columns
View remove-false.R
# 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)})
View lse.R
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
View test.html
Hello there, this is some plain text.
View mygui.m
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');
View grade.py
import sys
def main():
grade = input('Please enter a grade between 0-100, 999 to exit. ')
while grade <> 999:
validatedGrade = validate(grade)
displayGrade(validatedGrade)
View sample-pres.Rpres
sample-pres
========================================================
```{r setup, include=FALSE}
# set global chunk options
opts_knit$set(upload.fun = image_uri)
```
Image
========