Skip to content

Instantly share code, notes, and snippets.

@rainly
rainly / z.md
Created March 24, 2019 02:09 — forked from mischah/z.md
Installing und initializing z (https://github.com/rupa/z) with help of Homebrew.

#The power of z

Do you spend lots of time doing things like this?

cd this/is/the/path/that/i/want/so/i/type/it/all/out/to/get/whereiwant

With z, you could just do this:

pred='process matches ".*(ocker|vpnkit).*"
  || (process in {"taskgated-helper", "launchservicesd", "kernel"} && eventMessage contains[c] "docker")'

/usr/bin/log stream --style syslog --level=debug --color=always --predicate "$pred"
@rainly
rainly / gen_Corefile.sh
Created January 16, 2019 07:10 — forked from missdeer/gen_Corefile.sh
generate Corefile which uses your ISP's DNS servers to resolve domain names in China and uses OpenDNS/Cloudflare/Google DNS servers to resolve domain names outside China for CoreDNS. You should change 116.228.111.118 180.168.255.18 to your ISP's DNS server address or use public DNS server such as 114/DNSPod etc. directly.
#!/bin/bash
echo ". {" > Corefile
echo " forward . 208.67.222.222:443 208.67.222.222:5353 208.67.220.220:443 208.67.220.220:5353 tls://1.0.0.1 tls://8.8.8.8 tls://8.8.4.4 {" >> Corefile
china=`curl https://cdn.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/accelerated-domains.china.conf -s | while read line; do awk -F '/' '{print $2}' | grep -v '#' ; done | paste -sd " " -`
apple=`curl https://cdn.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/apple.china.conf -s | while read line; do awk -F '/' '{print $2}' | grep -v '#' ; done | paste -sd " " -`
google=`curl https://cdn.jsdelivr.net/gh/felixonmars/dnsmasq-china-list/google.china.conf -s | while read line; do awk -F '/' '{print $2}' | grep -v '#' ; done | paste -sd " " -`
echo " except $china $apple $google" >> Corefile
echo " }" >> Corefile
echo " proxy . 116.228.111.118 180.168.255.18" >> Corefile
echo " log" >> Corefile
@rainly
rainly / decrypt_pdf.py
Created October 10, 2018 14:27 — forked from linyiru/decrypt_pdf.py
Decrypt password-protected PDF in Python.
# Decrypt password-protected PDF in Python.
# cleaned-up version of http://stackoverflow.com/a/26537710/329263
#
# Requirements:
# pip install PyPDF2
#
# Usage: decrypt_pdf('encrypted.pdf', 'decrypted.pdf', 'secret_password')
import sys
from PyPDF2 import PdfFileReader, PdfFileWriter
@rainly
rainly / checkportconn.sh
Created September 30, 2018 08:28 — forked from chenshaoju/checkportconn.sh
Check Service Port Connection Status
#!/bin/sh
#
# Change "currentserverport" Port 443 if not correct.
currentsship=$(w |grep pts/0 |awk '{print $3}')
currentserverip=$(ifconfig eth0 |grep broadcast |awk '{print $2}')
currentserverport="443"
currentserveripport=$currentserverip":"$currentserverport
@rainly
rainly / bear.css
Created September 8, 2018 13:05 — forked from Kenshin/bear.css
Bear Theme with Typora 👉 http://ksria.qiniudn.com/[email protected]
/**
* Bear Theme with Typora
*
* @version : 0.0.1
* @update : 2018/09/08
* @homepage: https://gist.github.com/Kenshin/e5adc79da3149315bdfd72a35b70d65e
* @license : MIT https://github.com/kenshin/mduikit/blob/master/LICENSE
* @author : Kenshin Wang <[email protected]>
*
* @copyright 2018
@rainly
rainly / wireguard_config.txt
Created September 3, 2018 02:38 — forked from diyism/wireguard_config.txt
wireguard config
=====server side /etc/wireguard/wg0.conf:
[Interface]
PrivateKey = <privkey>
ListenPort = 24444
SaveConfig = false
Address = 10.0.0.1/32
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
[Peer]
@rainly
rainly / 指定nginx工作在第二个cpu上
Created August 31, 2018 02:36 — forked from diyism/指定nginx工作在第二个cpu上
指定nginx工作在第二个cpu上,跟php错开cpu
公司一台2个CPU共8核的服务器访问量上来后top里load高达8到17,但cpu占用却只有Cpu(s): 50%us,可能是static模式下启动php-fpm全起在第一个cpu上了,尝试把nginx的进程指定到第二个cpu上,负载马上降到2左右了:
有8个核心的话可以把nginx分到第二个cpu的1,3,5,7这4个核上, php5-fpm则默认跑在第一个cpu的0,2,4,6核心, 在nginx.conf里:
worker_processes 4;
worker_cpu_affinity 00000010 00001000 00100000 10000000; #不要用worker_cpu_affinity 10101010; 不均衡
sudo service nginx restart
第二个cpu的具体核心序号要先看看核心分布:
grep -P '^physical id' /proc/cpuinfo
比如4*2核不超线程的可能是:01 01 01 01 也可能是 00 11 00 11, 还可能是10 10 10 10(奇怪的是这些机器不论01先后,0号cpu的负载总是比1号大得多)
4*2核超线程的可能是:0000 1111 0000 1111
在top里看到某个php进程占用cpu很高想知道对应的request url:
php 5.3以上有fpm status page功能(http://php.net/manual/en/install.fpm.configuration.php#pm.status-path), 但是从网页访问的,
改用cgi-fcgi从命令行访问比较安全方便, cgi-fcgi就是cgi(nginx) to fcgi(php5-fpm)的意思
sudo vi /etc/php5/fpm/pool.d/www.conf
#解除注释 pm.status_path = /status
sudo service php5-fpm restart
sudo apt-get install libfcgi0ldbl #centos是yum install fcgi (先sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm 及 sudo yum upgrade ca-certificates --disablerepo=epel)
sudo SCRIPT_FILENAME=. SCRIPT_NAME=/status QUERY_STRING="full" REQUEST_METHOD=GET cgi-fcgi -bind -connect /var/run/php5-fpm.sock | grep -A7 <pid>
#boot into exist linux in /dev/sda1
#download iso file into for example: /home/malcolm/Downloads/lubuntu-18.04-desktop-amd64.iso
#sudo subl /boot/grub/grub.cfg:
menuentry 'Lubuntu 18.04 ISO' {
set isofile='/home/malcolm/Downloads/lubuntu-18.04-desktop-amd64.iso'
loopback loop (hd0,1)$isofile
linux (loop)/casper/vmlinuz boot=casper iso-scan/filename=$isofile noprompt noeject
initrd (loop)/casper/initrd.lz
}
#sudo reboot