2018-04-30

NaviServer and Markdown

naviserver-markdown


還是記錄一下這件事。和之前寫的東西類似,也就是 Markdown 檔案輸出為 HTML 格式。在研究 NaviServer 目前的 code 以後,我發現在 NaviServer tcl 目錄下加上 markdown.tcl,就可以用來處理 /*.md。

下面是 markdown.tcl 檔案的內容:
#
# markdown.tcl --
#
#   Add tclllib markdown support to NaviServer
#

#
# Register the ns_markdownfie handler for .md files
#

package require Markdown

ns_register_proc GET  /*.md ns_markdownfie

#
# ns_markdownfie --
#
#   Callback for Makrdown file.
#

proc ns_markdownfie {args} {

    set path [ns_url2file [ns_conn url]]
    if {![ns_filestat $path stat]} {
        ns_returnnotfound
        return
    }

    set infile [open $path]
    set md [read $infile]
    close $infile
    set data [::Markdown::convert $md]

    ns_headers 200 "text/html;charset=utf-8"
    ns_write $data
}

# EOF

重開 NaviServer 以後測試,我發現這個寫法是可行的。

Tclunqlite v0.3.4

檔案放置網頁


Tclunqlite

About

This is the UnQLite extension for Tcl using the Tcl Extension Architecture (TEA).

UnQLite is a in-process software library which implements a self-contained, serverless, zero-configuration, transactional NoSQL (Key/Value store and Document-store) database engine. This extension provides an easy to use interface for accessing UnQLite database files from Tcl.

Main Change

  1. Update UnQLite to 1.1.9

說明


這是一個小更新版本,整合 UnQLite 的版本更新。

2018-04-27

Apache Rivet and mod_actions

mod_actions


雖然 mod_actions 的文件是寫 CGI script,但是你可以使用 Apache Rivet, PHP 或者是類似的工具來撰寫。

下面是測試用的程式,用來將 markdown 檔案 (*.md) 轉換為 HTML 格式以後輸出:
package require Markdown

::rivet::load_env

if {[info exists ::request::env(PATH_TRANSLATED)]==0} {
    ::rivet::headers numeric 400
    return
}

if {[file exists $::request::env(PATH_TRANSLATED)]==0} {
    ::rivet::headers numeric 404
    return
}

set in [open $::request::env(PATH_TRANSLATED)]
set md [read $in]
close $in
set data [::Markdown::convert $md]

::rivet::headers type "text/html;charset=utf-8"
puts $data

再來加上設定(我加在 VirtualHost configure file):
Action markdown /mdhandler.tcl
AddHandler markdown .md

最後重開 Apache HTTP server 然後進行測試。我把程式放在 Github 上。

2018-04-15

tcl-curses: A "minimalist" tcl package for interfacing to curses

tcl-curses


大部份的 code 來自 Minimalist Curses。我只是加上 TEA 的檔案,這樣比較好編譯(對我而言),然後加上我自己需要的部份。

只有在 openSUSE LEAP 42.3 使用 ncurses 測試過。

2018-04-12

tcl-augeas

tcl-augeas


Augeas is a free software configuration-management library, written in the C programming language. Augeas is a tool for accessing and modifying data stored in configuration files of various formats.


可以用來設定檔案的管理,這樣可以有一個更好的方式來進行設定。在 Tcler's Wiki 條目上有一個 Tk 示範程式,列出來目前的設定。如果要做一些軟體設定,就不用自己寫一個分析設定檔案的程式, 而是透過 Augeas 來設定(如果 Augeas 有支援)。

很有趣的工具。我在 Ubuntu 14.04 編譯成功,如果我在 openSUSE LEAP 42.3 也成功,那我嘗試寫看看 tcl-augeas 的 RPM spec,如果成功我再嘗試放到 openSUSE build service 上。

2018-04-11

tclopusfile: Tcl bindings for Opusfile library

tclopusfile

Opus is a lossy audio coding format developed by the Xiph.Org Foundation and standardized by the Internet Engineering Task Force, designed to efficiently code speech and general audio in a single format, while remaining low-latency enough for real-time interactive communication and low-complexity enough for low-end embedded processors.


目前我的實作只有實作開啟檔案的部份,read 的部份使用 int16,float 的部份也省略(也就是我自己需要的部份,讀取 .opus 檔案然後播放音樂)。

目前只有幾個 sample 可以測試,不過聽起來是正常的,所以我把目前的實作放上去 github 了。

中間卡住的地方是 op_read,似乎跟 libopusfile 的實作有關,即使我加大我的 buffer,拿回來的 sample/channel 都是 960,一開始我以為他會計算 buffer 傳回來最大值,後來才發現…… 不是這樣。

2018-04-09

OpenCL and Tcl

維基百科的介紹

OpenCL(Open Computing Language,開放計算語言)是一個為異構平台編寫程式的框架,此異構平台可由 CPU、GPU、DSP、FPGA 或其他類型的處理器與硬體加速器所組成。OpenCL 由一門用於編寫 kernels(在 OpenCL 裝置上執行的函式)的語言(基於C99)和一組用於定義並控制平台的API組成。OpenCL 提供了基於任務分割和資料分割的平行計算機制。


OpenCL 一開始由蘋果所開發,並且擁有商標權。目前業界類似的是 NVIDIA 的 CUDA,而且 CUDA 目前看起來較為流行。OpenCL 交給 Khronos Group 之後,採用的主力是 AMD(AMD 曾經大力主推了一 陣子,不過大家也知道 AMD 前幾年狀況有點不好,所以……)

自由軟體的實作則是 pocl (Portable Computing Language),使用者可以在一般的 CPU 上使用 OpenCL API。再來是 pocl 最新的版本已經開始嘗試加入 NVIDIA GPU devices 的支援。

我看到 pocl 的時候,才想到確實 OpenCL 並沒有一定要在 GPU 上才行(只是大多數都是使用在 GPU 或者是 FPGA 上)。我已經稍微測試一下 pocl,發現 OpenCL 2.0 是可用的。

Tcl 有關的套件則是 TclOpenCL,嘗試 VecTcl 與 OpenCL 的整合。

更新:

有關的套件也可以參考 tcl-opencl