2019-05-21

Tcl:九九乘法表

這只是一個簡單的 Tcl 練習。

所以第一個是 for loop 的版本。
#!/usr/bin/env tclsh

for {set nx 0} {$nx < 10} {incr nx} {
    for {set ny 0} {$ny < 10} {incr ny} {
        puts "[format "%d x %d = %2d" $nx $ny [expr $nx  + $ny]]"
    }
} 

第二個版本是我在寫同樣的東西(也是九九乘法表),因為 Erlang 沒有 for 和 while 迴圈,所以我先建立一個 list,然後再使用 Erlang 提供的 lists:foreach 印出結果。我用同樣的精神寫 Tcl 九九乘法表的第二個版本(同時測試 mathop)。
#!/usr/bin/env tclsh

set x [list 1 2 3 4 5 6 7 8 9]
set y [list 1 2 3 4 5 6 7 8 9]

foreach nx $x {
    foreach ny $y {
        set z [::tcl::mathop::+ $nx $ny]
        puts "[format "%d x %d = %2d" $nx $ny $z]"
    }
}

2019-05-13

Next Scripting Framework 2.3.0

ANNOUNCE: Next Scripting Framework 2.3.0 is available


NSF 釋出了 2.3.0,所以我更新了我自己的 openSUSE RPM spec, 這可以比較方便進行測試。我在下載的時候 SourceForge 似乎出現問題,所以無法順利下載,我把下載檔案的地址切到 NSF 在 Github 的 mirror

2019-05-09

Update tklib spec

tklib-spec


因為 tablelist 釋出了新版 v6.5,為了反應 tklib 最近的變化,所以更新了我自己的 openSUSE RPM spec,更新到目前的 code base。

2019-04-16

使用 QEMU 執行 openSUSE/AARCH64 image

因為 tclBlend 我接到一個 issue,在 AARCH64 下編譯失敗,所以需要一個 AARCH64 模擬器來除錯。


首先要安裝 QEMU-ARM:
sudo zypper install qemu-arm

要下載一個 openSUSE AARCH64 image 來進行測試(我使用 unxz 解壓縮)。
wget https://download.opensuse.org/ports/aarch64/factory/images/openSUSE-Tumbleweed-ARM-JeOS-efi.aarch64-Current.raw.xz
unxz openSUSE-Tumbleweed-ARM-JeOS-efi.aarch64-Current.raw.xz

如果使用 efi image,需要有 Unified EFI BIOS 模擬器正確的載入 boot loader 才行(不然無法正確執行)。我從 Linaro 下載一個來使用。
wget https://releases.linaro.org/components/kernel/uefi-linaro/16.02/release/qemu64/QEMU_EFI.img.gz
gzip -d QEMU_EFI.img.gz 

然後就可以這樣執行:
qemu-system-aarch64 -m 2048 -cpu cortex-a57 -smp 2 -M virt -bios QEMU_EFI.img -serial stdio -device virtio-net-device,netdev=hostnet0,id=net0,mac=52:54:00:09:a4:37 -netdev user,id=hostnet0  -drive if=none,format=raw,file=openSUSE-Tumbleweed-ARM-JeOS-efi.aarch64-Current.raw,id=hd0  -device virtio-blk-device,drive=hd0

(使用者帳號為 root,密碼為 linux)

參考文章:
openSUSE:AArch64
Documentation/Platforms/ARM
Linux on AArch64 ARM 64-bit Architecture
Building ARM Servers With UEFI And ACPI


就 ARM 來說,有二種描述 hardware scheme 的方式,一種是 UEFI/ACPI,一種是 Device Tree。Linux kernel 可以編譯為二種都支援。文件中有提到:

ACPI support in drivers and subsystems for ARMv8 should never be mutually exclusive with DT support at compile time.

At boot time the kernel will only use one description method depending on parameters passed from the boot loader (including kernel bootargs).

Regardless of whether DT or ACPI is used, the kernel must always be capableof booting with either scheme (in kernels with both schemes enabled at compile time).

2019-04-10

Difference between 2 dates in XQuery

package require xqilla

xqilla db
set exprs [db prepare {days-from-duration(xs:dateTime('2019-06-14T00:00:00') - current-dateTime())}]
set result [$exprs execute]
set diff 0

while {[$result next]} {
    set diff [$result string_value]
}

puts "The answer is $diff."

$result close
$exprs close
db close

使用 XQuery 的日期函式計算出二個日期間的差距,這裡使用 XQilla 測試。

Difference between 2 dates in SQLite3

package require tdbc::sqlite3

tdbc::sqlite3::connection create db :memory:
set statement [db prepare {SELECT CAST ((JulianDay('2019-06-14') - JulianDay('now')) as Integer) as d}]    

set diff 0
$statement foreach row {
    if {[catch {set diff [dict get $row d]}]} {
        set diff 0
    }
}

puts "The answer is $diff."

$statement close
db close

