Archive

Archive for the ‘零敲碎打’ Category

VBS实现目录下所有文件归集

August 25th, 2017 No comments

一个简单的需求:
Windows 环境下用VBS/VBA来实现抽取某一个特定目录下的全部所有文件,要求遍历当前目录下所有的子目录。
注意各子目录下文件的文件名可能会重复,各子目录下存在空目录的情况。

实现VBS代码

'需要遍历的目录路径
dim strDirPath = "c:\dir"
 
'遍历目录
Private Sub FileTree(strPath)
    Set obFso = CreateObject("Scripting.FileSystemObject")
    If obFso.FolderExists(strPath) Then
        Set obFolder = obFso.GetFolder(strPath)
        '遍历当前目录下的所有目录,递归调用
        Set obSubFolders = obFolder.SubFolders
        For Each obSubFolder In obSubFolders
            Call FileTree(obSubFolder.Path & "")
        Next
        '剔除当前目录
        If strPath = Trim(strDirPath) Then
            Exit Sub
        End If
        '遍历当前目录下的所有文件
        Set obFiles = obFolder.Files
        For Each obFile In obFiles
            Call ExcuteFolderConcentrate(obFile.Path & "")
        Next
    Else
        MsgBox "Invalide Path"
        Exit Sub
    End If
End Sub
 
'文件归集操作
Private Sub ExcuteFolderConcentrate(strPath)
    Set obFso = CreateObject("Scripting.FileSystemObject")
    If obFso.FileExists(strPath) Then
        fullPath = Trim(strDirPath) & “\"
        '按目录层级设置新文件名
        newFileName = Replace(Right(strPath, Len(strPath) - Len(fullPath)), "\", "_”)
        '重复文件重新命名
        If obFso.FileExists(fullPath & newFileName) Then
            Call obFso.copyFile(strPath, fullPath & newFileName & ".duplicate")
        Else
            Call obFso.copyFile(strPath, fullPath & newFileName)
        End If
    End If
End Sub
 
'遍历整个目录,完成文件归集
FileTree (strDirPath)
'重新打开目录文件夹
CreateObject("Shell.Application").Explore strDirPath
Categories: 语言编程, 零敲碎打 Tags: ,

让WeCenter支持Github第三方登录功能

February 27th, 2017 1 comment

WeCenter 是一款知识型的社交化问答社区程序,专注于社区内容的整理、归类和检索,并通过连接微信公众平台,移动APP进行内容分发。

因为网站是一个技术支持社区,需要用到Github的第三方登录功能,WeCenter官方不支持Github的第三方登录,干脆自己写了一个。
基于Google的Oauth代码简单实现了Github 第三方登录功能,支持用github账户登录到WeCenter问答系统。

测试网址:http://faq.android-charts.com/
实现功能和演示效果请参考附件图片
Read more…

nginx对wordpress的sitemap插件生成的URL进行rewrite

February 27th, 2017 No comments

WordPress 默认使用apache的URL改写,一般修改.htaccess文件即可。如果使用nginx+php-fpm模式的服务器,需要自己进行重写URL。
nginx+php-fpm模式下,Yoast SEO和Google Sitemap Generator两款Sitemap插件可以使用一下配置实现Nginx对SitemapURL的重写。

Read more…

VMwareESX/ESXi 虚拟硬盘精简置备与厚置备转换

December 19th, 2016 No comments

VMware ESX/ESXi 虚拟硬盘精简置备与厚置备转换可以在SSH模式下使用vmkfstools命令直接进行转换。精简置备与厚置备转换涉及虚拟磁盘操作,操作时注意备份数据。

1.thin转换为thick,可以直接使用inflate模式进行转换。

vmkfstools -j thin2thick.vmdk

vmkfstools命令进行磁盘inflate

# vmkfstools -j  <source-disk-name.vmdk> 
-j可以替换为--inflatedisk

Read more…

Categories: 零敲碎打 Tags:

Windows Server 2012 GUI与Core的切换

December 19th, 2016 No comments

使用Hyper-V方案对服务器进行虚拟化实验,为了节省时间和提高安全性,安装Windows Server 2012 时直接安装成Microsoft Server 2012 Core。安装完毕后只有一个cmd命令提示符可以用。服务器管理各种不方便,考虑切换为GUI模式后再切换为Core模式。

切换GUI模式需要手动安装Windows Server的GUI组件
Server-Gui-Mgmt-Infra
Server-Gui-Shell
使用
Install-WindowsFeature
Uninstall-WindowsFeature
命令即可完成Windows功能的安装和删除

Read more…

[Linux]Java获取本机网卡IP地址

December 1st, 2016 No comments

应用程序服务器由Windows环境整体迁移到Linux环境,出现了不能获取本机IP地址的问题
原因是下面一段JAVA代码在Linux下直接返回127.0.0.1。Windows下有效的InetAddress貌似在linux下不起作用。

public static String getLocalIP() {
    String ip = "";
        try {
            InetAddress address = InetAddress.getLocalHost();
            if(address != null) {
                ip = address.getHostAddress();
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
    return ip;
}

原因在于Java使用的JNI代码调用的是Linux中的gethostname内核函数
这个函数在Linux主机没有绑定IP的情况下根据Host文件定义返回默认的localhost或者127.0.0.1。
Read more…

Categories: 系统管理, 零敲碎打 Tags: , ,

将SS的加密算法改为chacha20

August 15th, 2016 No comments

Shadowsocks更换加密算法后可以提高密钥加密和解密速度,同时可以规避GFW利用OpenSSL特性进行特征包跟踪的问题。

环境确认,安装编译工具

# Debian/Ubuntu
apt-get install build-essential
# CentOS
yum groupinstall "Development Tools"

下载、编译和安装libsodium1.0.11,支持chacha20

# 下载libsodium
 
wget https://github.com/jedisct1/libsodium/releases/download/1.0.11/libsodium-1.0.11.tar.gz
tar xvf libsodium-1.0.11.tar.gz
 
# 编译&安装
cd libsodium-1.0.11
./configure && make && make install
 
# 更新动态库
ldconfig

Read more…

Categories: 零敲碎打 Tags: ,