Skip to content

Instantly share code, notes, and snippets.

library(dplyr)
library(microbenchmark)
x = sample(c("less often", "1", "2", "3", "4", "4+"), 1e6, r = TRUE)
fun1 = function(x) {
case_when(
x == "less often" ~ 1L,
x %in% c("1", "2") ~ 2L,
x %in% c("3", "4") ~ 3L,
@1beb
1beb / bash.py
Created January 14, 2020 06:08 — forked from judotens/bash.py
Celery Run Bash Project
from __future__ import absolute_import
import os
from subprocess import Popen, PIPE
import datetime
import time
from celery import Celery
from celery import states
from os.path import dirname, join
@1beb
1beb / gitstats.sh
Created August 7, 2019 05:24 — forked from xeoncross/gitstats.sh
Git - calculate how many lines of code were added/changed by someone
# Run this in the project repo from the command-line
# http://stackoverflow.com/a/4593065/99923
git log --shortstat --author "Xeoncross" --since "2 weeks ago" --until "1 week ago" | grep "files changed" | awk '{files+=$1; inserted+=$4; deleted+=$6} END {print "files changed", files, "lines inserted:", inserted, "lines deleted:", deleted}'
library(data.table)
size = 1e6
resample <- function(x,size = 1e6) sample(x,size,replace = TRUE)
text <- c("Canada","Peru","Australia","Angola","France","", NA_character_)
text2 <- c("Oh Canada.","Arriba Peru.","Australia?","Vive la France.")
numerics <- rnorm(1e6)
dt <- data.table(
df <- structure(list(Year = c("2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2015", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016", "2016"),
Response = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L, 14L, 15L, 16L, 17L, 18L, 19L, 20L, 21L, 22L, 23L, 24L),
.Label = c("Trustworthy", "Supportive", "Leading", "Strong", "Dependable", "Consultative", "Knowledgeable", "Sensible", "Intelligent", "Consistent", "Stable", "Innovative", "Aggressive", "Conservative", "Visionary", "Arrogant", "Professional", "Responsive", "Confident", "Accessible", "Timely", "Focused", "Niche", "None"), class = "factor"), Proportion = c(0.5
library(microbenchmark)
plus_test <- function(x) {
return(+x)
}
asint_test <- function(x) {
return(as.integer(x))
}
test_me <- function(n) {
current_test <- function(df) {
for (i in 1:nrow(df)) { # for every row
if ((df[i, 'col1'] + df[i, 'col2'] + df[i, 'col3'] + df[i, 'col4']) > 4) { # check if > 4
df[i, 5] <- "greater_than_4" # assign 5th column
} else {
df[i, 5] <- "lesser_than_4" # assign 5th column
}
}
return(df[,5])
@1beb
1beb / test.Rmd
Created January 8, 2016 18:49
Example Rmd for issue with Tufte
---
title: "Test"
author: "Brandon Bertelsen"
date: "January 7, 2016"
output:
tufte::tufte_html: default
---
```{r setup, include=FALSE}
library(tufte)
@1beb
1beb / server.R
Last active December 4, 2015 23:51 — forked from withr/server.R
Encrypt password with md5 for Shiny-app.
library(shiny)
library(datasets)
Logged = FALSE;
PASSWORD <- data.frame(Brukernavn = "withr", Passord = "25d55ad283aa400af464c76d713c07ad")
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
source("www/Login.R", local = TRUE)
observe({
if (USER$Logged == TRUE) {
@1beb
1beb / gdocs2slidify.Rmd
Created December 15, 2013 05:18
Header to slidify document
---
title : Example Report
subtitle: Subtitle
job : Slidify 2013
mode: standalone # {standalone, draft}
---
{r init, echo=FALSE,message=FALSE, warning = FALSE, cache=FALSE}
opts_chunk$set(echo=FALSE,
message=FALSE,