Skip to content

Instantly share code, notes, and snippets.

@weishai
weishai / Image-convert-to-Base64.js
Last active August 29, 2015 14:19
Image convert to Base64
function readImage(input) {
if ( input.files && input.files[0] ) {
var FR= new FileReader();
FR.onload = function(e) {
$('#img').attr( "src", e.target.result );
$('#base').text( e.target.result );
};
FR.readAsDataURL( input.files[0] );
}
}
@weishai
weishai / serializeObject.js
Last active August 29, 2015 14:05
serialize Object for Form
$.fn.serializeObject = function() {
var o = Object.create(null),
elementMapper = function(element) {
element.name = $.camelCase(element.name);
return element;
},
appendToResult = function(i, element) {
var node = o[element.name];
if ('undefined' != typeof node && node !== null) {
@weishai
weishai / console.log.pretty.js
Created August 5, 2014 07:52
console.log.pretty
console.log(function(){/*
if you want to join we,
please explain this !
*/}.toString().split(/\n/).slice(1,-1).join("\n"))
@weishai
weishai / jQuery.rotateOnAxisInIE.js
Created June 8, 2014 17:55
jQuery Rotate On Axis In IE
/**
* jQuery Rotate On Axis In IE Plugin 1.0.0
*
* Copyright (c) 2014 Aryeh Citron
*
* Licensed under MIT: http://www.opensource.org/licenses/mit-license.php
*/
(function ($)
@weishai
weishai / html5-canvas-guaguaka-desc.js
Last active August 29, 2015 14:02
Html5 Canvas 实现的可刮涂层效果
e.preventDefault();
mousedown = false;
var data=ctx.getImageData(0,0,w,h).data;
for(var i=0,j=0;i< data.length;i+=4){
if(data[i] && data[i+1] && data[i+2] && data[i+3]){
j++;
}
}
if(j<=w*h*0.1){
alert('ok');
@weishai
weishai / WeixinJS.js
Created June 4, 2014 07:26
微信JS部分接口
/**
* 微信网页端调用JS
* @author dodge
* @contact dodgepudding@gmail.com
* @link http://blog.4wer.com/wechat-timeline-share
* @version 1.1
*
* 自定义分享使用:
* WeixinJS.hideOptionMenu() 隐藏右上角按钮
* WeixinJS.hideToolbar() 隐藏工具栏
@weishai
weishai / css3-for-arrow-with-shadow.css
Last active August 29, 2015 14:02
css3 for arrow with shadow
.arrow{
width: 48px;
height: 48px;
background-color: #08c;
box-shadow: 1px 1px 4px #888;
transform: rotate(45deg);
-webkit-transform: rotate(45deg);
position: absolute;
left: -24px;
top: -24px;
@weishai
weishai / curl请求.php
Created May 31, 2013 18:45
curl请求实例
<?php
$data = array ('context' => '明天去打篮球');
$data = http_build_query($data);
$opts = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
"Content-Length: " . strlen($data) . "\r\n",
'content' => $data,
'timeout' => 10
@weishai
weishai / JsonUti.js
Last active December 17, 2015 22:59
简单的js代码可以实现格式化json,使用方法很简单: 网页换行和制表符不一样,设置一下 JsonUti.n = "<br />"; JsonUti.t = "&nbsp;&nbsp;&nbsp;"; document.getElementById("afterformat").innerHTML = JsonUti.convertToString(json); 需要注意,此处的json是JSON类型,如果是string的话需要先把string转成JSON格式。
var JsonUti = {
//定义换行符
n: "\n",
//定义制表符
t: "\t",
//转换String
convertToString: function(obj) {
return JsonUti.__writeObj(obj, 1);
},
//写对象
@weishai
weishai / change-wordpress-login-url.php
Last active December 17, 2015 19:58
修改wordpress默认登录地址
<?php
/* 修改wordpress默认登录地址 */
function wb_redir_login() {
wp_redirect(home_url('/').'/login'); //这个地址可以随意修改
exit;
}