This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
names <- list(a = c("firstname1","firstname2"), | |
b = c("lastname1","lastname2")) | |
eval( substitute( paste(a, b), names )) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
trap 'get_window_size' WINCH # trap when a user has resized the window | |
get_window_size() { | |
_WINDOW_X=`tput lines` | |
_WINDOW_Y=`tput cols` | |
echo "X: $_WINDOW_X" | |
echo "Y: $_WINDOW_Y" | |
return 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
readOne () { | |
tput smso | |
echo "Press any key to return \c" | |
tput rmso | |
oldstty=`stty -g` | |
stty -icanon -echo min 1 time 0 | |
dd bs=1 count=1 >/dev/null 2>&1 | |
stty "$oldstty" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-get update |pv -tN "Updating" > /dev/null & pid=$! | |
trap "kill $pid 2> /dev/null" EXIT | |
while kill -0 $pid 2> /dev/null; do | |
tput cup 10 10 | |
done | |
trap - EXIT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LIST=$1 | |
PACKAGE_LIST=$(dpkg --get-selections | awk '{ print $1 }' | grep -v -e "-dbg" | cut -f1 -d":") | |
getsize () { | |
size=$(apt-cache --no-all-versions show $1 | grep Installed-Size | awk '{ print $2 }') | |
((NEEDED+=$size)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(stats) | |
## Extends the example for 'switch' | |
center <- function(x, type = c("mean", "median", "trimmed")) { | |
type <- match.arg(type) | |
switch(type, | |
mean = mean(x), | |
median = median(x), | |
trimmed = mean(x, trim = .1)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Example of accessing the function call stack | |
IsHungry <- function(){ | |
e <- substitute(cat(sub("\\(.*\\)", " ", deparse(sys.calls()[[i]])))) | |
Bob <- function(n){ | |
Loves <- function(n){ | |
Burgers <- function(n){ | |
TheEnd <- function(n){ | |
invisible(sapply(1:n, function(i) eval(e, list(i)))) | |
} | |
TheEnd(sys.nframe()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
today <- Sys.Date() | |
yearEnd <- as.Date(paste0(year(today), "-12-31")) | |
daysVec <- seq(today, yearEnd, by=1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
j <- function(x) { | |
y <- 2 # Define y | |
# j returns this function | |
function() { | |
c(x, y) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# One line to keep rows such that there are no NAs across all columns | |
dt[Reduce("&", lapply(dt, function(i) !is.na(i)))] |
OlderNewer