Skip to content

Instantly share code, notes, and snippets.

View parnurzeal's full-sized avatar

Theeraphol Wattanavekin parnurzeal

View GitHub Profile
@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]
@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 / 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 / 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 / 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}
source 'https://rubygems.org'
group :test do
gem 'chefspec', '~> 3.4.0'
gem 'foodcritic', '~> 3.0.3'
gem 'strainer', '~> 3.0'
gem 'test-kitchen', '~> 1.2.1'
gem 'knife-spork', '~> 1.3.2'
gem 'hipchat', '~> 1.1.0'
gem 'guard', '~> 1.8.3'
Vagrant::Config.run do |config|
# debug default is :headless
config.vm.boot_mode = "gui"
# the .box file
config.vm.box = "afa-chef-server"
config.vm.box_url = "/V3/base_debian/with-apt.box"
# ssh config
config.ssh.private_key_path = "afa_private_key"
git checkout master
COOKBOOK=`git log -1 --pretty=%s | awk '{print $1}'`
VERSION=`git log -1 --pretty=%s | awk '{print $2}'`
# In case, Jenkins commit merge before build
if [ "$COOKBOOK" == "Merge" ] ; then
COOKBOOK=`git log -2 --pretty=%s | tail -1 | awk '{print $1}'`
VERSION=`git log -2 --pretty=%s | tail -1 | awk '{print $2}'`
fi
@parnurzeal
parnurzeal / gist:74d0a3082bb56a607639
Created September 11, 2014 09:09
go_routine_writing_file.go
func doKickoff2(opts Option) {
scriptName := opts.Kickoff2.ScriptName
configFile := opts.Kickoff2.ConfigFile
contentByte, err := ioutil.ReadFile(opts.Kickoff2.ConfigFile)
if err != nil {
log.Error("%v", err)
return
}
var config TomlConfig
_, err = toml.Decode(string(contentByte), &config)
@parnurzeal
parnurzeal / sails
Last active August 29, 2015 14:08
Dockerfile
#This is a comment
FROM centos:centos6
MAINTAINER Theeraphol Wattanavekin <[email protected]>
# Basic packages for work & troubleshooting
RUN yum update -y && yum install -y \
git \
vim \
zsh \
tar
RUN rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm