Skip to content

Instantly share code, notes, and snippets.

View liyang85's full-sized avatar

Yang Li liyang85

View GitHub Profile
@liyang85
liyang85 / ChromeAppDownloader.py
Last active August 12, 2020 05:45 — forked from arulrajnet/ChromeAppDownloader.py
Python 2 script to download the Chrome Extensions (CRX) file directly from the google chrome web store.
#! /usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Python Script to download the Chrome Extensions (CRX) file directly from the Google Chrome Web Store.
Referred from http://chrome-extension-downloader.com/how-does-it-work.php
"""
from __future__ import division
import argparse
@liyang85
liyang85 / pyenv_build_python.sh
Last active July 31, 2020 08:34
There is a more simple method than modifying build script, which is at the bottom of this gist. pyenv's built-in `python-build` script doesn't support Tk, so we have to modify it. (According to https://github.com/pyenv/pyenv/issues/1375#issuecomment-524280004)
#!/usr/bin/env bash
#
# Usage: python-build [-kpv] <definition> <prefix>
# python-build --definitions
# python-build --version
#
# -k/--keep Do not remove source tree after installation
# -p/--patch Apply a patch from stdin before building
# -v/--verbose Verbose mode: print compilation status to stdout
# -4/--ipv4 Resolve names to IPv4 addresses only
@liyang85
liyang85 / Great tutorials for git
Last active November 5, 2019 03:27
Git snippets
https://githowto.com/
@liyang85
liyang85 / set_env_after_centos_minimal_installation.sh
Created April 20, 2018 08:02
在虚拟机中最小化安装CentOS之后,配置网络、关闭SELinux和防火墙、配置EPEL仓库、安装常用软件、下载dotfiles。 https://github.com/liyang85/scripts-during-mage-linux-training/blob/master/01_improving/set_env_after_centos_mini_install_by_liyang.sh
#!/bin/bash
#
#===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
# Filename: set_env_after_centos_mini_install_by_liyang.sh
# Description:
# Date: 2018-01-07
# Author: Li Yang
# Website: https://liyang85.com
#===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
#!/bin/bash
# vim: set fdm=marker:
#
#===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
# Filename: auto_compile_lamp_by_liyang.sh
# Description:
# Date: 2018-02-14
# Author: Li Yang
# Website: https://liyang85.com
#===== ===== ===== ===== ===== ===== ===== ===== ===== ===== ===== =====
@liyang85
liyang85 / httpd init.d script.sh
Created December 3, 2017 14:29
For compiled httpd and can work on CentOS 6.
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: The Apache HTTP Server is an efficient and extensible \
# server implementing the current HTTP standards.
# processname: httpd
# config: /app/httpd22/conf
# config: /etc/sysconfig/httpd
@liyang85
liyang85 / Compile GNU Screen 4.6.2 in CentOS 6.sh
Created December 3, 2017 13:45
CentOS 6 shipped Screen 4.00.03 cannot support vertical split region!
yum -y install ncurses-devel
./configure
make && make install
install -m 644 etc/etcscreenrc /etc/screenrc
@liyang85
liyang85 / Extract one file from an rpm package.sh
Created December 3, 2017 13:44
must use rpm2cpio and cpio, or no other way can do this.
# find the target file in the package
rpm2cpio httpd-2.2.15-59.el6.centos.x86_64.rpm | cpio -tv | grep "init.d/httpd"
# view content of the target file then redirect it
rpm2cpio httpd-2.2.15-59.el6.centos.x86_64.rpm | cpio -i --to-stdout ./etc/rc.d/init.d/httpd > /etc/rc.d/init.d/httpd
@liyang85
liyang85 / validation (name and IP address) in bash.sh
Created November 25, 2017 12:49
另一种验证IP的方法。要点: ①直接把变量值包含的空格替换为下划线 ②匹配IP的正则表达式要更具体 ③在Bash中测试regex **不要** 使用任何引号! https://stackoverflow.com/a/13015572/3025050
#!/bin/bash
read name
while [[ ! "$name" =~ '[A-Za-z ]' ]]; do
read -p "Wrong name format. Re-enter: " name
done
name="${name// /_}"
read ip
@liyang85
liyang85 / Validating an IP Address.md
Last active November 25, 2017 12:48
①首先验证输入的IP是由圆点分成的四段,且每段内容为1-3位数字 ②然后把四段内容用圆点分隔,存入数组 ③最后验证数组每一个元素小于等于255 http://www.linuxjournal.com/content/validating-ip-address-bash-script

To belabor the obvious: IP addresses are 32 bit values written as four numbers (the individual bytes of the IP address) separated by dots (periods). Each of the four numbers has a valid range of 0 to 255.

The following bash script contains a bash function which returns true if it is passed a valid IP address and false otherwise. In bash speak true means it exits with a zero status, anything else is false. The status of a command/function is stored in the bash variable "$?".

#!/bin/bash

# Test an IP address for validity:
# Usage:
#      valid_ip IP_ADDRESS