Skip to content

Instantly share code, notes, and snippets.

View xuanyu-h's full-sized avatar
🎯
Focusing

xuanyu xuanyu-h

🎯
Focusing
  • Shanghai
View GitHub Profile
class ArrayBlockingQueue
attr_reader :capacity, :queue
def initialize(capacity = 5)
@capacity = capacity
@lock = Mutex.new
@empty = ConditionVariable.new
@full = ConditionVariable.new
@queue = []
end
@xuanyu-h
xuanyu-h / Tecmint_monitor.sh
Created July 25, 2018 06:52
Tecmint_monitor.sh
####################################################################################################
# Tecmint_monitor.sh #
# Written for Tecmint.com for the post www.tecmint.com/linux-server-health-monitoring-script/ #
# If any bug, report us in the link below #
# Free to use/edit/distribute the code below by #
# giving proper credit to Tecmint.com and Author #
# #
####################################################################################################
#! /bin/bash
# unset any variable which system may be using
@xuanyu-h
xuanyu-h / vpnsetup-centos.sh
Last active July 4, 2018 15:17
vpnsetup-centos
#!/bin/sh
#
# Script for automatic setup of an IPsec VPN server on CentOS/RHEL 6 and 7.
# Works on any dedicated server or virtual private server (VPS) except OpenVZ.
#
# DO NOT RUN THIS SCRIPT ON YOUR PC OR MAC!
#
# The latest version of this script is available at:
# https://github.com/hwdsl2/setup-ipsec-vpn
#
@xuanyu-h
xuanyu-h / shadowsocks.service
Created July 4, 2018 14:56
shadowsocks.service
[Unit]
Description=Shadowsocks
[Service]
TimeoutStartSec=0
ExecStart=/usr/local/bin/ssserver -c /usr/etc/shadowsocks.json
[Install]
WantedBy=multi-user.target
@xuanyu-h
xuanyu-h / sshd_config.sh
Created July 4, 2018 14:16
sshd_config.sh
Port 2202
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
UsePrivilegeSeparation yes
@xuanyu-h
xuanyu-h / haproxy.conf
Created April 8, 2018 08:24 — forked from thpham/haproxy.conf
test config haproxy for gRPC loadbalancing
global
tune.ssl.default-dh-param 1024
defaults
timeout connect 10000ms
timeout client 60000ms
timeout server 60000ms
frontend fe_http
mode http
@xuanyu-h
xuanyu-h / Vagrantfile
Created January 3, 2018 03:19
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
BOX_NAME = ENV['BOX_NAME'] || "centos/7"
VAGRANTFILE_API_VERSION = "2"
CONSUL_ENCRYPT = "eEZJ2MTe0keJc2EkvZ+l3Q=="
CONSUL_DATACENTER = "nyc"
CONSUL_DATA_DIR = "/var/consul"
CONSUL_NODE_IP = {
@xuanyu-h
xuanyu-h / SnowFlake.java
Created December 29, 2017 03:12
Twitter 雪花算法
/**
* @author Spirit
* @date 2017/12/14
*/
/**
* Twitter 雪花算法
*
* 0 - 0000000000 0000000000 0000000000 0000000000 0 - 00000 - 00000 - 000000000000
* 1 位标识
@xuanyu-h
xuanyu-h / config.py
Last active December 22, 2017 02:41
python context??
from functools import wraps
def print_method_name(f):
@wraps(f)
def decorated(*args, **kwargs):
print("enter function: {0}, {1}, {2}".format(f.__name__, args, kwargs))
return f(*args, **kwargs)
return decorated
@xuanyu-h
xuanyu-h / singleton.py
Created December 20, 2017 07:31
Python 单例模式
class AuthManager(object):
"""Authentication Manager."""
def __new__(cls):
singleton = cls.__dict__.get('__singleton__')
if singleton is not None:
return singleton
cls.__singleton__ = singleton = object.__new__(cls)