Skip to content

Instantly share code, notes, and snippets.

View ArnauMontagud's full-sized avatar

Arnau Montagud ArnauMontagud

View GitHub Profile
@ArnauMontagud
ArnauMontagud / heatmaply.R
Created August 5, 2021 11:25
[R Interactive heatmap] Using heatmaply to have interactive heatmap #R
# interactive heatmap :
install.packages("heatmaply")
library(heatmaply)
a<-
heatmaply(mtcars, k_col = 2, k_row = 3) %>% layout(margin = list(l = 130, b = 40))
dev.off ()
# mtcars
# x <- heatmapr(mtcars)
library(heatmaply)
@ArnauMontagud
ArnauMontagud / colour_palettes.R
Created August 5, 2021 11:23
[R show colour palettes] #R
# show colour palettes (RColorBrewer palettes)
library(tmaptools)
palette_explorer()
@ArnauMontagud
ArnauMontagud / updateR.R
Last active August 5, 2021 11:27
[R Update R] #R
# from here: https://www.r-statistics.com/2013/03/updating-r-from-r-on-windows-using-the-installr-package/
rm(list=ls())
if(!require(installr)) {
install.packages("installr"); require(installr)} #load / install+load installr
updateR()
@ArnauMontagud
ArnauMontagud / HammingDist.java
Last active August 5, 2021 11:19
[Java Calculate Hamming distance] Calculating the Hamming Distance for two strings of the same length #Java
// adapted from here: https://stackoverflow.com/questions/16260752/using-for-loop-to-get-the-hamming-distance-between-2-strings
public class Hamming
{
private String compOne;
private String compTwo;
public Hamming(String one, String two)
{
compOne = one;
@ArnauMontagud
ArnauMontagud / xor_function.sh
Created August 5, 2021 11:12
[Shell XOR function of a hexadecimal string] #Shell
#!/usr/bin/env bash
# BASH function to get the result
# of a ^ b when a, b are in the
# following hexadecimal string
# form: AF396463D8705 ...
# Obtained from here:
# http://www.codeproject.com/Tips/470308/XOR-Hex-Strings-in-Linux-Shell-Script
# Author is Sanjay1982 (see http://www.codeproject.com/Members/Sanjay1982)
@ArnauMontagud
ArnauMontagud / making_pptx.R
Created August 5, 2021 11:05
[R Make a PPTX] #R
library(rvg)
library(ggplot2)
library(officer)
doc <- read_pptx()
doc <- add_slide(doc, layout = "Title and Content", master = "Office Theme")
doc <- ph_with_vg(doc, code = barplot(1:10), type = "body")
print(doc, target = "my_plot.pptx")
@ArnauMontagud
ArnauMontagud / Option1_base.R
Last active August 5, 2021 11:03
[R Check for missing packages and install them] Place at the beginning of the R script to check for missing packages and install them (and only in option2 load them) #R
# from: https://stackoverflow.com/questions/4090169/elegant-way-to-check-for-missing-packages-and-install-them
# This checks for missing packages and installs them. You will need to load them manually
list.of.packages <- c("ggplot2", "magrittr")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
# library(ggplot2)
@ArnauMontagud
ArnauMontagud / transpose.sh
Last active August 5, 2021 11:09
[Shell Transpose table using awk] Take a table, transpose it and print it with a suffix #awk #shell
#!/usr/bin/bash
# usage for a table called filename.txt: transpose.sh filename
# from here: https://stackoverflow.com/questions/1729824/an-efficient-way-to-transpose-a-file-in-bash
transpose () {
awk '
{
for (i=1; i<=NF; i++) {
a[NR,i] = $i
}
@ArnauMontagud
ArnauMontagud / Add_to_bashrc_option1.txt
Last active August 5, 2021 11:04
[Shell Infinite bash history] Keep all history, forever #shell #bashrc
# Option 1, from here: https://spin.atomicobject.com/2016/05/28/log-bash-history/
# more history settings, date wise, infinite
export PROMPT_COMMAND='if [ "$(id -u)" -ne 0 ]; then echo "$(date "+%Y-%m-%d.%H:%M:%S") $(pwd) $(history 1)" >> ~/.logs/bash-history-$(date "+%Y-%m-%d").log; fi'
Add to ~/.bashrc, Make the ~/.logs folder, and you are set forever
Then, you can do a grep 'whatever script or data name' ~/.logs/*
@ArnauMontagud
ArnauMontagud / count_lines_github.sh
Created August 5, 2021 09:18
[count lines from GitHub repo] #GitHub #shell
#!/usr/bin/env bash
git clone --depth 1 https://github.com/PhysiBoSS/PhysiBoSS.git && cloc PhysiBoSS && rm -rf PhysiBoSS