Skip to content

Instantly share code, notes, and snippets.

@lilongen
lilongen / redis-delete-all-matching-keys
Created April 26, 2016 06:16
Delete all keys in redis matching a regular expression
# Deleting all keys in redis that match a regular expression
# General
redis-cli [options] KEYS "prefix:*" | xargs redis-cli [options] DEL
# If authorization is needed
redis-cli -a <AUTH> KEYS "prefix:*" | xargs redis-cli -a <AUTH> DEL
# If no authorization is needed
redis-cli KEYS "prefix:*" | xargs redis-cli DEL
@lilongen
lilongen / perl-edit-file-like-sed
Last active April 26, 2016 06:54
perl-edit-file-like-sed, perl stream-edit file like sed, use perl to edit file like sed, sed file using perl
examples:
1). modify file using regular expression pattern single-line mode ( '.' and '\s' match '\n')
perl -i -p0E 's|(<artifactId>api</artifactId>[^<]+<version>)(bbb)(</version>)|\1a\3|g' pom.xml
2). modify file using regular expression pattern multi-line mode
perl -i -pE 's|(<artifactId>api</artifactId>[^<]+<version>)(bbb)(</version>)|\1a\3|g' pom.xml
3). do not modify file actually, just print the changed contents
perl -p0E 's|(<artifactId>api</artifactId>[^<]+<version>)(bbb)(</version>)|\1a\3|g' pom.xml
@lilongen
lilongen / kdc-configure-file-contents
Last active April 26, 2016 07:04
KDC configure files example
# /etc/krb5.conf
[logging]
default = FILE:/var/log/krb5libs.log
kdc = FILE:/var/log/krb5kdc.log
admin_server = FILE:/var/log/kadmind.log
[libdefaults]
dns_lookup_realm = false
ticket_lifetime = 24h
@lilongen
lilongen / postgresql-usage-examples
Last active April 29, 2016 07:48
PostgreSQL install and usage examples
* install
# yum install postgresql-server postgresql-contrib
# postgresql-setup initdb
* allow passowrd authentication & remote access
# vi /var/lib/pgsql/data/pg_hba.conf
host all all 127.0.0.1/32 ident
host all all ::1/128 ident
->
host all all 127.0.0.1/32 md5
@lilongen
lilongen / detect-new-added-hard-disk-without-reboot-vmware-linux-guest
Last active May 6, 2016 08:36
How To Detect a New Hard Disk Without Rebooting VMware Linux Guest
# ls /sys/class/scsi_host/ | while read host ; do echo "- - -" > /sys/class/scsi_host/$host/scan ; done
from
http://wingloon.com/2013/05/07/how-to-detect-a-new-hard-disk-without-rebooting-vmware-linux-guest/
@lilongen
lilongen / enable-ntp-on-centos
Last active May 10, 2016 01:36
enable ntp on centos
* install ntp
yum install ntp
* edit /etc/ntp.conf
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
* enable ntp service
centos 7
@lilongen
lilongen / tsung.md
Created June 16, 2016 01:55 — forked from clasense4/tsung.md
Install tsung centos 7

Install tsung centos 7

yum -y install erlang perl perl-RRD-Simple.noarch perl-Log-Log4perl-RRDs.noarch gnuplot perl-Template-Toolkit
wget http://tsung.erlang-projects.org/dist/tsung-1.6.0.tar.gz
tar xfz tsung-1.6.0.tar.gz
cd tsung-1.6.0
./configure && make && make install

mkdir /root/.tsung
@lilongen
lilongen / mysql.support.utf8mb4
Last active July 27, 2016 07:17
mysql support utf8mb4
https://mathiasbynens.be/notes/mysql-utf8mb4
my.cnf
...
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
@lilongen
lilongen / mongo-date-range-query
Created January 5, 2017 09:59
mongo-date-range-query
var objIdMin = ObjectId(Math.floor((new Date('1990/10/10'))/1000).toString(16) + "0000000000000000")
var objIdMax = ObjectId(Math.floor((new Date('2011/10/10'))/1000).toString(16) + "0000000000000000")
db.myCollection.find({_id:{$gt: objIdMin, $lt: objIdMax}})
@lilongen
lilongen / mysql57.usage
Last active January 29, 2018 03:17
mysql5.7 usage after install
1. MySQL5.7+ generates a temporary random password after installation and stored in /var/log/mysqld.log
2. get the temporay password to reset root password
grep "A temporary password is generated for root" /var/log/mysqld.log
3. a. mysql> uninstall plugin validate_password;
b. /etc/my.cnf
validate_password_policy=LOW