Posts Tagged ‘ Coding

[转载][MySQL]MySQL 的 SET NAMES xxx 字符编码问题分析

转载自: PHPChina


近来接受 BBT 的培训,做一个投票系统。系统程式码倒不是很难,但是我的时间主要花费在了研究字符集和编码上面。MySQL 和 Apache 两个系统的编码 (字符集) 问题让我费劲脑筋,吃尽苦头。网上对这些问题的解决比较零散,比较片面,大部分是提供解决方法,却不说为什么。于是我将这几天收获总结一下,避免后来者再走弯路。这篇文章对 PHP 编写有一点帮助 (看完你就知道,怎样让你的 PHP 程式在大部分空间提供商的服务器里显示正常),但是更多帮助在于网络服务器的架设和设置。
Read more

[JavaScript]动态网页设计的相关网页 (dhtml)

国外网站

中文网站

其它

[Perl][JavaScript]以数学的原理处理四舍五入

我看过太多人都把四舍五入的问题看成是“字串”来处理,实际上,如果把四舍五入做为“数学”来解的话,程式大概只要几行即可解决。

以四舍五入取整数的例子来讲,其原理就是: 任何数值 +0.5 再取整数

但要注意的是,当四舍五入遇到“负数”时就会变成“五舍六入”,这是因为中间数要往数值大的那边进位的缘故。所以加上了负数的处理,程式至少又多了一行:
Read more

在 Blogger 中使用 dp.SyntaxHighlighter 显示程式码

db.SyntaxHighlighter 是一支不错的程式码高亮度显示程式,特点为:

  1. 显示行号
  2. 支援12种程式语言
  3. 模组化加载需要的程式语言
  4. 支援 “<pre>” 及 “<textarea>” 区块
  5. 纯文字检视
  6. 复制到剪贴簿
  7. 直接打印程式码

缺点就是加载速度较慢。

