跳到主要內容

live code in blog

KLIPSE 是一個可以產生互動式程式碼的網頁套件,換言之,在網頁上顯示你的程式碼,可以讓觀賞者修改並且輸出程式碼的結果。與其他顯示原始程式碼的 javascript 套件不同之處在於 live 與 interactive,live 的功能可以即時顯示程式碼的結果,interactive 讓使用者可以修改,因此,使用者可以在網頁、部落格上面修改程式碼,並且即時顯示修改後的結果。實際安裝測試,確實可以達到上面所提到的效果。

在 KLIPSE 文件有一段話:

In order to integrate the klipse plugin on a blog, library documentation or any other web page, add the following javascript tag at the end of the page body according to the language of the code snippets:

必須要安裝在網頁 body 標籤底部,實際測試時,只需將下列這一段程式碼放到最後:
 
<script src="https://storage.googleapis.com/app.klipse.tech/plugin_prod/js/klipse_plugin.min.js"></script>

另外兩個重要連結為:

<link rel="stylesheet" type="text/css" href="https://storage.googleapis.com/app.klipse.tech/css/codemirror.css">

<script>
    window.klipse_settings = {
        selector_eval_js: '.language-klipse-cpp', // css selector for the html elements you want to klipsify
    };
</script>
 
可以放到 head 標籤內部。接著就是撰寫測試的程式碼:
 
<pre><code class="language-klipse-cpp">#include &lt;ctime&gt;
#include &lt;iostream&gt;
using namespace std;

int main()
{
  const double sysTime = time(0);
  cout &lt;&lt; "System Time in seconds is: " &lt;&lt; sysTime &lt;&lt; "." &lt;&lt; endl;
  return 0;
}
</code></pre> 

若有其他的語言要呈現在網頁上,可以修改設定如下:

<script>
    window.klipse_settings = {
        codemirror_options_in: {
            lineWrapping: true,
            autoCloseBrackets: true
        },
        codemirror_options_out: {
            lineWrapping: true
        },
        beautify_strings: true,
        selector: '.language-klipse',
        selector_eval_js: '.language-klipse-eval-js',
        selector_jsx: '.language-klipse-jsx',
        selector_es2017: '.language-es2017',
        selector_brainfuck: '.language-brainfuck',
        selector_transpile_jsx: '.language-transpile-jsx',
        selector_eval_php: '.language-klipse-eval-php',
        selector_eval_markdown: '.language-klipse-markdown',
        selector_eval_lambdaway: '.language-klipse-lambdaway',
        selector_eval_python_client: '.language-klipse-python',
        selector_eval_html: '.language-klipse-html',
        selector_sql: '.language-klipse-sql',
        selector_eval_ruby: '.language-klipse-eval-ruby',
        selector_eval_scheme: '.language-klipse-scheme',
        selector_eval_cpp: '.language-klipse-cpp',
        selector_js: '.language-klipse-js',
        selector_reagent: '.language-reagent',
    };
</script>

這一則訊息來至於 Standard C++ 的 A new way of blogging about C++,有趣的是:
 
A long time ago, all the developers had a common dream. The dream was about interactivity, liveness, evaluation…
But we put this dream aside - because the browser understands only javascript.
And after a while, we even forgot that we ever had this dream.
Still, there are some people that didn’t forget this dream, like Alan Kay:

還是有人對於 dream 一直抱持著希望並且努力的想要實現它。

另外,有許多的 online compiler,例如:compiler-explorerWandbox,還有 for Python, html 等語言的 repl.it online compiler

留言

這個網誌中的熱門文章

CodeBlocks 多國語言的設定步驟

多年來一直都是使用 CodeBlocks 英文的介面,不曾想過要將 CodeBlocks 設定成多國語言的開發環境,對於不習慣於英文介面的國人,設定中文的使用介面是非常需要的環境,在 CodeBlocks 論壇有一篇文章提到 :Do you know http://wiki.codeblocks.org/index.php?title=Internationalization ?這個連結說明在 Windows 系統如何設定 CodeBlocks 成為 Internationalization 的環境,整個設定過程如下: 到 CodeBlocks 翻譯文件網站 下載 .mo 檔案:下載時需要 Ubuntu One 的帳號及密碼,登入後點選 .mo 檔案(不要下載 .po 檔是可編輯檔) 系統會傳送一封信件,點選信件的連結,將 .mo 檔案下載 將檔案複製到 C:\Codeblocks\share\CodeBlocks\locale\zh_TW 目錄(沒有這個目錄請自己建立) 開啟 CodeBlocks >> Setting >> Environment >> View >> Internationalization 選項打勾 >> 點選 Chinese 重新開啟 CodeBlocks 要加入其他語言的 .mo 檔案,則在 locale 目錄中新增其他語言的目錄名稱,例如: 德國 de_DE,這樣 CodeBlocks 就是多國語言的開發環境了。 當如果要恢復英文的介面,只要取消 Internationalization 的選項勾選,然後再次重新開啟 CodeBlocks 就回到英文的開發環境。 後記: CodeBlocks 翻譯文件網站 要下載 .mo or .po 檔案需要等待系統回復信件到 Email 信箱,無法及時處理,將這些檔案儲存在 Google Driver 的 src/CodeBlocks 目錄,以後可以從這裡直接取用。

輸入及轉換 Unicode 編碼

如何輸入羅馬數字?不管大寫的數字 ,或者小寫的數字,不知道 Unicode 編碼的人總是會以輸入英文字母 i or I 來替代,即輸入 i, ii, iii, or I, II, III,或許他們不會面臨要輸入 4 以上的羅馬數字,這樣的做法就可以在人類的視覺誤差中暫時瞞騙過關,然而,這樣的作法卻帶來資訊系統不可見的人為問題。這篇文章將描述如何輸入正確的羅馬數字?如何搜尋 Unicode 編碼?以及如何輸入 Unicode 編碼。關於 Unicode 編碼輸入與顯示是一個相當複雜的議題,這篇文章僅針對在 Windows 作業系統中的應用程式如何輸入與搜尋 Unicode 編碼?如何在 Unicode 編碼與對應字元之間做轉換?不會涉及其他的議題;若依照下面描述的輸入方式輸入 Unicode 編碼,不保證能完全符合你/妳所使用個人電腦系統的環境,請再參考相關的文章來解決輸入與顯示 Unicode 編碼的問題。 Unicode 編碼的輸入方式 在 Wiki 的文件 中說明如何在不同環境下輸入特殊字元的 Unicode 編碼,在 Windows 作業系統中輸入 Unicode 編碼的方式如下: Microsoft Word or Wordpad:先輸入 unicode 的編碼,再按下 Alt + x,例如,在 word 中輸入 1f370,然後按下 Alt+x,就會顯示 🍰( &#x1f370)的字元 其他 Microsoft 所有應用程式:應用程式包括 Microsoft PowerPoint, Excel, VS Code 等程式,且要支援 Unicode 編碼的版本,都可以使用注音輸入法來輸入 Unicode 編碼;首先切換到注音輸入法的中文輸入模式,然後按下~鍵(Esc 下方的鍵) + u + Unicode 編碼,特別要注意輸入的數字是鍵盤上方的數字鍵,不可以使用 Number Pad 的數字鍵。 查詢 Unicode 編碼 Unicode編碼的對應字元可以連結到 The Unicode Consortium 的 Code Charts 網站,在網站中輸入你/妳想要字元的 Unicode 編碼,如此就可以找到這個 Unicode 編碼的字元,問題是:我們通常是心中有字元的圖像,或者是要先看到字元的樣子,才知道我們要使用哪一個字

cmd 程式無法執行的解決步驟

因為要設定 cmd 的編碼方式為 Unicode 編碼( chcp 65001),可能不小心修改了編碼,而導致cmd 無法開啟,主要的原因是:「cmd 變成沒有編碼」,所以才造成 cmd 無法開啟。在 Windows 8 中要恢復 cmd 編碼的步驟如下: 1. 滑鼠移到左上角,會出現功能的選項,點選「搜尋」的圖示 2. 在輸入的格子中,輸入「cmd」但是不要按下 enter 3. 滑鼠移到「cmd 命令提示字元」,,按下「滑鼠右鍵」 4. 下面會出現一些選項,點選「開啟檔案位置」,如此可以找到 cmd 命令提示字元的位置 5. 在「 命令提示字元」檔案中按下滑鼠右鍵,並點選「內容」 6. 點選「選項」,把「950 - Big 5 繁體中文」的編碼加入