Skip to content

Instantly share code, notes, and snippets.

@xyqfer
xyqfer / select.text.js
Created September 28, 2013 07:21
文本框中选择指定长度的文本
function selectText(textbox, startIndex, stopIndex) {
if (textbox.setSelectionRange) {
textbox.setSelectionRange(startIndex, stopIndex);
} else if (textbox.createTextRange) {
var range = textbox.createTextRange();
range.collapse(true);
range.moveStart("character", startIndex);
range.moveEnd("character", stopIndex - startIndex);
range.select();
}
@xyqfer
xyqfer / type.js
Created September 28, 2013 07:22
对象类型检测
var toType = function(obj) {
return Object.prototype.toString.call(o).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
}
@xyqfer
xyqfer / array.prototype.js
Created September 28, 2013 07:24
Array.prototype
// forEach
if (typeof Array.prototype.forEach != "function") {
Array.prototype.forEach = function (fn, context) {
for (var k = 0, length = this.length; k < length; k++) {
if (typeof fn === "function") {
fn.call(context, this[k], k, this);
}
}
};
@xyqfer
xyqfer / upload.img.php
Created September 28, 2013 07:28
php上传生成缩略图-等比例无损压缩,可填充补充色
<?php
error_reporting( E_ALL );
 
// 测试
imagezoom('1.jpg', '2.jpg', 400, 300, '#FFFFFF');
 
/*
    php缩略图函数:
        等比例无损压缩,可填充补充色 author: 华仔
    主持格式:
@xyqfer
xyqfer / curl.php
Created September 28, 2013 07:31
php-curl
<?php
$url='http://twitter.com/statuses/user_timeline/16387631.json'; //rss link for the twitter timeline
print_r(get_data($url)); //dumps the content, you can manipulate as you wish to
/* gets the data from a URL */
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
@xyqfer
xyqfer / cookie.js
Created September 28, 2013 07:35
cookie
@xyqfer
xyqfer / no.cache.php
Created September 28, 2013 07:38
防止浏览器缓存
<?php
header("Expires: Tue, 01 Jul 2001 06:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
@xyqfer
xyqfer / ip.php
Created September 28, 2013 07:40
获得用户IP
function get_clientip(){
if(isset($_SERVER)){
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])){
$realip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif (isset($_SERVER['HTTP_CLIENT_IP'])){
$realip = $_SERVER['HTTP_CLIENT_IP'];
}else{
$realip = $_SERVER['REMOTE_ADDR'];
}
}else{
@xyqfer
xyqfer / socket.php
Created September 28, 2013 07:44
使用Sockets获取网页内容
/**
* Returns the contents of a web page
*
* Opens a remote web document, and returns the contents. This method
* uses sockets to get the document. Returns the contents of the document with
* the headers being stored in the $headers variable.
* This method can handle 301 and 302 redirects, but will return false
* if anything other than those status codes, or a 200, is returned by
* the web server.
*
@xyqfer
xyqfer / opacity.css
Created September 28, 2013 07:47
透明效果
selector {
opacity: .75; /* Standard: FF gt 1.5, Opera, Safari */
filter: alpha(opacity=75); /* IE lt 8 */
-ms-filter: "alpha(opacity=75)"; /* IE 8 */
-khtml-opacity: .75; /* Safari 1.x */
-moz-opacity: .75; /* FF lt 1.5, Netscape */
}