Skip to content

Instantly share code, notes, and snippets.

View pipizhang's full-sized avatar
👽

Peter Zhang pipizhang

👽
View GitHub Profile
@pipizhang
pipizhang / aes_cryptojs_pycrypto.js
Created June 6, 2020 20:37 — forked from adrianlzt/aes_cryptojs_pycrypto.js
Interoperable CryptoJS (defaults) <-> PyCrypto
/*
* CryptoJS by default:
* - uses CBC mode
* - pkcs7 for padding
* - evpKDF to extract key
* - part of the key is used as IV
* - before converting to base64 it makes "Salt__"+salt+encrypted_text
*/
var CryptoJS = require('crypto-js');
@pipizhang
pipizhang / Jenkinsfile
Created May 26, 2020 18:26 — forked from lferro9000/Jenkinsfile
Jenkinsfile with PHP pipeline for Jenkins 2
#!/usr/bin/env groovy
node('php') {
stage('Get code from SCM') {
checkout(
[$class: 'GitSCM', branches: [[name: '*/#your-dev-branch#']],
doGenerateSubmoduleConfigurations: false,
extensions: [],
submoduleCfg: [],
@pipizhang
pipizhang / parser_phperror.rb
Last active May 6, 2020 10:09 — forked from vittee/parser_phperror.rb
Fluentd Parser Plugin for parsing PHP Error log
# vim: ts=2
#
require 'fluent/parser'
module Fluent
class TextParser
class PhpErrorParser < Parser
Plugin.register_parser('phperror', self)
config_param :xdebug, :bool, :default => false
@pipizhang
pipizhang / event.video.youtube.js
Created May 2, 2020 00:30 — forked from benwong/event.video.youtube.js
YouTube iFrame API wrapper for event videos
var EventYouTubeVideo = (function(){
var module = {};
module.init = function(){
var tag = document.createElement('script');
tag.src = "http://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
};
@pipizhang
pipizhang / install-comodo-ssl-cert-for-nginx.rst
Created July 17, 2018 22:15 — forked from bradmontgomery/install-comodo-ssl-cert-for-nginx.rst
Steps to install a Comodo PositiveSSL certificate with Nginx.

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@pipizhang
pipizhang / auto-ssh-add.sh
Created March 29, 2018 20:36
Automated ssh-add without enter passphrase
#!/usr/bin/expect
#author PeterZhang
set pass "YOUR_PASSPHRASE"
spawn ssh-add $HOME/.ssh/id_rsa
expect "*passphrase*" {send "$pass\r"}
interact
@pipizhang
pipizhang / sshrc
Last active November 17, 2020 04:43
Slack notifications for SSH login
#!/bin/bash
# Send login info to slack
IP=$(echo $SSH_CONNECTION | awk '{print $1}')
TIME=$(date -u "+%Y-%m-%d %H:%M:%S %Z")
MESSAGE="$(whoami) just connected to $(hostname) via $IP at $TIME"
SLACK_WEBHOOK="YOUR_SLACK_WEBHOOK"
slack_msg() {
cat <<EOF
@pipizhang
pipizhang / mysql_slow_report.sh
Last active March 29, 2018 20:37
Send MySQL slow query report to email
#!/bin/bash
SLOWDUMP="/opt/mysql/bin/mysqldumpslow"
EMAIL_TO="$YOUR_EMAIL"
SLOWLOG_FILE="/var/log/mysql-slow.log"
SLOWLOG_ALL="/var/log/mysql-slow-all.log"
text=$(cat "$SLOWLOG_FILE")
if [ "$text" != "" ]; then
echo "find update, send mail"
$SLOWDUMP $SLOWLOG_FILE | mutt -s "[BANANA] mysql slow query report" $EMAIL_TO
@pipizhang
pipizhang / all_trafic_socks5.sh
Created March 27, 2018 18:23
Redirect all trafic through Shadowsocks
#!/bin/bash
SERVER=""
PORT=8080
PASSWORD=""
iptables -t nat -N SHADOWSOCKS
iptables -t mangle -N SHADOWSOCKS
# Ignore your shadowsocks server's addresses
@pipizhang
pipizhang / iciba.sh
Last active March 27, 2018 18:27
A simple english translator via w3m
#!/bin/bash
w3m "http://www.iciba.com/$@"