Skip to content

Instantly share code, notes, and snippets.

View libo1106's full-sized avatar

libo libo1106

View GitHub Profile
@libo1106
libo1106 / get_post_excerpt
Created October 12, 2013 17:15
WordPress中文摘要,按字数截取
function get_post_excerpt($post, $excerpt_length=240){
if(!$post) $post = get_post();
$post_excerpt = $post->post_excerpt;
if($post_excerpt == ''){
$post_content = $post->post_content;
$post_content = do_shortcode($post_content);
$post_content = wp_strip_all_tags( $post_content );
$post_excerpt = mb_strimwidth($post_content,0,$excerpt_length,'…','utf-8');
@libo1106
libo1106 / socket-server.php
Last active December 23, 2015 19:59
php socket demo
#!/usr/local/bin/php -q
<?php
error_reporting(E_ALL);
/* Allow the script to hang around waiting for connections. */
set_time_limit(0);
/* Turn on implicit output flushing so we see what we're getting
* as it comes in. */
ob_implicit_flush();
@libo1106
libo1106 / gist:6589293
Created September 17, 2013 02:14
黏贴图片
document.getElementById("rte").focus();
document.body.addEventListener("paste", function(e) {
for (var i = 0; i < e.clipboardData.items.length; i++) {
if (e.clipboardData.items[i].kind == "file" && e.clipboardData.items[i].type == "image/png") {
// get the blob
var imageFile = e.clipboardData.items[i].getAsFile();
// read the blob as a data URL
var fileReader = new FileReader();
fileReader.onloadend = function(e) {
@libo1106
libo1106 / gist:6532287
Created September 12, 2013 01:50
webkit-tap-highlight-color
/* lets try a lighter blue... */
html {
-webkit-tap-highlight-color: rgba(201, 224, 253, 0.8);
}
/* for some buttons or links, simply hide the selection color all together */
.no-highlight {
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
}
function isUrl(s) {
var regexp = /((http|https):\/\/)?[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2}/;
return s.indexOf(' ') < 0 && regexp.test(s);
}
isUrl('http://baidu.com/')
@libo1106
libo1106 / gist:6268515
Last active December 21, 2015 07:08
proxy for file_get_contents()
<?php
$proxy = stream_context_create(array(
'http' => array(
'timeout' => 5,
'proxy' => 'tcp://proxy.domain.com:8080',
'request_fulluri' => True,
)
));
$page = file_get_contents('http://www.baidu.com/', false, $proxy);
echo($page);
@libo1106
libo1106 / gist:6208819
Last active December 20, 2015 22:59
isMSIE
// 判断是否IE
function isMSIE(){
var match = /(msie) ([\w.]+)/.exec( navigator.userAgent.toLowerCase() );
if(match !== null){
return true;
}else{
return false;
}
}
@libo1106
libo1106 / gist:6183485
Created August 8, 2013 10:19
未知高度垂直居中
<!--
高版本浏览器可以直接使用table-cell配合vertical-align来实现垂直居中。
IE6\7则需要多一个容器,调整定位来实现
-->
<style>
.wrap{
width:500px;height:300px;border:3px solid #ddd;margin:0 auto;padding:20px;display:table;
*position:relative;
}
@libo1106
libo1106 / big-bg-img
Created July 16, 2013 10:30
自适应大背景
/*
* background-attachment: fixed必须有,保证浏览器完整渲染背景图
*/
html {
background: url(images/perfect-full-page-bg.jpg) no-repeat center center fixed;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
}
@libo1106
libo1106 / gist:5956669
Created July 9, 2013 11:31
让软件走代理
Proxifier工具