Skip to content

Instantly share code, notes, and snippets.

View parnurzeal's full-sized avatar

Theeraphol Wattanavekin parnurzeal

View GitHub Profile
@parnurzeal
parnurzeal / grep_too_long_line.sh
Last active August 29, 2015 13:58
A solution for grep a file with too long line. Usage: ./grep_too_long_line.sh FILE WORD_TO_CUT WORD_TO_FIND
#!/bin/bash
ORG_FILE=$1
WORD_TO_CUT=$2
WORD_TO_FIND=$3
zcat ${ORG_FILE} | sed 's/'${WORD_TO_CUT}'/'${WORD_TO_CUT}'\n/g' | grep ${WORD_TO_FIND}
@parnurzeal
parnurzeal / my.bash_profile
Last active August 29, 2015 13:56
my.bash_profile
# color my terminal
export CLICOLOR=1
export LSCOLORS=ExGxFxdxCxDxDxBxBxExEx
#sets up the prompt color (currently a green similar to linux terminal)
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$ '
#sets up proper alias commands when called
alias ls='ls -G'
alias ll='ls -hl'
alias subln='/Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl -n'
@parnurzeal
parnurzeal / sar_wanted_result.sh
Created December 25, 2013 00:53
Bash script for taking wanted average data from sar in wanted format. It needs a time file with have following format. /var/log/sa/sa20 10:00:00 11:00:00 13:30:20 14:10:00 19:30:00 20:00:00 . . .
#!/bin/bash
read -a words
SA_FILE=${words[0]}
echo $SA_FILE
printf "%9s%9s%9s%9s%9s%10s%10s\n" "Start" "End" "%user" "%system" "%iowait" "RX" "TX"
while read -a words; do
CPU=`sar -f $SA_FILE -s ${words[0]} -e ${words[1]} | grep Average | awk '{print $3" "$5" "$6}'`
NETWORK=`sar -n DEV -f $SA_FILE -s ${words[0]} -e ${words[1]} | grep Average | grep em3 | awk '{print $5" "$6}'`
printf "%9s%9s%9s%9s%9s%10s%10s\n" ${words[0]} ${words[1]} ${CPU[0]} ${CPU[1]} ${CPU[2]} ${NETWORK[0]} ${NETWORK[1]}
@parnurzeal
parnurzeal / easy_file_sharing.py.snippet
Last active February 19, 2020 14:14
This is easy snippet for easy_file_sharing.py which you can pass directly to your command line.
python -c 'import BaseHTTPServer; import CGIHTTPServer; import sys; import socket; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.connect(("www.google.com",8000)); ipaddr = s.getsockname()[0]; s.close(); print "="*36 ; print "Access: " + ipaddr +":"+str(9999); print "="*36 ; server=BaseHTTPServer.HTTPServer ; handler = CGIHTTPServer.CGIHTTPRequestHandler; server_address = ("",int(9999)); httpd = server(server_address, handler); httpd.serve_forever()'
@parnurzeal
parnurzeal / easy_file_sharing.py
Created May 30, 2013 02:40
This is very easy file sharing using python. It is very useful and easy when you want to download or sharing the files from servers behind proxy (which normally you need to do many steps before getting to the files). However, this is not secure. Please do use in internal network or as your own risk. Usage: 1.) put the file in sharing folder 2.) …
#!/usr/bin/python
import BaseHTTPServer
import CGIHTTPServer
import sys
import socket
def get_local_ip_address(target):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect((target,8000))
ipaddr = s.getsockname()[0]