Skip to content

Instantly share code, notes, and snippets.

@shangdev
shangdev / inotify+rsync实时同步文件
Last active November 16, 2017 17:27
Centos6.8: inotify+rsync install
1. 检查你的服务器版本是否支持inotify机制,如果输出 CONFIG_INOTIFY_USER=y 则表示支持
$ grep INOTIFY_USER /boot/config-$(uname -r)
2. 编译安装inofity-tools工具包
$ wget http://github.com/downloads/rvoicilas/inotify-tools/inotify-tools-3.14.tar.gz
$ tar -zxvf inotify-tools-3.14.tar.gz
$ ./configure --prefix=/usr --libdir=/lib64 && make && make install
3. 脚本
#!/bin/bash
@shangdev
shangdev / ZipArchive
Created November 10, 2017 06:30
PHP遍历目录并下载文件
$zip = new \ZipArchive();
if ( $zip->open( $zip_name, \ZipArchive::CREATE ) !== true ) {
wp_die( 'Can not open file, or file creation failed' );
}
foreach ( $files_path as $path ) {
if ( file_exists( $path ) ) {
$zip->addFile( $path, basename( $path ) );
}
}
$zip->close();
@shangdev
shangdev / Nginx install and Add-module
Last active November 17, 2017 06:30
Nginx install and Add-module in centos
############################
## 安装Nginx
############################
首先安装必要的库(nginx 中gzip模块需要 zlib 库,rewrite模块需要 pcre 库,ssl 功能需要openssl库)。选定/usr/local为安装目录,以下具体版本号根据实际改变。
1.安装PCRE库
$ cd /usr/local/
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.38.tar.gz
$ tar -zxvf pcre-8.38.tar.gz
$ cd pcre-8.38
proxy_cache_path /var/nginx/cache/aws/trueniu levels=2:2:2 use_temp_path=off keys_zone=aws_3:500m inactive=30d max_size=10g;
server {
listen 80;
server_name trueniu.com www.trueniu.com;
if ( $scheme = http ) {
return 301 https://www.trueniu.com$request_uri;
}
}
@shangdev
shangdev / the_posts_pagination
Created September 23, 2017 17:01
归档页分页函数 the_posts_pagination 的使用
/**
* The pagenation
* @info 每页显示数量设置:设置->阅读->博客页面至多显示
*/
the_posts_pagination( array(
'prev_text' => '«',
'next_text' => '»',
) )
@shangdev
shangdev / paginate_links
Created September 23, 2017 16:56
WP_Query 中 paginate_links 的使用。
@shangdev
shangdev / Delete Default Jquery
Created August 5, 2017 10:44
Wordpress:function.php写入取消默认Jquery的引入
// Delete System Jquery
function delete_jquery() {
if ( is_admin() ) return;
wp_deregister_script('jquery');
}
add_action('wp_enqueue_scripts', 'delete_jquery');
@shangdev
shangdev / Change Import Jquery.js method
Created August 3, 2017 12:30
Change Import Jquery.js method
//Making jQuery Google API
function modify_jquery() {
if (!is_admin()) {
// comment out the next two lines to load the local copy of jQuery
wp_deregister_script('jquery');
}
}
add_action('init', 'modify_jquery');
@shangdev
shangdev / Google Map API 移动友好处理
Created July 31, 2017 16:59
Google Map API 移动友好处理
官方文档:https://developers.google.com/maps/documentation/javascript/interaction?hl=zh-cn
<script>
/**
* Google Map
*/
function initMap() {
var uluru = {lat: 34.318877, lng: 108.948488};
var map = new google.maps.Map(document.getElementById('c_map'), {
center: uluru,
/**
* robots.txt
*
* @param string $output The output of the robots.txt file
* @return string $public If the site is public facing
*/
function robots_mod( $output, $public ) {
$output .= "Disallow: /wp-includes/\n";
$output .= "Disallow: /wp-content/plugins/\n";
$output .= "Allow: /\n";