Skip to content

Instantly share code, notes, and snippets.

@mastropinguino
Last active July 11, 2023 16:14
Show Gist options
  • Save mastropinguino/caaa5f15399e6442e61c51250fb54ee3 to your computer and use it in GitHub Desktop.
Save mastropinguino/caaa5f15399e6442e61c51250fb54ee3 to your computer and use it in GitHub Desktop.

Springboot project structure recommentation

config - class which will read from property files

cache - caching mechanism class files

constants - constant defined class

controller - controller class

exception - exception class

model - pojos classes will be present

security - security classes

service - Impl classes

util - utility classes

validation - validators classes

bootloader - main class

Backtrace programs

(taken from: https://wiki.ubuntu.com/Backtrace)

  1. Make sure the GNU Debugger is installed.

sudo apt-get install gdb

  1. Start gdb (some programs run as root, so one would use sudo gdb instead of just gdb below):
gdb 2>&1 | tee gdb-<program>.txt
(gdb) handle SIG33 pass nostop noprint
(gdb) set pagination 0

3a. Run program

run <arguments, if any>

3b. or attach to existing process

find pid: pidof <program>

(gdb) attach <PID> 
(gdb) continue 
  1. The program will continue running. Perform any actions necessary to reproduce the crash. If the program hangs but doesn't crash you can press ctrl+c in gdb while the program is frozen and then continue with the next step. Retrieve a backtrace:
(gdb) backtrace full
(gdb) info registers
(gdb) x/16i $pc
(gdb) thread apply all backtrace
(gdb) quit 

Now we have a complete output from GDB, contained in gdb-.txt

INFO Note that you can also set logging to a file like this:

(gdb) set logging file gdb-<program>.txt
(gdb) set logging on 

Sublime useful settings

{
  "folder_exclude_patterns": ["node_modules", ".svn", ".git", ".hg", "CVS"],
  "file_exclude_patterns": ["*.pyc", "*.pyo", "*.exe", "*.dll", "*.obj","*.o", "*.a", "*.lib", "*.so", "*.dylib", "*.ncb", "*.sdf", "*.suo", "*.pdb", "*.idb", ".DS_Store", "*.class", "*.psd", "*.db", "*.sublime-workspace"],
  "binary_file_patterns": ["generated/*", "*.tbz2", "*.gzip", "*.jpg", "*.jpeg", "*.png", "*.gif", "*.ttf", "*.tga", "*.dds", "*.ico", "*.eot", "*.pdf", "*.swf", "*.jar", "*.zip"],
  "tab_size": 2,
  "translate_tabs_to_spaces": true,
}

Size of table in mysql

Link: https://chartio.com/resources/tutorials/how-to-get-the-size-of-a-table-in-mysql/

SELECT
  TABLE_NAME AS `Table`,
  ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)`
FROM
  information_schema.TABLES
WHERE TABLE_SCHEMA = "bookstore" 
ORDER BY
  (DATA_LENGTH + INDEX_LENGTH)
DESC;
  
-- NB: remove WHERE clausole in order to get all tables size
#!/bin/bash
#---------------------------------------------------------------------
usage() {
cat<<EOF
Usage: ${0} program_name [program_args]
Trace a given program using gdb.
EOF
}
log() {
echo "${*}" 1>&2
}
die() {
usage
log 'error:' ${*}'.'
exit 1
}
#---------------------------------------------------------------------
test "x${*}" = "x" && die 'no process given'
LOG="/tmp/gdb-`basename ${1}`.txt"
log "outputting trace to '${LOG}'"
PROG_PID=$1
exec gdb -batch-silent \
-ex 'set logging overwrite on' \
-ex "set logging file ${LOG}" \
-ex 'set logging on' \
-ex 'handle SIG33 pass nostop noprint' \
-ex 'set pagination 0' \
-ex "attach $PROG_PID" \
-ex 'backtrace full' \
-ex 'info registers' \
-ex 'x/16i $pc' \
-ex 'thread apply all backtrace' \
-ex 'quit'
< /dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment