2025年10月19日

Create a Virtual Disk in a Ramdisk, mounting it at boot and set it as TEMP environment variable in Windows

step 1. Install Imdisk toolkit and initiate a ramdisk at R: with it.

step 2. Create a powershell script with codes shown as below:

function Set_env_temp_folder_path {
    param (
        [string]$FolderPath
    )
    [Environment]::SetEnvironmentVariable("TEMP", $FolderPath, "User")
    [Environment]::SetEnvironmentVariable("TMP", $FolderPath, "User")
    [Environment]::SetEnvironmentVariable("TEMP", $FolderPath, "Machine")
    [Environment]::SetEnvironmentVariable("TMP", $FolderPath, "Machine")
}
$RTmpFolderPath = "R:\RTemp"
New-Item -Path $RTmpFolderPath -ItemType Directory
Set_env_temp_folder_path $RTmpFolderPath

function Remove-FolderIfExists {
    param (
        [string]$FolderPath
    )

    if (Test-Path -Path $FolderPath -PathType Container) {
        try {
            Remove-Item -Path $FolderPath -Recurse -Force
            Write-Host "Folder '$FolderPath' has been deleted successfully."
        } catch {
            Write-Error "Failed to delete folder '$FolderPath'. Error: $_"
        }
    } else {
        Write-Host "Folder '$FolderPath' does not exist."
    }
}

$VhdPath = "R:\ramdisk.vhdx"
$TmpFolderPath = "R:\Temp"
Remove-FolderIfExists $TmpFolderPath
$TmpFolderTargetPath = "S:\Temp"

$break_while_loop = $false
while ($break_while_loop -ne $true) {
    try {
        New-VHD -Path $VhdPath -SizeBytes 22GB -Dynamic
        Mount-VHD -Path $VhdPath
        $disk = Get-DiskImage -ImagePath $VhdPath | Get-Disk
        Initialize-Disk -Number $disk.Number -PartitionStyle GPT -PassThru | New-Partition -UseMaximumSize -DriveLetter S | Format-Volume -Compress -FileSystem NTFS -NewFileSystemLabel "SecRamDisk" -Confirm:$false
        New-Item -Path $TmpFolderTargetPath -ItemType Directory
        Set_env_temp_folder_path $RTmpFolderPath
        Remove-FolderIfExists $TmpFolderPath
        cmd /c mklink /D "$TmpFolderPath" "$TmpFolderTargetPath"
        Set_env_temp_folder_path $TmpFolderPath
        $break_while_loop = $true
    } catch {
        Write-Host "Error mounting VHD: $_"
        $break_while_loop = $fa
    }
}

step 3. Execute Windows Task Scheduler(工作排程器) and create a new task to run at boot:

command:

powershell

parameter:
-ExecutionPolicy Bypass -NoExit "D:\Ramdisk\RamdiskStartupConfigure\attachRamdisk.ps1

Some troubles in installing programs with Imdisk as source of ramdisk can be avoided with this method.

2024年2月9日

Windows Conda 環境下使用 ssh 將 git repository 推送到 github 的方法(錯誤排除)

背景:透過Conda建立一個專門負責 git 任務的虛擬環境,並透過SSH途徑 push/pull Github 上面的 git repository,相關的公鑰與私鑰均已建立並部署完成。

錯誤訊息1 @ 推送權限不足產生錯誤:

(gitonly) PS E:\scripts\python\scripts> git push git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

錯誤訊息2 @ 增加私鑰時的錯誤:

(gitonly) PS E:\scripts\python\scripts> ssh-add C:\Users\user\.ssh\for_github
Could not open a connection to your authentication agent.
經檢查發現
ssh-add 為 conda 所建立 git 環境下附帶的 ssh-add。

(gitonly) PS C:\Users\user> Get-Command ssh-add
CommandType  Name  Version  Source -----------  ----  -------  ------ Application  ssh-add.exe  0.0.0.0  D:\ProgramData\miniconda3\envs\gitonly...


同時經檢查發現 ssh 為 conda 所建立 git 環境下附帶的 ssh。

(gitonly) PS C:\Users\user> Get-Command ssh
CommandType  Name  Version  Source
-----------  ----  -------    ------
Application  ssh.exe  0.0.0.0  D:\ProgramData\miniconda3\envs\gitonly...

解決方法:運用 Windows 本身附帶的 Windows

1. 先使用系統管理員權限開啟 Powershell 並啟動 SSH 服務
Get-Service -Name ssh-agent | Set-Service -StartupType Manual
Start-Service ssh-agent
Get-Service ssh-agent | select -property Status,Name,DisplayName,Starttype
 Status Name      DisplayName                  StartType
 ------ ----      -----------                  ---------
Running ssh-agent OpenSSH Authentication Agent    Manual