使用 SQLite3 的日期函式計算出二個日期間的差距,這裡使用 tdbc::sqlite3 測試。

2019-03-19

Magicsplat Tcl/Tk 8.6.9-1.9.1 for Windows

ANNOUNCE: Magicsplat Tcl/Tk 8.6.9-1.9.1 for Windows


The following new packages have been added in this release:
- Next Scripting Framework nsf (2.2.0) with nx and XOTcl
- Ffidl 0.7
- Critcl 3.17
- Tix widget library 8.4.3


所以 Magicsplat Tcl/Tk 釋出一個新版。

2019-03-04

tkimg 1.4.9

tkImg


tkImg 釋出了一個新的版本,1.4.9。


下面是節錄的說明:

This file contains a collection of format handlers for the Tk photo image type, and a new image type, pixmaps. It can be used in combination with Tcl/Tk 8.3 or later but 8.6 or newer are highly recommended.

Included in this distribution are the most recent versions (as of March 2019) of the libz, libpng, libjpeg, and libtiff libraries. These are not required, unless you need support for the PNG, JPEG, or TIFF format. Note that you have to build these libraries to support the named formats, even if your system already has shared libraries for these formats. This is because the libraries here are built such that they can be loaded as packages by the Tcl/Tk core, making the handling of the various dependencies much easier. An earlier version, 1.2.4, used a modified copy of Tcl's functions for loading of shared libraries to load the support libraries at runtime. These have been abandoned in favor of the new approach.

2019-02-25

NaviServer 4.99.18

NaviServer 4.99.18 檔案已經被放上去 SourceForge,所以可以下載了。


這次的更新內容可以看這裡

New Features:
-------------

 - Added ability to provide memory sizes via memory units (kB, MB, GB,
   KiB, MiB, GiB) in the configuration files and commands. We follow
   the approach taken by e.g. PostgreSQL and use 1024 as
   multiplicator, which is e.g. useful for buffer sizes. All memory
   sizes in the config files can be specified in memory
   units. Currently, the only commands supporting memory units are
   ns_cache_create, ns_cache_configure and ns_http. The configuration
   based on integers without memory units continues to work.


 - Portable config files (windows compatibility)

   Rationale: unixoid platforms use traditionally ".so" as extension
   of binary modules, no matter what "info sharedlibextension" is. On
   macOS, the sharedlibextension returns ".dylib", while the module is
   named ".so". Under windows, it seems that the extension of the module
   has to be ".dll", so we can't write portable config
   files without extra effort.

   The new code tries now first to load the library as specified for
   backward compatibility (maybe containing a file extension). When
   this fails, it tries to append either ".so" in unixoid platforms or
   ".dll" under windows.

 
 - new API call: ns_db currenthandles

   Return information about handles currently allocated to the thread
   performing this call. The result contains a dict with the pools,
   from which handles were allocated, the names of the handles and
   their "active" state (a handle is active between a "ns_db select"
   and the last "ns_db getrow" statement). If no handles are allocated
   by this thread, empty is returned.

   For example, a possible result is "main {nsdb0 1} subquery {nsdb1
   0}" indicating that the current thread has allocated handles from
   pool "main" and "subquery", but the handle from pool "main" (i.e.
   "nsdb0") is currently active (during a select).

   This feature requires Tcl 8.5 or newer.


 - More security features: SameSite support for cookies

   The command ns_setcookie supports now the flag "-samesite" with
   permissible values "strict|lax|none". When the flag is set it
   prevents the browser from sending this cookie along with cross-site
   requests to mitigate cross site scripting attacks. Permissible
   values are [term strict], [term lax], or [term none]
   (default). While the value [term strict] prevents sending the
   cookie to the target site in all cross-site browsing context, the
   value of [term lax] allows sending the cookie when the user clicks
   on regular links. For details, see
   https://www.owasp.org/index.php/SameSite

   The "SameSite" cookie flag is not yet part of an RFC, but most major
   browsers support it. Browsers that do not support it, ignore the flag
   silently (see https://caniuse.com/#search=samesite).

   Although most cookies should probably use the flags, in order to
   provide backward compatibility, the flag can't be activated by
   default on all cookies.


 - Better entries in server log for scheduled procedures.

   With this change, one can determine exactly, which scheduled thread
   was executing an instance of which scheduled procedure. Similarly
   as for connection threads, one can now distinguish, whether two
   log-entries are from the same instance of a scheduled proc or from
   different ones.

 - nsdb stats: Return as well number of currently connected DB connections.


目前還沒有編譯和測試,晚上我會試著升級我目前使用的版本。

2019-02-14

Update tcl-cmark

tcl-cmark


tcl-cmark 最近更新,修正了 cmark-gfm 最近幾個版本的不相容修改結果 tcl-cmark 會編譯失敗的問題。我自己的 RPM spec 也跟著更新,移掉我自己之前的修正,使用 tcl-cmark 更新的部份就可以了。