安装步骤

  1. 修改 blogger 样板,搜寻 “</body>”,在 “上方” 加入(你可以选择你要的语言加载即可):
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shCore.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushPhp.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushJScript.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushSql.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushXml.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushDelphi.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushPython.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushRuby.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushCss.js'></script>
    <script class='javascript' src='http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/shBrushCpp.js'></script>
    <script class='javascript'>
    dp.SyntaxHighlighter.ClipboardSwf = 'http://syntaxhighlighter.googlecode.com/svn/tags/1.5.0/Scripts/clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
    </script>

    (因为 “偷吃步” 的关系,程式直接连到 dp.SyntaxHighlighter 的 SVN 上,你可以视情况下载回来放到自己的服务器)

  2. dp.SyntaxHighlighter 原本已经有一个 CSS 档了,但如果将这个 CSS 档以 “Link” 的方式加载,却无法正常显示。所以,请自行增加下列 CSS 到 blogger 样板的 CSS 区段:
    /*dp.highlighter*/
    .dp-highlighter {
      font-family: "Consolas", "Courier New", Courier, mono;
      font-size: 12px;
      background-color: #E7E5DC;
      width: 99%;
      overflow: auto;
      margin: 18px 0px 18px 0px;
      padding-top: 1px; /* adds a little border on top when controls are hidden */
      border:1px inset;
      max-height:200px;
    }
    .dp-highlighter .bar {
      padding-left: 45px;
    }
    .dp-highlighter.collapsed .bar,
    .dp-highlighter.nogutter .bar {
      padding-left: 0px;
    }
    .dp-highlighter ol {
      list-style: decimal; /* for ie */
      list-style: decimal-leading-zero; /* better look for others */
      background-color: #fff;
      margin: 0px 0px 1px 45px; /* 1px bottom margin seems to fix occasional Firefox scrolling */
      padding: 0px;
      color: #5C5C5C;
    }
    .dp-highlighter.nogutter ol {
      list-style-type: none !important;
      margin-left: 0px;
    }
    .dp-highlighter ol li,
    .dp-highlighter .columns div {
      border-left: 3px solid #6CE26C;
      background-color: #f8f8f8;
      padding-left: 10px;
      line-height: 14px;
    }
    .dp-highlighter.nogutter ol li,
    .dp-highlighter.nogutter .columns div {
      border: 0;
    }
    .dp-highlighter .columns {
      color: gray;
      overflow: hidden;
      width: 100%;
    }
    .dp-highlighter .columns div {
      padding-bottom: 5px;
    }
    .dp-highlighter ol li.alt {
      background-color: #fff;
    }
    .dp-highlighter ol li span {
      color: Black;
    }
    /* Adjust some properties when collapsed */
    .dp-highlighter.collapsed ol {
      margin: 0px;
    }
    .dp-highlighter.collapsed ol li {
      display: none;
    }
    /* Additional modifications when in print-view */
    .dp-highlighter.printing {
      border: none;
    }
    .dp-highlighter.printing .tools {
      display: none !important;
    }
    .dp-highlighter.printing li {
      display: list-item !important;
    }
    /* Styles for the tools */
    .dp-highlighter .tools {
      padding: 3px 8px 3px 10px;
      font: 9px Verdana, Geneva, Arial, Helvetica, sans-serif;
      color: silver;
      background-color: #f8f8f8;
      text-align1: right;
      padding-bottom: 10px;
      border-left: 3px solid #6CE26C;
    }
    .dp-highlighter.nogutter .tools {
      border-left: 0;
    }
    .dp-highlighter.collapsed .tools {
      border-bottom: 0;
    }
    .dp-highlighter .tools a {
      font-size: 9px;
      color: #a0a0a0;
      text-decoration: none;
      margin-right: 10px;
    }
    .dp-highlighter .tools a:hover {
      color: red;
      text-decoration: underline;
    }
    /* About dialog styles */
    .dp-about { background-color: #fff; margin: 0px; padding: 0px; }
    .dp-about table { width: 100%; height: 100%; font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; }
    .dp-about td { padding: 10px; vertical-align: top; }
    .dp-about .copy { border-bottom: 1px solid #ACA899; height: 95%; }
    .dp-about .title { color: red; font-weight: bold; }
    .dp-about .para { margin: 0 0 4px 0; }
    .dp-about .footer { background-color: #ECEADB; border-top: 1px solid #fff; text-align: right; }
    .dp-about .close { font-size: 11px; font-family: Tahoma, Verdana, Arial, sans-serif !important; background-color: #ECEADB; width: 60px; height: 22px; }
    /* Language specific styles */
    .dp-highlighter .comment, .dp-highlighter .comments { color: #008200; }
    .dp-highlighter .string { color: blue; }
    .dp-highlighter .keyword { color: #069; font-weight: bold; }
    .dp-highlighter .preprocessor { color: gray; }
  3. 储存即可

使用方法

  • 方法一 - 使用 “<textarea>” 区块,需将 “&” 转换为 “&amp;”:
    <textarea name="code" class="程式语言">
    程式码
    </textarea>
  • 方法二 - 使用 “<pre>” 区块,需将 “&” 转换为 “&amp;”、”<” 转换为 “&lt;”、”>” 转换为 “&gt;”:
    <pre name="code" class="程式语言">
    程式码
    </pre>

参考网页

在 Blogger 中使用 google-code-prettify 显示程式码

google-code-prettify 是一支不错的程式码高亮度显示程式,特点为:

  1. 支援 15 种程式语言(但某些语言似乎还没完成)
  2. 程式仅两个档案
  3. 加载速度较快

缺点为:

  1. 跟 IE 的相容性比较不佳,在 IE 内复制程式码时无换行符号
  2. 无行号显示
  3. 仅支援 "<pre>" 区块
  4. 程式码过长时不会自动显示卷轴 (可透过修改 CSS 解决)

安装步骤

  1. 修改 blogger 样板,搜寻 "</head>",在 "上方" 加入
    <link href='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css' type='text/css' rel='stylesheet' />
    <script type='text/javascript' src='http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.js'></script>

    (因为 "偷吃步" 的关系,程式直接连到 google-code-prettify 的 SVN 上,你可以视情况下载回来放到自己的服务器)

  2. 继续搜寻 "<body>",在标签内的 onload 事件加入:
    prettyPrint();
  3. 储存即可。

使用方法

      使用 "<pre>" 区块,需将 "&" 转换为 "&amp;"、"<" 转换为 "&lt;"、">" 转换为 "&gt;":
<pre class="prettyprint">
程式码
</pre>

参考网页

[Perl]Perl 的相关网页资源

手册

教学/手册

Read more

几种网页转址与“301 永久搬移”的语法

转址的方式分为:

  • 302: 暂时搬移 (Temporarily Moved)
  • 301: 永久搬移 (Permanently Moved)

Read more

各种资料手册下载,强力推荐

Cheat Sheet Roundup 是一个很棒的网站,内有作业系统、程式设计、数据库、网页设计…等 30 余种相关的资料手册可供下载(包含一些单页的 Data Sheet 可以用来贴在自己的座位墙板上),对于设计师与相关资讯人员,都是很好的参考资料,强力推荐。

看看人家的程式是怎么写的

在国外有一些网站,专门存放一些程式码的精华片段,写程式如果遇到瓶颈,可以上来逛逛…

Coding

Regular Expression

[转载]让人既爱又头痛的 GNU/GPL

转载自: 自由软件铸造场


GNU Genral Public License(以下简称GNU/GPL)是第一份自由软件授权条款,也是目前最广为被使用的授权条款之一。自由软件之父 Richard M. Stallman(以下称 Stallman)为了替他的软件开发计画- GNU 计画寻找适当的授权方式,在 1989 年草拟出 GNU/GPL 第一版。它的整个架构与理念源自于 Stallman 所宣示的软件使用者四大自由(注一):

  • 使用的自由:可以不受任何限制使用该软件。
  • 研究的自由:可以研究该软件的运作方式,并使其符合个人需求。
  • 散布的自由:可以自由地复制该软件并散布给他人。
  • 改良的自由:可以自行改良该软件并散布改良后的版本,以嘉惠众人。

Read more

return top