2. 運用 Windows 系統自帶的 ssh-add 匯入私鑰
C:\Windows\System32\OpenSSH\ssh-add.exe C:\Users\user\.ssh\for_github
Identity added: C:\Users\user\.ssh\for_github (user@email.com)
3.  調整 git repository 預設的 SSH client 為 Windows 系統自帶的(要先切換到專案目錄下)
git config --local core.sshCommand "'C:/Windows/System32/OpenSSH/ssh.exe'"
4. 可以 git push 了。




2019年9月7日

Calling tensorflow maxout in Keras

Since maxoutdense has been deprecated in Keras, we may call it through Keras Lambda layer, e.g.:

import tensorflow as tf
maxout = Lambda(
  lambda x: tf.contrib.layers.maxout(x, num_units=768),
  output_shape=None,
  mask=None,
  arguments=None,
  name='Maxout'
  )(dropout)

2018年1月21日

Portableapps Application File Association

Foxitreader as an exmple
Save the following as a .reg and register it
=================
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
"FoxitReader Portable"="Software\\FoxitReaderPortable\\Capabilities"

[HKEY_LOCAL_MACHINE\SOFTWARE\FoxitReaderPortable\Capabilities]
"ApplicationName"="FoxitReader Portable"
"ApplicationDescription"="Foxit Reader is the PDF Reader which enables you to become part of the connected world. Provide authors with comments on documents, be notified when new document versions become available, discuss interesting topics right in the document, or securely open protected documents."
"ApplicationIcon"="\"D:\\Documents\\PortableApps\\FoxitReaderPortable\\FoxitReaderPortable.exe\",0"
"Hidden"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\FoxitReaderPortable\Capabilities\FileAssociations]
".pdf"="FoxitReaderPortable"
".fdf"="FoxitReaderPortable"
".xfdf"="FoxitReaderPortable"
".xdp"="FoxitReaderPortable"

[HKEY_LOCAL_MACHINE\SOFTWARE\FoxitReaderPortable]
"LocalizedString"="FoxitReader Portable"
""="FoxitReader Portable"

[HKEY_LOCAL_MACHINE\SOFTWARE\FoxitReaderPortable\DefaultIcon]
""="\"D:\\Documents\\PortableApps\\FoxitReaderPortable\\FoxitReaderPortable.exe\",0"

[HKEY_LOCAL_MACHINE\SOFTWARE\FoxitReaderPortable\shell\open\command]
""="\"D:\\Documents\\PortableApps\\FoxitReaderPortable\\FoxitReaderPortable.exe\""

[HKEY_LOCAL_MACHINE\SOFTWARE\FoxitReaderPortable\shell\properties\command]
""="\"D:\\Documents\\PortableApps\\FoxitReaderPortable\\FoxitReaderPortable.exe\" -preferences"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FoxitReaderPortable]
""="FoxitReader Portable"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FoxitReaderPortable\DefaultIcon]
""="\"D:\\Documents\\PortableApps\\FoxitReaderPortable\\FoxitReaderPortable.exe\",0"

[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\FoxitReaderPortable\shell\open\command]
""="\"D:\\Documents\\PortableApps\\FoxitReaderPortable\\FoxitReaderPortable.exe\" \"%1\""

2015年8月22日

GoldenDict Font, CSS configuration in PORTABLEAPPS

If you want adjust the displaying styles(e.g. font size) in Portable GoldenDict, you may create a file called "article-style.css" in "GoldenDictPortable\App\GoldenDict\portable", and then edit it.

And you may check the css attributes assigned and html layout by left clicking on the lookup result page and selecting "checking the html code(F12)".

REF: GoldenDict FAQ

2014年12月17日

集遊法的權力邏輯與壓迫結構



近日,因游錫堃選舉晚會申請遭刁難/被移送法辦,加上集會遊行法部分條文將於明年元旦失效,又使爭議浮現出來。

「和平」集遊的處境為何如此艱難?如以和平集會遊行須充分保障不得任意驅離處罰為大前提,在現制下,諸如聚集地檢署告發張通榮關說的議員、集結機關前請願、還有718號解釋的三個集遊案件等,即便和平而未侵害他人生命身體財產,其「危害性」仍被認為遠高於鹽水蜂炮(有殺傷性及蔓延性)和白沙屯媽祖(出巡路線隨機決定而難以預測控制)等。蜂炮和媽祖無須面臨申請許可的要求,能夠豁免於警方濫用駁回、變更、撤銷或廢止許可的裁量,從而與機關間產生爭議時更不會陷入被無端驅離以及因時效有限、舉證艱難等救濟無門的困境甚至判刑的可能。

對比之下,我們仍可以從各界反對論述中,一再看到這些「未申請」=「危險存在」衝著和平集遊而來的方程式。這種「對危險寬容對和平嚴厲」的權力邏輯,歸根究底來自於三點:欠缺對權力關係的敏感度、誤解喧囂正面意義而予以排除,以及將「和平」與「和諧」觀念混淆。

