Skip to content

Instantly share code, notes, and snippets.

View hansrajdas's full-sized avatar

Hansraj Das hansrajdas

  • India
  • 04:14 (UTC +05:30)
View GitHub Profile
@hansrajdas
hansrajdas / golang-debugging.md
Last active April 14, 2024 16:04
Golang debugging

Run golang test with dlv

Below command will run the tests defined in current package

dlv test

# If Go version is outdated
dlv test --check-go-version=false

# Ignore protobuf conflict
GOLANG_PROTOBUF_REGISTRATION_CONFLICT=warn dlv test --check-go-version=false
@hansrajdas
hansrajdas / postgres.md
Last active September 23, 2023 14:29
Postgres commands

Connect to postgres DB

Install psql and use below command from shell

psql postgres://username:password@hostname:5432/db_name

# With some params
psql postgres://username:password@hostname:5432/db_name?application_name=root_connection

Postgres commands

@hansrajdas
hansrajdas / python-inbuilt.md
Created January 27, 2023 19:55
Python inbuilt functions are faster/optimized

Python inbuilt functions are faster/optimized

Taken a simple example: Generate a list 100 million number then sum them all using below 2 ways

First, using python's sum function on list

s = [i for i in range(100000000)]
f = sum(s)
print(f)
@hansrajdas
hansrajdas / docker.md
Last active January 26, 2022 19:16
Docker basic commands

Containers

  • Application + library dependencies
  • Lightweight as compared to using VM for each application
  • Uses cgroups to restrict resource allocation of each container

Docker

  • Docker uses LXC containers
  • Dcoker container solves compatibilty issues for different components running on different OS
  • Docker utilises kernel so we can run same docker containers on different flavours of linux kernal based OS like redhat, ubuntu, debian, etc
  • Dcoker packages containers and ships them to run on any OS we want
@hansrajdas
hansrajdas / kubernetes.md
Last active June 7, 2024 19:30
Kubernetes

Overview

  • Automatically deploying and managing container is called container orchestration
  • K8s is an container orchestration tool/technology
  • Other alternatives of K8s are docker swarm and mesos

Cluster architecture

  • K8s cluster is a set of machines (or nodes) running in sync
  • One of the node is master node, responsible for actual orchestration
  • kube-scheduler schedules pods on nodes based on node capacity, load on node and other policies. This runs in kube-system namespace
  • kubelet runs on worker node which listens for instructions from kube-apiserver and manages containers
@hansrajdas
hansrajdas / git.md
Last active October 3, 2021 08:58
git versioning

Version control systems(VCS)

  • Local VCS: Files stored on local machines
  • Centralised VCS: A centralised system where the main repository is stored. Eg: CVS, SVN, Perforce
  • Distributed VCS: Each client doesn't just check out the latest snapshot of the files; rather, they fully mirror the repository, including its full history. Eg: Git, Mercurial, Bazzar.

Other VCS like CVS, SVN, Bazzar stores delta changes after every commit(in each version of project), instead git stores snapshots of projects in every version(some file may have reference to previous, if that file was not updated)

Everything is local

  • Git is fast as everything is local in git. While working other repository systems like SVN and CVS we need to be connected to the server to commit anything but with git we can commit locally also and when connected to the server we can push the changes.
  • Also we can see the history of the project as it stores everything on local drive
@hansrajdas
hansrajdas / vim.md
Last active June 19, 2024 22:27
VIM commands

Acronym

  • C-a ==> CTRL-a

Modes in VIM

  • Normal mode(n) When we open mode, the default mode is normal
  • Insert mode(i) When we want to insert some text, we press i, a or A etc to go in insert mode
  • Command mode(c) When we type colon(:) from normal mode, we enters command mode
  • Visual mode(v) Using v or V or C-i

Start VIM

@hansrajdas
hansrajdas / terminator.md
Last active December 23, 2019 20:11
Basic terminator commands
ctrl+shift+o  Split horizontally
ctrl+shift+e  Split vertically
ctrl+shift+x  Maximize current window(in splitted one), press again to have splitted view
ctrl+shift+t  Opens a new tab in terminator window
ctrl+shift+i  Opens a new terminator window
ctrl+         Increase font size
ctrl-         Decrease font size
ctrl+0        Reset font size
ctrl+pageUp Goto previous tab
@hansrajdas
hansrajdas / tmux.md
Last active September 10, 2023 07:44
TMUX basic commands
@hansrajdas
hansrajdas / commands.md
Last active September 30, 2021 15:49
Some shell commands used frequently

Redo last command but as root

sudo !!

Open an editor(for composing) to run a long command

ctrl + x + e