Skip to content

Instantly share code, notes, and snippets.

@mshafeeqkn
mshafeeqkn / .bashrc
Last active July 18, 2024 03:12
The PS1 variable for bashrc
parse_git_branch() {
_branch=$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')
_branch="$_branch"
echo $_branch
}
export PS1="\[\033[38;5;42m\]\u@\h\[\033[00m\]:\[\033[38;5;39m\]\W\[\033[38;5;198m\]\$(parse_git_branch)\[\033[00m\]$ "
@mshafeeqkn
mshafeeqkn / .vimrc
Created July 18, 2024 03:03
The vimrc file I am using
set hlsearch
set incsearch
set ic
set expandtab
set shiftwidth=4
set tabstop=4
set laststatus=2
set statusline=%f
set autoindent
set tags=tags;/
@mshafeeqkn
mshafeeqkn / dump_struct.c
Last active June 15, 2024 01:06
Print the dump of a structure which will be useful for understanding structure padding
void dump_structure(void *ptr, unsigned long size) {
unsigned long addr;
// Top row of the table
printf("\nSize of the structure: %lu\n ", size);
for(int i = 0; i <= 0xf; i++) {
if(i == 8) printf(" ");
printf(" %x ", i);
}
uint8_t reverse_byte(uint8_t byte) {
byte = ((byte & 0x55) << 1) | ((byte & 0xAA) >> 1);
byte = ((byte & 0x33) << 2) | ((byte & 0xCC) >> 2);
byte = ((byte & 0x0F) << 4) | ((byte & 0xF0) >> 4);
return byte;
}