Skip to content

Instantly share code, notes, and snippets.

View verajosemanuel's full-sized avatar
💭
RRRRRRRRRRRRRRRR

Jose Manuel Vera verajosemanuel

💭
RRRRRRRRRRRRRRRR
View GitHub Profile
@verajosemanuel
verajosemanuel / remove_containing.sh
Last active November 14, 2017 09:29
#sed remove line containing pattern #bash #regex
sed '/pattern/ {$!N;d;}'
@verajosemanuel
verajosemanuel / delete_from_pattern_to_end.sh
Last active November 14, 2017 09:29
#sed delete from pattern to end of #files #regex #bash
sed '/pattern/,$d'
@verajosemanuel
verajosemanuel / sed_insert_between_patterns.sh
Last active November 14, 2017 09:29
#sed insert character/s between two patterns #regex #bash
# here, inserting tab between
sed -r 's/(pattern1)(pattern2)/\1\t\2/g'
@verajosemanuel
verajosemanuel / get_df_name.R
Last active November 14, 2017 09:27
get object name, not content in #R
# for just one object
deparse(substitute(my.object))
#for a bunch of objects of the same class
# as string
dfs <- names(which(unlist(eapply(.GlobalEnv,is.data.frame))))
@verajosemanuel
verajosemanuel / add_comment.R
Last active November 14, 2017 09:27
add comment #metadata to object in #R
# set comment
comment(my_data_frame) <- "This is a comment"
# return comment
comment(my_data_frame)
[1] "This is a comment"
@verajosemanuel
verajosemanuel / return_several_data_frames_from_function.R
Last active November 14, 2017 09:27
return more than one #df from inside a #function in #R
# be warned this is not a very proper way of R programming
# if you need to promote objects from inside function to
# parent environment better think twice
myfunc <- function(x) {
# do something like manipulating data and returning several df
# .........
# .....
@verajosemanuel
verajosemanuel / basename.sh
Last active November 14, 2017 09:26
Get basename no matter extension inside while #loop #bash
for f in *.*
do
name_is=$(basename ${f%.*})
done
@verajosemanuel
verajosemanuel / extension_count.sh
Last active November 14, 2017 09:26
Get #files extension for counting filetype #bash
if [ ${f: -4} == ".pdf" ];then ((pdffiles++)); fi
if [ ${f: -5} == ".docx" ];then ((docxfiles++)); fi
@verajosemanuel
verajosemanuel / check_contains_values.sh
Last active November 14, 2017 09:25
#bash check if variable contains values or is empty
if [[ -z "${myVar// }" ]];then # if myVar is empty
# do something
fi
if [[ -n "${myVar// }" ]];then # if myVar is NOT empty
# do something
fi
@verajosemanuel
verajosemanuel / variable_contains.sh
Last active November 14, 2017 09:25
#sql like in #bash variable
if [[ "${myVar}" =~ "myText" ]];then
# do something
fi