Skip to content

Instantly share code, notes, and snippets.

View ftorto's full-sized avatar

ftorto ftorto

  • TOULOUSE, France
View GitHub Profile
input=$1
result="${input/find/replacement}"
@ftorto
ftorto / diff.sh
Created February 24, 2017 06:52
Compare 2 lists
# List common lines in $1 and $2
function common {
comm --check-order -12 $1 $2
}
# List lines only present in $1
function onlyina {
comm --check-order -3 $1 $2 | sed '/\t/d'
}
@ftorto
ftorto / parallel_limit.sh
Created February 24, 2017 07:21
Parallelize actions with max parallel count
function parallel_function {
# something
}
max_parallel_jobs=4
while true
do
parallel_function &
((start_date=start_date+1))
while [ $(jobs | wc -l) -ge $max_parallel_jobs ] ; do sleep 1 ; done
@ftorto
ftorto / find.sh
Created April 6, 2017 12:57
Find files with only one line
find . -type f -exec awk 'END { if (NR > 1) print FILENAME }' {} \;

Prints an horizontal line taking the whole terminal length (no auto resize)

printf '%*s\n' "${COLUMNS:-$(tput cols)}" '' | tr ' ' _
@ftorto
ftorto / README.md
Created October 11, 2017 07:31
Parallelize tasks #jenkins #pipeline
  for (i = 0; i < sources.length; i++){
    String source = sources[i]
    String contrib_url = source.split(" ")[0]
    String contrib_tag = source.split(" ")[1]
    String contrib_dest_path = i.toString().padLeft(4,'0') + "__" + contrib_url.split('/').last() + "__" + contrib_tag
    builders[contrib_dest_path] = {
      echo "\u2600 Pulling [${contrib_url}] using tag [${contrib_tag}] to [${contrib_dest_path}]"
      checkout([$class: 'GitSCM', branches: [[name: "refs/tags/"+contrib_tag]], doGenerateSubmoduleConfigurations: false, extensions: [[$class: 'RelativeTargetDirectory', relativeTargetDir: contrib_dest_path]], submoduleCfg: [], userRemoteConfigs: [[credentialsId: credentials, url: contrib_url]]])
 }
@ftorto
ftorto / remove_block_if_pattern_found.sh
Created November 2, 2017 08:26
Remove a block (like a comment block) if this one contains a defined pattern in a specific file
# Remove a block beginning with $1, ending with $2 if it contains $3, in file $4
# $1 and $2 are sed regexp escaped surrounded with '/'
# Example: remove_block_if_pattern_found '/\/\*/' '/\*\//' '@license' $f
function remove_block_if_pattern_found {
start=$1
end=$2
pattern=$3
file=$4
# Considering everything above "package ...;" as header
@ftorto
ftorto / cleangpg.sh
Created February 12, 2018 21:53
Remove primary secret key from .gnupg
# Your fingerprint
gpgKey=0x1234123123123
# Export the full backup to store somewhere
gpg --export-secret-keys --armor ${gpgKey} > ${gpgKey}.full_backup.asc
# Export partial backup with only your subkeys
gpg --export-secret-subkeys --armor ${gpgKey} > ${gpgKey}.only_subkeys.asc
# Erase your .gnupg
@ftorto
ftorto / README.md
Created February 13, 2018 14:05
Google agenda into thunderbird
@ftorto
ftorto / openpgp.txt
Created February 13, 2018 18:43
Identité reliée à OpenKeychain
This Gist confirms the Linked Identity in my OpenPGP key, and links it to this GitHub account.
Token for proof:
[Verifying my OpenPGP key: openpgp4fpr:65b4874cef9335afb7dfd21215dbc405801c44e0]