舉例來說,「白狼路過」及「411包圍中正一分局行動」事件以來,各界競相爭奪集會遊行定義及臨時性急迫性集會遊行管制架構的話語權,防堵這種「假路過真集遊」的現象。然而,「路過」乃至於紅衫軍曾出現的中華民國過生日「宗教、節慶活動」是否適用集遊法免經許可之類的爭議,根本不是重點所在。白狼率眾向反服貿陣營路過嗆聲的過程中,中正一分局針對均未申請集遊許可的雙方並未依慣常的「依法行政」權力邏輯強行管制、驅離,反而出動警力,在維安的前提下,給予雙方盡情表達異見、嗆聲及發洩的機會。這種策略,達成行政目的外也促成了自由民主社會中應有的生猛有力及眾聲喧嘩,反而更是「和平即應保障」的典範。

但為何各界仍總是以管制思維介入?大法官之言作為代表,其認為集遊「…本質上…即易對…秩序產生影響,且…會引起相異立場者之反制舉措而激發衝突」而須「預為綢繆」,故許可制不違憲。但問題在於,和平而無危險的集遊卻在眾人想像中消失,喧囂被過度解讀為具有典型危險,但如果要管制危險,本應處罰危險行為,而非預設禁止集遊。為了克服行政及場地衝突的實際需求,以鼓勵方式,例如報備者有請求警方排除未報備者的優先使用權、佔用車道優惠,先後報備者在警方協助下均有使用權(例如嘉義市選前之夜)等,都是適當的應對措施。

再者,有大法官認為台灣的集遊過於著重抗議政府而對與各界溝通對話及公共辯論無益,但從上述異見者間針鋒相對的過程,與其說集遊是「與各界溝通」,不如說是透過集遊引出「真正的」溝通與辯論——正是因為原有對話管道因其中一方無意而關閉(涉及雙方的實力問題),而集遊本身就是透過表意者的集結,展現力量,藉以展開心靈、道德、論述、意志力量的對決與比拚,取得言論平台上的籌碼以及歷史地位,使雙方恢復對話並深化討論,318正是開啟公共對話的最佳代表:318前多少人懂服貿爭議?

公共議題的辯論,過程本就不可能也不應該是和諧的。所謂集遊應「和平」並不應當代表相敬如賓沒有衝突的「和諧烏托邦」。如果我們未能察覺喧囂謾罵集結施壓與言論開放、不受拘束又活潑有力間的緊密關係,又漠視在自由民主社會中將衝突明朗化的多種正面助益,一味要求和諧的結果,無異於緊縮言論、捍衛既有秩序從而漠視那些被剝奪的自我、被壓抑的不滿及隨時可能引發的衝突,最後只能惡化不對稱權力結構對於無力者的宰制與壓迫。辯論的交戰高度,從道德正當性與歷史地位,硬是因為集遊法被拉下至有無申請許可的法律層次,這也非言論自由精神所樂見。大法官不僅欠缺權力敏感度,忽視街頭異議者所處不對稱權力結構下的「被」消音處境,更是背離肯認政治的壓迫者,欠缺平等尊重,動輒以違法標籤貶抑他們,使得街頭異議者不斷面臨身份上的挑戰,自主公民常常還沒進場就已經被打趴了。

從這個角度出發,國家所應保障的,從來就不只是某些意見所稱「只是單純保障意見的自由表達與傳播」,在平等視角下,更應著重人民能否實現自我,也就是應注重能否意見「有效」表達及傳播,從而有效塑造公共辯論。然而,現行集遊法中,台面下黑影幢幢的集遊許可協商要求、各種行政處分與執行措施的差別歧視,都成為偏袒現有秩序的既得利益者利器。各界念茲在茲地指出這些集遊障礙都是為了兼顧自由保障與社會秩序維持所必須,但這些需要是否真切?我想,也許誇大其詞,也許是種純粹的反動修辭而已。

蘋果日報論壇版,20140124(此為原文未經修改版)

2012年4月13日

威瑪共和的城市美學

刊載於2012-04-13蘋果日報,此處為原稿
----
3月28日士林王家拆除完畢後,郝龍彬市長先是力陳「一切依法行政」,隔天卻隨即出面開記者會宣稱已經意識到問題,並且已要求營建署修法,但始終未果,未來將推動修法。都更處長林崇傑甚至「落淚」宣稱飽受「拆除王家很痛苦」的壓力。過程中,台北市政府一下非拆不可,一下又不想拆;一下要營建署給他一部好法律,一下又抗拒營建署先前提出的三贏方案。整個事件中,台北市政府不是一個不在意實質正當行政的「類威瑪共和」政府,就是每個官員都用威瑪共和的城市美學基調擘劃城市願景。