Skip to content

Instantly share code, notes, and snippets.

View codeasashu's full-sized avatar
🌊
Waiting to sail

ashutosh chaudhary codeasashu

🌊
Waiting to sail
View GitHub Profile
@codeasashu
codeasashu / vim-cheatsheet.md
Last active November 7, 2019 06:06
My Vim cheatsheet

Basics (Should know)

  1. [[ Goto function definition starting from cursor position
  2. '', `' Return to previous cursor position
  3. { Go back to previous linegap, } go to next linegap
  4. dgg Remove from current position to begining of file
  5. dG Remove from current to end of file
  6. #, * search and highlight the word under current cursor in the whole file.
  7. ma to set mark at position a, 'a to go to line at mark a, or `a to go to exact column at a
  8. gd to go to local variable initialisation. (gd = Goto Declaration)
@codeasashu
codeasashu / docker-compose.yaml
Created December 18, 2018 08:48
Yaml learning center
version: '3'
services:
consul-agent-1: &consul-agent
image: consul:latest
networks:
- consul-demo
command: "agent -retry-join consul-server-bootstrap -client 0.0.0.0"
@codeasashu
codeasashu / entrypoint.sh
Created January 9, 2019 10:06
Restrict docker container access from internet except for few allowed ips
#
# iptables configuration
#
# The following allows in- and outbound traffic
# within a certain `CIDR` (default: `192.168.0.0/24`),
# but blocks all other network traffic.
#
ALLOWED_CIDR1=172.0.0.0/16
ALLOWED_CIDR2=13.233.249.192
@codeasashu
codeasashu / Dockerfile
Created January 20, 2019 20:41
Steps to launch a consul server deamon
FROM python:3
EXPOSE 8000
CMD ["python", "-m", "http.server"]
@codeasashu
codeasashu / entrypoint.sh
Created February 5, 2019 09:20
Docker gotchas
#!/bin/bash
## Below script allows to fetch private github/gitlab repo
## Assume, $PRIVATE_SSH =
## -----BEGIN OPENSSH PRIVATE KEY-----
## b3BlbnNzaC1rZXktdjEAAAAABG5.....
cat > /root/.ssh/id_rsa <<EOF
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5.....
@codeasashu
codeasashu / getes.sh
Last active March 8, 2019 14:03
Get Elasticsearch Data
#!/bin/sh
##Useage: ./getes.sh
## To dry run query: ./getes.sh -v -x POST -d '{a:b}' http://elasticurl
## To actually run query: ./getes.sh -x POST -d '{a:b}' http://elasticurl
## Default action is search, so you can omitt -x GET switch
METHOD="GET"
DATA="{}"
DRYRUN=0
@codeasashu
codeasashu / default.conf
Created March 21, 2019 20:30
nginx json logging
#log_format custom '$request_body';
log_format custom '$remote_addr - $remote_user [$time_local] '
'"$request" $status $bytes_sent '
'"$http_referer" "$http_user_agent" "$request_body"';
log_format json_combined escape=json
'{'
'"time_local":"$time_local",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
  1. Toggle hidden files I

  2. Create new file at given directory cursor: ma

@codeasashu
codeasashu / greps.txt
Created April 8, 2019 08:23
Some better Regexes
1. Extract all (PHP) requests from apache access.log:
grep -Eo '"POST /[a-zA-Z0-9_ ]+/[a-zA-Z0-9_]+.php HTTP/1.1"' access.log
2. find all urls in a folder across all files:
grep -rnEo "(http|https)://[a-zA-Z0-9./?=_-]*" folder/
3. SED delete range of lines in a huge text files:
sed -i '21,141d' file
@codeasashu
codeasashu / git-cheatsheet.md
Last active October 18, 2019 17:01
Git cheatsheet