文章分类 » code

Mount network location in Golang on Windows

import (
	"syscall"
	"unsafe"
)

type NETRESOURCE struct {
	Scope        uint32
	Type         uint32
	DisplayType  uint32
	Usage        uint32
	lpLocalName  *uint16
	lpRemoteName *uint16
	lpComment    *uint16
	lpProvider   *uint16
}

func MountWindowsNetworkLocation(location string, username string, password string) error {
	h := syscall.MustLoadDLL("mpr.dll")
	c := h.MustFindProc("WNetAddConnection2W")

	nr := NETRESOURCE{
		Type:         uint32(1),
                // lpLocalName: syscall.StringToUTF16Ptr("R:"), uncomment this line to map a local device
		lpRemoteName: syscall.StringToUTF16Ptr(location),
	}
        dwFlags := uint32(1)

	r1, _, err := c.Call(uintptr(unsafe.Pointer(&nr)),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(password))),
		uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(username))), uintptr(dwFlags))

	if r1 != 0 {
		return err
	}

	return nil
}

wordpress 隐藏非主页的侧边栏

function bluehua_hide_widgets($sidebars_widgets) {
    if (is_home()) {
        return $sidebars_widgets;
    } else {
        return array();
    }
}

add_filter('sidebars_widgets', 'bluehua_hide_widgets', 10);

Mac OS X重命名磁盘卷标

加了块ssd硬盘,默认的分区名是 “未命名1”, 有点二,改了个好理解的。

$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk1s2 on /Volumes/Macintosh HD (hfs, local, journaled)
$sudo diskutil rename /dev/disk0s2 "SSD盘"

php-fpm 5.3.3 rpm package with root privileges for centos/redhat 6

出于安全的考虑从源里面安装的php-fpm是不允许以root权限运行的

ERROR: [pool www] please specify user and group other than root

但是有些时候确实需要root权限,可以使用我打的开放root版本

php-fpm-5.3.3-1.i_want_root.el6.i386.rpm
php-fpm-5.3.3-1.i_want_root.el6.x86_64.rpm

如果想打其他php版本的包,可以修改下面的脚本使用

#!/bin/sh
yum install rpm-build gcc make subversion wget
yum install bzip2-devel gmp-devel zlib-devel pcre-devel libxml2-devel openssl-devel
test ! -f ./autoconf-2.13-8.noarch.rpm && wget "http://rpm.bluehua.org/php-fpm/autoconf-2.13-8.noarch.rpm"
rpm -e autoconf
rpm -ivh ./autoconf-2.13-8.noarch.rpm
#修改源码版本
test ! -f ./php-5.3.3.tar.bz2 && wget "http://museum.php.net/php5/php-5.3.3.tar.bz2"
tar jxvf ./php-5.3.3.tar.bz2
cd php-5.3.3/
rm -rf ./sapi/fpm/
#选择适当的php-fpm版本
svn co http://svn.php.net/repository/php/php-src/branches/PHP_5_3_10/sapi/fpm/ ./sapi/fpm
./buildconf --force
test ! -f ./php-fpm-build-rpm.tar.gz && wget "http://rpm.bluehua.org/php-fpm/php-fpm-build-rpm.tar.gz"
tar zxvf ./php-fpm-build-rpm.tar.gz
#修改php-fpm.spec中的版本号
rpmbuild -bb ./php-fpm.spec

开始提供坑爹的找不到的rpm下载

php-sqlite-5.3.3-1.el6.i686.rpm
php-sqlite-5.3.3-1.el6.x86_64.rpm

之后碰到找不到的包都会打好放到这里~