2012年5月

以动手实践为荣,以只看不练为耻;//这个不错!多写代码才是王道
以打印日志为荣,以出错不报为耻;//打印日志???
以局部变量为荣,以全局变量为耻;//过多使用全局变量,破坏代码封装性
以单元测试为荣,以手工测试为耻;//某个模块功能(函数)是否按照你的意愿工作
以代码重用为荣,以复制粘贴为耻;//常用的东西写成类库,LIB,DLL,供其他程序调用
以多态应用为荣,以分支判断为耻;//动态调用派生类的虚函数
以定义常量为荣,以魔法数字为耻;//魔法数字?是到处都是数字的意思吧
以总结思考为荣,以不求甚解为耻。//该深入时要彻底搞懂,其余会用就行,讨厌强记

去方特玩了 没第一次那么有兴趣了 比较刺激的都玩了 还晕 真是晕死 难受死了
照片没找到好看了 等找到了在发

1、PHP Snips

一个提供PHP相关代码的网站。注意,此网站从4月20日起,开始使用 Nginx 服务器

2、DZone Snippets
一个综合性质的代码库,涵盖了25种编程语言。开发者注册以后,可以通过Tag和关键字方便的管理自己的代码库。

3、Code Beach
一个为Mac开发者提供代码的网站。该网站要求所上传代码必须能在Mac OS X下进行编译。

4、Code Keep
由于用户几乎每天提供大量代码,Code Keep已经成为一个很受开发者欢迎的网站。此网站提供的代码包含了C、C++、VB等编程语言。

5、Cats Who Code
Cats Who Code网站主要为网站开发者、网页设计师、网站管理员等提供相应的代码段。此网站目标是通过提供高质量的源代码和教程,使得网站开发变得简便、有趣。

6、Snipplr
Snipplr是一个庞大的代码资源库,用户可以在世界上任何一台联网的电脑上访问自己的代码库,同时,也可以和他人共享自己的代码库。

7、Code Codex

Code Codex是程序世界的Wiki。在这里,用户可以浏览、使用别人提交的优秀的代码;学到新的编程算法;提高社区里程序的性能。

8、Dev Snippets

这是一个主要提供有关Web设计与开发代码的网站。

9、Smipple

Smipple是一个用以和同事、朋友分享代码的站点。

10、Dream in Code
一个提供代码的站点,从CSS到程序设计,包含范围很广。

Code Snippets是一个公共代码库。开发者可以通过Tag和关键字方便的管理自己的代码库,并可以选择是否和分享它们。
12、Snipt
一个分享代码的站点,涵盖了CSS、SQL语句到C++等方面。

13、 byteMyCode

byteMyCode是一个方便开发者分享源代码的站点。同时,它还为用户提供了一个代码管理工具,方便用户管理自己的代码库。

英文原文:12 Most Useful Sites to Find Code Snippets

Hash passwords with salts
[php]
// Déclaration des constantes
define('PREFIX_SALT', 'bonjour');
define('SUFFIX_SALT', 'aurevoire');
$hashSecure = md5(PREFIX_SALT.'m0tDePasse'.SUFFIX_SALT);
[/php]
HP Database Config

[php]

$dbhost = '127.0.0.1';
$dbuser = 'root';
$dbpass = '';
$dbname = 'directory';

[/php]

Simple PHP Math Image Captcha

[php]
// captcha width
$captcha_w = 150;
// captcha height
$captcha_h = 50;
// minimum font size; each operation element changes size
$min_font_size = 12;
// maximum font size
$max_font_size = 18;
// rotation angle
$angle = 20;
// background grid size
$bg_size = 13;
// path to font - needed to display the operation elements
$font_path = 'fonts/courbd.ttf';
// array of possible operators
$operators=array('+','-','*');
// first number random value; keep it lower than $second_num
$first_num = rand(1,5);
// second number random value
$second_num = rand(6,11);
[/php]

ZIP File PHP code script

[php]
require ("incl/zipfile.inc.php");
$zipfile = new zipfile();
$filedata = implode("", file("incl/zipfile.inc.php"));
$zipfile->add_dir("incl/");
$zipfile->add_file($filedata, "incl/zipfile.inc.php");
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=zipfile.zip");
echo $zipfile->file();
?>
[/php]

Extracting Image With PHP

[php]
$contenttograbimagefrom = $youroriginalhtmlwithimage;
$firstImage = "";
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $contenttograbimagefrom, $ContentImages);
$firstImage = $ContentImages[1] [0]; // To grab the first image
echo $firstImage;
[/php]

A simple PHP Mysql Class

[php]
//Simply include this file on your page
require_once("DbConnect.class.php");

//Set up all yor paramaters for connection
$db = new DbConnect("localhost","user","password","database",$error_reporting=false,$persistent=false);

//Open the connection to your database
$db->open() or die($db->error());

//Query the database now the connection has been made
$db->query("SELECT * FROM....") or die($db->error());

//You have several options on ways of fetching the data
//as an example I shall use
while($row=$db->fetcharray()) {

//do some stuff

}

//close your connection
$db->close();

#################################################################
Class DbConnect {

var $host = '';
var $user = '';
var $password = '';
var $database = '';
var $persistent = false;

var $conn = NULL;

var $result= false;
var $error_reporting = false;

/*constructor function this will run when we call the class */

function DbConnect ($host, $user, $password, $database, $error_reporting=true, $persistent=false) {

$this->host = $host;
$this->user = $user;
$this->password = $password;
$this->database = $database;
$this->persistent = $persistent;
$this->error_reporting = $error_reporting;
}

function open() {

if ($this->persistent) {

$func = 'mysql_pconnect';

} else {

$func = 'mysql_connect';

}

/* Connect to the MySQl Server */

$this->conn = $func($this->host, $this->user, $this->password);

if (!$this->conn) {

return false;

}

/* Select the requested DB */

if (@!mysql_select_db($this->database, $this->conn)) {

return false;
}
return true;
}

/*close the connection */

function close() {

return (@mysql_close($this->conn));
}

/* report error if error_reporting set to true */

function error() {

if ($this->error_reporting) {

return (mysql_error()) ;
}

}

function query($sql) {

$this->result = @mysql_query($sql, $this->conn);

return($this->result != false);

}
function affectedrows() {

return(@mysql_affected_rows($this->conn));
}

function numrows() {

return(@mysql_num_rows($this->result));

}
function fetchobject() {

return(@mysql_fetch_object($this->result, MYSQL_ASSOC));

}
function fetcharray() {

return(mysql_fetch_array($this->result));

}

function fetchassoc() {

return(@mysql_fetch_assoc($this->result));
}

function freeresult() {

return(@mysql_free_result($this->result));

}

}
[/php]