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 / raspberryPi_torrentbox.md
Last active December 5, 2018 12:16
Using Raspberry Pi as Torrentbox

Raspberry Pi as a TorrentBox

Instead of running your computer day and night to download GBs of torrents, we are going to use Raspberry Pi as a always on TorrentBox.

Step 1: OS installation

We are going to use Ubuntu Mate on our Pi. You can download your Pi image from https://ubuntu-mate.org/raspberry-pi/ .

After the installation we'll proceed to our next step.

@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 / sem_open problem.md
Last active November 5, 2018 10:33
unable to compile sem_open in UBUNTU

Problem

/tmp/ccz11fg4.o: In function `main':
firstCode.c:(.text+0x24): undefined reference to `sem_open'
firstCode.c:(.text+0x34): undefined reference to `sem_post'
firstCode.c:(.text+0x4c): undefined reference to `sem_wait'

Solution

Link with pthread library.

@jadia
jadia / samba_share.md
Last active November 20, 2018 08:58
Locally share folder in Ubuntu 18.04

Sharing a folder in Ubuntu 18.04

sudo apt-get install samba
sudo apt-get install samba-common-bin

Back up and edit config file

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.old
@jadia
jadia / ssh_prevention_tips.md
Last active November 24, 2018 11:26
Tips to prevent unauthorized SSH login to your server
  • change your ssh port (common)

  • drop packets from unknown IP address if you have a reliable source range.

  • add multi factor authentication

  • port knocking

  • scheduled firewall/service (only run ssh when you need it, emergency access via console)

@jadia
jadia / dpkg_error.md
Last active December 1, 2018 11:11
How To Solve “sub process usr bin dpkg returned an error code 1″ Error in Ubuntu

I was having problem with lvm package.

dpkg: error processing package lvm2 (--configure):  
installed lvm2 package post-installation script subprocess returned error exit status 1  
Processing triggers for initramfs-tools (0.130ubuntu3.5) ...  
update-initramfs: Generating /boot/initrd.img-4.15.0-39-generic  
Errors were encountered while processing:  
lvm2  
E: Sub-process /usr/bin/dpkg returned an error code (1)  
@jadia
jadia / wget_folder.md
Created December 3, 2018 08:16
Download everything in URL folder
wget -r --no-parent http://www.example.com/somedir/

-r recursive Download

--no-parent Don´t download anything from the parent directory

@jadia
jadia / wrong_epel.md
Created December 3, 2018 20:04
How to remove EPEL 7.0 repo from CentOS 6.5

Remove the previous epel release and install the correct one.

yum remove epel-release
wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -ihv epel-release-6-8.noarch.rpm
@jadia
jadia / yesNoInC.md
Last active January 17, 2019 12:00
Yes/No option in C program

I had the following code and the yes no functionality won't work.

printf("\nDo you wish to add more records? [y/n] ");
		scanf("%c", &choice);
		printf("\nYour choice: %c\n", choice);
		if (choice != 'y')
		{
			printf("Making choice false.");
 addMore = false;
@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]