Skip to content

Instantly share code, notes, and snippets.

@nigimaster
Last active August 17, 2020 10:53
Show Gist options
  • Save nigimaster/742e689b7b528b8ea725caf098a0d81d to your computer and use it in GitHub Desktop.
Save nigimaster/742e689b7b528b8ea725caf098a0d81d to your computer and use it in GitHub Desktop.
Collected snippets
### Jenkins
# start Jenkins in Shutdown mode
# init.groovy
import jenkins.model.*;
Jenkins.instance.doQuietDown();
# How to Start, Stop or Restart your Jenkins Instance
http://<jenkins.server>/restart
http://<jenkins.server>/safeRestart
http://<jenkins.server>/exit
http://<jenkins.server>/safeExit
http://<jenkins.server>/quietDown
http://<jenkins.server>/cancelQuietDown
### Decript
// decrypt SSH Private Key
println(hudson.util.Secret.decrypt(
"{AQAAABAAAAAgYLJWCZtomd4hxJcnqmUgSI9q7hC9mnUt0zI/ATVpv5hr6V7AP3JEF77Sidql2V66}"
)
)
// decrypt a secretbytes string (ssh-key/file credential)
println(new String(com.cloudbees.plugins.credentials.SecretBytes.fromString(secret).getPlainData(), "ASCII"))
// decrypt a regular secret
println(hudson.util.Secret.fromString(secret).getPlainText())
### base64
#1: Encoding text data
echo 'linuxhint.com' | base64
#2: Decoding text data
echo 'bGludXhoaW50LmNvbQo=' | base64 --decode
#3: Encoding text file
base64 sample.txt
#4: Decoding text file
base64 -d encodedData.txt
(source https://linuxhint.com/bash_base64_encode_decode/)
### JobDSL
Documentation URL: https://jenkinsci.github.io/job-dsl-plugin/#
The Configure Block: https://github.com/jenkinsci/job-dsl-plugin/wiki/The-Configure-Block
Jenkins Job DSL Playground: https://job-dsl.herokuapp.com/
### JCasC
Reference URL: https://{YOUR-JENKINS-URL}/configuration-as-code/reference#PrivateKeySource-directEntry
GITHub URL: https://github.com/jenkinsci/configuration-as-code-plugin
### Jenkins Script Console
URL: https://{YOUR-JENKINS-URL}/script
# Jenkins Job-dsl URL
https://jenkins.your-url.works/plugin/job-dsl/api-viewer/index.html
### Git
# delete branches that have been merged into origin/develop (excluding develop/master)
git branch --remote --merged origin/develop \
| grep -v master | grep -v develop | sed 's/origin\///' \
| xargs --no-run-if-empty git push origin --delete --dry-run
# Remove last wrong commit
git reset --hard HEAD^
git push origin -f
# Reset master to local
git fetch origin
git reset --hard origin/master
# Revert file
$ git checkout -- filename
# Cleaning up commit history with git rebase
git rebase -i HEAD~commit-number-to-rebase-here
# If there are literally only two commits, then HEAD~2 is undefined,
# and the message is expected. The commit before the current one (ie. the first of the two) is HEAD~1,
#a nd typing
git reset --soft HEAD~ && git commit --amend
# will merge the two commits into 1.
# Remove x commit in history
git reset --hard HEAD~n-commits-here
(after p,s,..)
git push -f
git push --force-with-lease
# add globally your gitignore locally
subl ~/.gitignore_global
# add in the file what needs to be ignored
git config --global core.excludesfile ~/.gitignore_global .
# Undo the Last Commit
# If you want to test the previous commit
git checkout <test commit hash> ; then you can test that last working version of your project.
# If you want to revert the last commit
git revert <unwanted commit hash>
# then you can push this new commit, which undid your previous commit.
# To fix the detached head
git checkout <current branch> .
# GIT Rebase
git checkout master
git pull
git checkout branch
git rebase -i origin/master
# if conflits happened, need to fix.
# accept incoming, for your last version from branch
# accept current change, from the master version
# git add the file
# git rebase --continue
#
# GIT Stash
# save/stash your change locally
git stash
# switch to branch or create another branch
# and run git pull
git pull
# go back to work on your local changes
git stash pop
# GIT pull only one folder, e.g. install
mkdir git_checkout
cd git_checkout/
git init
git remote add -f origin https://ISC76454@bitbucket.ontwikkel.local/scm/biomen/mbis.git
git config core.sparsecheckout true
echo install/ >> .git/info/sparse-checkout
git pull origin master
### SSH
Configuring SSH authentication
ssh-keygen -t rsa
# get public key from id_rsa.pub
# get private key from id_rsa
## prevent the passphrase prompt from appearing and set the key-pair to be stored in plaintext
ssh-keygen -b 2048 -t rsa -f /tmp/sshkey -q -N ""
### EXEL text manipulation
# example below for NGNIX redirects
# add test to begin cell
= "rewrite ^" & B1
# or
= "https://$host" & D1
# add test to end cell
= A1 & "$"
# or
= C1 & " permanent;"
# combine cells
=E1&" "&F1
of
=A1&" "&C1 &" permanent;"
## Shortcut EXEL redirects manipulation
# first half
= "rewrite ^" & C2 & "$"
# second half
= "https://$host" & D1
# full redirect
=A1&" "&C1 &" permanent;"
### VI
# to delete all lines
:1,$d
# to paste from clipboard
# First, make sure you're in edit mode (press i).
Then you can paste with Ctrl+Shift+V,
if you're in a terminal emulator like gnome-terminal (or select "Paste" from the right-click menu).
# DOCKER
This will destroy all your images
$ docker rmi $(docker images -q) --force
One liner to stop / remove all of Docker containers:
$ docker stop $(docker ps -a -q)
$ docker rm $(docker ps -a -q)
To test your GCP container image locally using Docker:
$ PORT=8080 && docker run -p 8080:${PORT} -e PORT=${PORT} gcr.io/[PROJECT_ID]/[IMAGE]
To test your container image locally using Docker:
$ docker run --rm --interactive --tty jenkins/jnlp-slave:3.35-5-alpine bash
# NUXT JS
# Installare le dipendenze
$ npm install # oppure yarn install
# Avvia il server locale con "hot reload" su localhost:3000
$ npm run dev
# Compila gli assets per l'ambiente di produzione
$ npm run build
# Avvia il server locale servendo i files prodotti dal precedente comando
$ npm start
# genera il progetto statico nella directory dist/
$ npm run generate
# NUXT
$ npm install
$ npm run-script build
$ npm run dev
# How to trigger a Kubernetes cronjob manually
Triggering a CronJob manually was difficult or impossible in older versions of Kubernetes, but since K8S 1.10 it can be done like this:
kubectl create job --from=cronjob/<name of cronjob> <name of job$ >
For example, if the name of your cronjob is “pgdump”, then you might run:
kubectl create job --from=cronjob/pgdump pgdump-manual-001
To see a list of cron jobs, run “kubectl get cronjob”.
# TAR archive
# Split Large ‘tar’ Archive into Multiple Files of Certain Size
$ split -b 10M archive-name.tar.bz2 "archive-name.tar.bz2.part"
# How to Join Tar Files After Splitting
$ cat archive-name.tar.bz2.parta* > backup.tar.gz.joined
# VI
Use :%s/foo/bar/g to replace all occurrences of the word foo in the current file with the word bar. Leaving off the g at the end only replaces the first occurrence of foo on each line of the current file.
:%s/foo/bar/g
# ORACLE DB
# Oracle: Total Size of The Database
# An oracle database consists of data files, redo log files, control files, temporary files.
# The size of the database actually means the total size of all these files.
col "Database Size" format a20
col "Free space" format a20
col "Used space" format a20
select round(sum(used.bytes) / 1024 / 1024 / 1024 ) || ' GB' "Database Size"
, round(sum(used.bytes) / 1024 / 1024 / 1024 ) -
round(free.p / 1024 / 1024 / 1024) || ' GB' "Used space"
, round(free.p / 1024 / 1024 / 1024) || ' GB' "Free space"
from (select bytes
from v$datafile
union all
select bytes
from v$tempfile
union all
select bytes
from v$log) used
, (select sum(bytes) as p
from dba_free_space) free
group by free.p
/
# Linux users & group
# id user-here
uid=65(user-here) gid=55(ldap) groups=55(ldap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment