if (jQuery.datepicker) {
    jQuery.datepicker.setDefaults({
        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
        dayNamesShort: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
        dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
        monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
        monthNamesShort: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'],
        weekHeader: '周',
        nextText: '下月&#x3e',
        prevText: '&#x3c上月',
        closeText: '完成',
        currentText: '今天',
        yearSuffix: '年'
    });
}

/*扩展 jQuery.browser 的属性*/
if (!jQuery.browser) {
    jQuery.browser = {};
}
jQuery.extend(jQuery.browser, {
    /*检查浏览器是否支持CSS3*/
    css3: (function () {
        var css3Div = document.createElement('div');
        if ('border-radius' in css3Div.style) {
            css3Div.style['border-radius'] = '3px';
            return css3Div.style['border-radius'] == '3px';
        }
        else {
            return false;
        }
    })(),
    /*检查浏览器是否支持HTML5*/
    html5: (function () {
        return !!document.createElement('canvas').getContext;
    })()
});
jQuery.widget("ui.tabs", $.ui.tabs, {
    addTab: function (options) {
        var _self = this;
        options = $.extend({
            title: 'New Tab', //标题
            content: '', //内容
            id: 'tab_' + new Date().getTime(), //Id
            enableClose: true, //是否允许关闭
            activate: true //是否激活
        }, options || {});

        var id = "tabs-" + options.id;
        var tab = this.element.find('.ui-tabs-nav li[aria-controls="' + id + '"]');
        if (tab.length < 1) {
            var _li = $('<li></li>').append($('<a></a>').attr('href', '#' + id).html(options.title));
            this.element.find(".ui-tabs-nav").append(_li);
            var _div = $('<div></div>');
            _div.attr('id', id);
            _div.append(options.content);
            this.element.append(_div);
            if (options.enableClose) {
                var _closeBtn = $('<span class="ui-icon ui-icon-close" role="presentation" title="关闭"></span>').click(function () {
                    var _this = $(this);
                    var panelId = _li.remove().attr("aria-controls");
                    $("#" + panelId).remove();
                    if (_li.hasClass('ui-tabs-active')) {
                        _self.element.tabs('option', 'active', _self.element.find(".ui-tabs-nav li").length - 1);
                    }
                });
                _li.append(_closeBtn);
            }
            this.refresh();
            if (options.activate) {
                this._activate(this.element.find(".ui-tabs-nav li").length - 1);
            }
            //解决不支持css3的浏览器问题
            if (!$.browser.css3) {
                _div.height(this.element.innerHeight() - this.element.css('padding-top').replace('px', '') - this.element.find(".ui-tabs-nav").outerHeight(true) - Math.mul(_div.css('margin-top').replace('px', ''), 2));
            }
        } else if (options.activate) {
            var activeIndex = this.element.find(".ui-tabs-nav li").index(tab);
            this._activate(activeIndex);
        }
    }
});

namespace Provider.Payment.Alipay
{
    public class AlipayUtil
    {
        /// <summary>
        /// 生成签名
        /// 相关文档:https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.vwCvxF&treeId=62&articleId=104741&docType=1
        /// </summary>
        /// <param name="obj">要签名的对象</param>
        /// <param name="signKey">签名密匙</param>
        /// <returns>签名字符串</returns>
        public static string GenerateSign(object entity, string signKey)
        {
            SortedDictionary<string, object> sorted = GetSortedDictionary(entity);
            return GenerateSign(sorted, signKey);
        }
        /// <summary>
        /// 生成签名
        /// </summary>
        /// <remarks>
        /// 相关文档:https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.vwCvxF&treeId=62&articleId=104741&docType=1
        /// </remarks>
        /// <param name="obj">要签名的对象</param>
        /// <param name="signKey">签名密匙</param>
        /// <returns>签名字符串</returns>
        public static string GenerateSign(SortedDictionary<string, object> sorted, string signKey)
        {
            StringBuilder builder = new StringBuilder();
            foreach (KeyValuePair<string, object> pair in sorted)
            {
                if (pair.Key != "sign" && pair.Key != "sign_type")
                {
                    object value = pair.Value;
                    Type type = pair.Value.GetType();
                    if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>))
                    {
                        type = type.GetGenericArguments()[0];
                    }
                    if (type == typeof(DateTime))
                    {
                        value = Convert.ToDateTime(value).ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    builder.Append(pair.Key + "=" + value + "&");
                }
            }
            string str = builder.Remove(builder.Length - 1, 1).ToString() + signKey;
            string sign = MD5Encrypt(str);
            return sign;
        }
        /// <summary>
        /// 获得属性值并排序
        /// </summary>
        /// <param name="entity">参数</param>
        /// <returns></returns>
        protected static SortedDictionary<string, object> GetSortedDictionary(object entity)
        {
            Type type = entity.GetType();
            PropertyInfo[] propertys = type.GetProperties();
            SortedDictionary<string, object> sorted = new SortedDictionary<string, object>();
            foreach (PropertyInfo property in propertys)
            {
                Type propertyType = property.GetType();
                object objValue = null;
                if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
                {
                    bool HasValue = (bool)type.GetProperty("HasValue").GetValue(entity, null);
                    if (HasValue)
                    {
                        objValue = type.GetProperty("Value").GetValue(entity, null);
                    }
                }
                else
                {
                    objValue = property.GetValue(entity, null);
                }
                string value = (objValue ?? "").ToString();
                if (!String.IsNullOrEmpty(value))
                {
                    sorted.Add(property.Name, value);
                }
            }
            return sorted;
        }
        /// <summary>
        /// MD5加密
        /// </summary>
        protected static string MD5Encrypt(string input)
        {
            MD5 md5 = MD5.Create();
            byte[] bytes = Encoding.UTF8.GetBytes(input);
            byte[] buffer = md5.ComputeHash(bytes);
            StringBuilder builder = new StringBuilder();
            foreach (byte b in buffer)
            {
                builder.Append(b.ToString("x2"));
            }
            return builder.ToString();
        }
    }
}

前言

Deluge是一个功能齐全的跨平台BitTorrent 客户端软件,可在Linux, OS X, Unix和Windows操作系统下工作。它使用libtorrent作为其后端,有包括GTK+,网络远程客户端,命令行模式等多种用户界面。其设计方针是体积小巧且节约系统资源,通过丰富的插件来实现核心以外的众多功能。Deluge响应Freedesktop.org的倡议,兼容于GNOME, KDE, XFCE和其它多种桌面环境。它还是一款自由软件,使用GPLv3进行授权。

1、安装 deluge

sudo apt-get install deluge

2、安装 deluge web 管理面板

sudo apt-get install deluged deluge-web deluge-console

deluge 的安装目录在 /usr/lib/python2.7/dist-packages/deluge

如果出现add-apt-repository: command not found错误,执行:

sudo apt-get install python-software-properties

3、创建 deluged.service 配置文件

sudo vi /etc/systemd/system/deluged.service

复制粘贴:

[Unit]
Description=Deluge Bittorrent Client Daemon
Documentation=man:deluged
After=network-online.target
[Service]
Type=simple
User=root
ExecStart=/usr/bin/deluged -d
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/deluged
Restart=on-failure
TimeoutStopSec=300
[Install]
WantedBy=multi-user.target

4、创建 deluge-web.service 配置文件

sudo vi /etc/systemd/system/deluge-web.service

复制粘贴:

[Unit]
Description=Deluge Bittorrent Client Web Interface
Documentation=man:deluge-web
After=network-online.target deluged.service
Wants=deluged.service
[Service]
Type=simple
User=root
ExecStart=/usr/bin/deluge-web
ExecStop=/usr/bin/kill /usr/bin/deluge-web
Restart=on-failure
[Install]
WantedBy=multi-user.target

5、启动 deluged 和 deluge-web 服务,并设置自启动

sudo systemctl start deluged
sudo systemctl enable deluged

sudo systemctl start deluge-web
sudo systemctl enable deluge-web

6、开启远程访问(可选)

deluge-web默认只允许本地访问。默认端口:8112,默认密码:deluge

#启用远程访问
deluge-console "config -s allow_remote True"

#禁用远程访问
deluge-console "config allow_remote"

访问地址:http://你的公网IP:8112

deluge web

到此,deluge 客户端配置基本完成。

deluge 官方网站:https://www.deluge-torrent.org/

解决configure: error: The Sodium crypto library libraries not found.错误。

1、下载并解压

wget https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable.tar.gz
tar -zxf libsodium-1.0.18-stable.tar.gz
cd libsodium-stable

备用下载地址:https://down.24kplus.com/linux/libsodium-1.0.18-stable.tar.gz

2、编译安装

./configure --prefix=/usr
make && make check
sudo make install
sudo ldconfig

如出现以下错误:

config.status: error: Something went wrong bootstrapping makefile fragments
     for automatic dependency tracking.  Try re-running configure with the
     '--disable-dependency-tracking' option to at least be able to build
     the package (albeit without support for automatic dependency tracking). 

执行:

yum install make -y

更多错误解决方案:https://www.24kplus.com/linux/400.html

1、先安装yum-utils

yum install yum-utils -y

2、设置yum repos

创建文件/etc/yum.repos.d/nginx.repo

sudo vi /etc/yum.repos.d/nginx.repo

复制粘贴:

[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key

[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key

默认情况下,安装稳定版(stable)nginx,如果要安装主线版本(mainline) nginx包,请运行以下命令:

sudo yum-config-manager --enable nginx-mainline

3、安装nginx

sudo yum install nginx -y

查看nginx版本

nginx -v

nginx version: nginx/1.16.0

3、启动 nginx

#启动
systemctl start nginx
#检查状态
systemctl status nginx
#设置自启动
systemctl enable nginx

到此,Nginx安装结束。

官方英文原文:http://nginx.org/en/linux_packages.html#RHEL-CentOS

CentOS 7/8 源码安装 mbedtls 2.16.3, 解决configure: error: mbed TLS libraries not found. 错误。

1、下载并解压

wget https://tls.mbed.org/download/mbedtls-2.16.3-gpl.tgz
tar -xf mbedtls-2.16.3-gpl.tgz
cd mbedtls-2.16.3

备用下载地址:https://down.24kplus.com/linux/mbedtls/mbedtls-2.16.3-gpl.tgz

2、编译安装

make
make DESTDIR=/usr install
ldconfig

如果出现 make[1]: python2: Command not found 错误,执行:

yum -y install python2

如果出现 /usr/bin/env: ‘perl’: No such file or directory 错误,执行:

yum -y install perl

CentOS 安装 shadowsocks-libev, 本教程仅提供学习,请勿用于商业用途和不法行为。

如果你觉得安装步骤繁杂,可以试试 一键安装 shadowsocks-libev

1、准备编译环境

CentOS 7

yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y

CentOS 8

yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel -y

2、获取shadowsocks-libev源码, 并安装

yum install git
git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init
./autogen.sh && ./configure --disable-documentation && make
sudo make install

如果出现 error: The Sodium crypto library libraries not found 错误,安装 libsodium

如果出现 error: mbed TLS libraries not found. 错误,安装 mbedtls

3、 创建配置文件

sudo mkdir /etc/shadowsocks-libev
sudo vi /etc/shadowsocks-libev/config.json

复制粘贴如下内容(注意修改密码“password”):

{
     "server":"0.0.0.0",
     "server_port":8388,
     "local_port":1080,
     "password":"password",
     "timeout":600,
     "method":"aes-256-cfb" ,
     "fast_open": false
 }

4、创建Shadowsocks-libev.service配置文件

sudo vi /etc/systemd/system/shadowsocks-libev.service

复制粘贴:

[Unit]
Description=Shadowsocks-libev Server
Documentation=https://shadowsocks.org/en/
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/ss-server -c /etc/shadowsocks-libev/config.json -u
Restart=on-abort

[Install]
WantedBy=multi-user.target

5、启动 Shadowsocks-libev 服务

sudo systemctl start shadowsocks-libev

6、设置开机启动

sudo systemctl enable shadowsocks-libev

至此, Shadowsocks-libev服务器端的基本配置已经全部完成了!

设置防火墙开放端口

开放 tcp/udp 8388 端口

firewall-cmd --zone=public --add-port=8388/tcp --permanent
firewall-cmd --zone=public --add-port=8388/udp --permanent

重新载入防火墙配置,使规则生效

sudo systemctl restart firewalld

优化 Shadowsocks-libev 直达航班: 优化 shadowsocks-libev 网络

最后送上Windows 客户端 Shadowsocks-4.1.7.1.zip

using System;
using System.Drawing;
using System.Drawing.Imaging;

namespace Utility
{
    public class ImageUtil
    {
        ///<summary>
        /// 生成缩略图
        /// </summary>
        /// <param name="originalImagePath">源图路径(物理路径)</param>
        /// <param name="thumbnailPath">缩略图路径(物理路径)</param>
        /// <param name="width">缩略图宽度</param>
        /// <param name="height">缩略图高度</param>
        /// <param name="mode">生成缩略图的方式</param>    
        public static void MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
        {
            Image originalImage = Image.FromFile(originalImagePath);

            int towidth = width;
            int toheight = height;

            int x = 0;
            int y = 0;
            int ow = originalImage.Width;
            int oh = originalImage.Height;

            switch (mode)
            {
                case "HW"://指定高宽缩放(可能变形)                
                    break;
                case "W"://指定宽,高按比例                    
                    toheight = originalImage.Height * width / originalImage.Width;
                    break;
                case "H"://指定高,宽按比例
                    towidth = originalImage.Width * height / originalImage.Height;
                    break;
                case "Cut"://指定高宽裁减(不变形)                
                    if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
                    {
                        oh = originalImage.Height;
                        ow = originalImage.Height * towidth / toheight;
                        y = 0;
                        x = (originalImage.Width - ow) / 2;
                    }
                    else
                    {
                        ow = originalImage.Width;
                        oh = originalImage.Width * height / towidth;
                        x = 0;
                        y = (originalImage.Height - oh) / 2;
                    }
                    break;
                default:
                    break;
            }
            //新建一个bmp图片
            Image bitmap = new Bitmap(towidth, toheight);
            //新建一个画板
            Graphics g = System.Drawing.Graphics.FromImage(bitmap);
            //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            //设置高质量,低速度呈现平滑程度
            //g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQualityBilinear
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
            //清空画布并以透明背景色填充
            g.Clear(Color.Transparent);
            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight), new Rectangle(x, y, ow, oh), GraphicsUnit.Pixel);
            try
            {
                //以jpg格式保存缩略图
                bitmap.Save(thumbnailPath, ImageFormat.Jpeg);
            }
            catch (System.Exception e)
            {
                throw e;
            }
            finally
            {
                originalImage.Dispose();
                bitmap.Dispose();
                g.Dispose();
            }
        }
    }
}

这是微软官方提供的解决方案,支持简体中午,繁体中文,韩语和日语。

需要安装依赖的 Visual Studio International Pack

下载地址:https://www.microsoft.com/zh-CN/download/details.aspx?id=15251

using System;
using System.Data;
using System.Configuration;
using Microsoft.International.Converters.PinYinConverter;

namespace Utility.Convert
{
    /// <summary>
    ///ChineseConvert 的摘要说明
    /// </summary>
    public class ChineseConvert
    {
        public ChineseConvert() { }

        /// <summary>
        /// 汉字转化为拼音
        /// </summary>
        /// <param name="str">汉字</param>
        /// <returns>全拼</returns>
        public static string GetPinyin(string str)
        {
            string r = string.Empty;
            foreach (char obj in str)
            {
                try
                {
                    ChineseChar chineseChar = new ChineseChar(obj);
                    string t = chineseChar.Pinyins[0].ToString();
                    r += t.Substring(0, t.Length - 1);
                }
                catch
                {
                    r += obj.ToString();
                }
            }
            return r;
        }

        /// <summary>
        /// 汉字转化为拼音首字母
        /// </summary>
        /// <param name="str">汉字</param>
        /// <returns>首字母</returns>
        public static string GetFirstPinyin(string str)
        {
            string r = string.Empty;
            foreach (char obj in str)
            {
                try
                {
                    ChineseChar chineseChar = new ChineseChar(obj);
                    string t = chineseChar.Pinyins[0].ToString();
                    r += t.Substring(0, 1);
                }
                catch
                {
                    r += obj.ToString();
                }
            }
            return r;
        }

    }
}