Skip to content

Instantly share code, notes, and snippets.

View nyrahul's full-sized avatar
🐞

Rahul Jadhav nyrahul

🐞
View GitHub Profile
@nyrahul
nyrahul / bashrc_ext
Created January 11, 2018 07:41
Set netns name and git branch name in bash-PS1
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
netns_name() {
str=`ip netns identify $$`
[[ "$str" != "" ]] && echo "\033[1;35m[$str]\033[0m " && return
}
export PS1="$(netns_name)\u@\h:\[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\$ "
ssh -L 4000:192.168.56.102:80 127.0.0.1
# 4000 = Remote port
# 192.168.50.102 = Remote IP
# 80 = Local port
# 127.0.0.1 = Local IP
What this means?
Whatever packets come to 127.0.0.1:80 forward it to 192.168.56.102:4000
@nyrahul
nyrahul / perf_stats.sh
Created March 9, 2018 09:52
Get Perf statistics over multiple run and show it in column format
#!/bin/bash
OUTFILE=perf_out.txt
rm perf*.txt
for((i=0;i<4;i++)); do
#timeout -s SIGINT 12 perf stat -e dTLB-loads -e cs,cycles,instructions -D 2000 -a -o perf$i.txt
#timeout -s SIGINT 12 perf stat -e dTLB-stores -e cs,cycles,instructions -D 2000 -a -o perf$i.txt
#timeout -s SIGINT 12 perf stat -e dTLB-load-misses,dTLB-store-misses -e cs,cycles,instructions -D 2000 -a -o perf$i.txt
timeout -s SIGINT 12 perf stat -e cs,cycles,instructions -D 2000 -a -o perf$i.txt
@nyrahul
nyrahul / parse_cmdargs.sh
Created April 4, 2018 02:13
bash parse cmd args
usage()
{
echo "Usage: $0 <options>"
}
parse_cmdargs()
{
# -s | --server is the short and long option to be parsed
# Remember to specify : in cases where argument is nessary both in short and long options
OPTS=`getopt -o s: --long server:xyz: -n 'parse-options' -- "$@"`
#!/bin/bash
set -E
trap 'echo Failed at $lineno COMMAND: $BASH_COMMAND && exit 1' ERR
SRV_IP="192.168.106.2"
SP_IP="192.168.105.2"
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -F
#!/bin/bash
[[ "`whoami`" != "root" ]] && echo "Got to be root. Use sudo." && exit
export LOG_LEVEL=DBG
export OVERRIDE_IP=192.168.100.100
./server_proxy &
sleep 1
sysctl -w net.ipv4.ip_forward=1
Verifying my Blockstack ID is secured with the address 1FhDaxSAbL7yf78wAgtZshqvt7EJsC4mfx https://explorer.blockstack.org/address/1FhDaxSAbL7yf78wAgtZshqvt7EJsC4mfx
@nyrahul
nyrahul / clang-format-config
Last active September 11, 2018 04:08
My clang-format
---
Language: Cpp
# BasedOnStyle: LLVM-Modified-by-RJ
AccessModifierOffset: -2
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
Iptables ip/port range spec:
Multiple individual ports:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 110,143,993,955 -j MARK --set-mark 13
Port Range:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 1024:3000 -j MARK --set-mark 13
Multiple Port ranges:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 1000:2000,3000:4000 -j MARK --set-mark 13
@nyrahul
nyrahul / my_cmds.sh
Last active March 1, 2019 14:31
important command ref
#!/bin/bash
#socat examples:
#recv msgs on udp port 60K and print to stdout. recv input on stdin and sendto connected socket.
socat - UDP4-LISTEN:60000
socat - UDP4-SENDTO:192.168.106.2:60000
# send contents of t.c to multiple TCP4 servers
socat GOPEN:t.c - | tee >(socat - tcp4:127.0.0.1:12345) >(socat - tcp4:127.0.0.1:33455) > /dev/null