Skip to content

Instantly share code, notes, and snippets.

View jadia's full-sized avatar
💭
Progress beats Perfect.

Nitish Jadia jadia

💭
Progress beats Perfect.
View GitHub Profile
@jadia
jadia / malloc_calloc_memset.md
Created October 19, 2018 13:30
How Malloc+memset and calloc works

The short version:

Always use calloc() instead of malloc()+memset(). In most cases, they will be the same. In some cases, calloc() will do less work because it can skip memset() entirely. In other cases, calloc() can even cheat and not allocate any memory! However, malloc()+memset() will always do the full amount of work.

Understanding this requires a short tour of the memory system.

Quick tour of memory

There are four main parts here: your program, the standard library, the kernel, and the page tables. You already know your program, so...

Memory allocators like malloc() and calloc() are mostly there to take small allocations (anything from 1 byte to 100s of KB) and group them into larger pools of memory. For example, if you allocate 16 bytes, malloc() will first try to get 16 bytes out of one of its pools, and then ask for more memory from the kernel when the pool runs dry. However, since the program you're asking about is allocating for a large amount of memory at once, `mal

@jadia
jadia / locale_issue_zsh.md
Created August 3, 2019 07:14
zsh (anon):12: character not in range error

zsh | (anon):12: character not in range

Solution:

sudo apt-get install -y language-pack-en
sudo update-locale

Then zsh starts working!

@jadia
jadia / docker-compose.yaml
Created January 2, 2021 22:38
Run postgres and pgAdmin on Docker for practice
version: '3'
services:
postgres:
image: postgres
hostname: postgres
ports:
- "5432:5432"
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
@jadia
jadia / docker-compose.jenkins-dind.yml
Created July 29, 2020 03:42 — forked from adelmofilho/docker-compose.jenkins-dind.yml
Docker-in-Docker approach to run Jenkins as a Docker container
# This docker-compose file intent to create a multi-container application
# that runs a Jenkins container connected via TLS to a Docker-in-Docker (dind) container as Docker daemon.
#
# Advice about this approach can be found at:
# http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/
#
# As well discussion about another alternatives on this setup can be found at:
# https://forums.docker.com/t/using-docker-in-a-dockerized-jenkins-container/322/11
#
# Quick reference about Docker-in-Docker can be fount at:
@jadia
jadia / extract_libffmpeg.so.md
Last active July 5, 2020 05:05
Facebook cannot run videos in Opera and firefox

REFER TO BELOW video_fix_opera.md FILE FIRST. THIS IS A BACKUP METHOD IF THAT METHOD DOESN'T WORK

If you do not get the file from your system, you can extract the file from the chromium package. Follow below instructions to get the package. Original post. Copied here, just in case owner decides to delete the gist.

Install libffmpeg.so in vivaldi

This short instruction shows how to install libffmpeg.so in vivaldi to play e.g. mp4 videos.

@jadia
jadia / rename_with_suffix.md
Created May 27, 2020 15:51
Add suffix to file names

Add .zip suffix to all files starting with name test

bash -c "ls test* | xargs -I {} mv {} {}.zip"
@jadia
jadia / gpg_error.md
Last active March 28, 2020 16:43
Github, SSH - gpg failed to sign the data

GPG sign issue when commiting the message

error: gpg failed to sign the data
fatal: failed to write commit object

sudo apt install -y pinentry-tty && \
sudo update-alternatives --config pinentry
@jadia
jadia / grep_through_files.md
Created March 13, 2020 11:54
Grep through all the files in the folder

Grep through all the files in the folder

Search through directory and sub-directories

grep -r stuffToSearch ./*

Search only specific files

@jadia
jadia / qemu_image_convert.md
Created October 16, 2019 07:46
Convert VDI images to IMG or QCOW2 in QEMU

Convert VDI images to IMG or QCOW2 in QEMU

qemu-img convert -f vdi -O qcow2 vm.vdi vm.qcow2
@jadia
jadia / newVMimage.md
Last active October 4, 2019 05:19
Create new qcow2 image for KVM
sudo qemu-img create -f qcow2 ~/VOLUME-NAME.qcow2 30G
                                 ^[name of storage]