2026-02-26

當開發機是Windows on ARM...

 在MacOS上要使用windows去編譯一些程式常常會遇到一些plamform的問題...

- cmake build failed

當使用 cmake -S . -B build 要建立 build system files

原本的專案是在x64上, 所以直接執行會直接使用ARM64去build

所以需要改為 cmake -S . -B build -A ARM64

2025-10-07

windows 11 不使用微軟帳號登入

試過"斷網路", 試過"用無效的email登入失敗"
最後還是改registry最好用... 
  1. 在安裝畫面中, 按下 Shift+F10開啟命令提示字元視窗
  2. 然後輸入regedit
  3. 切換到 HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\OOBE
  4. 新增 DWORD 32, 名稱為 HideOnlineAccountScreens, Value 為 1
切回去後, 重頭開始就不會進入要求登入的畫面了

[update] 看到一個新的方式, 不過還沒測試過...
https://github.com/the-P1neapple/WinJS-Microsoft-Account-Bypass

2023-06-29

在Hyper-V上跑ubuntu 22.04 Desktop, 裝完後一登入就凍住

如果你也遇到這情況, 你可以執行以下步驟
按 Ctrl+Alt+F3 進入 virtual console. (按Ctrl+Alt+F1 可以再回到GUI)
登入後執行下面指令 (更新kernel)

* sudo add-apt-repository ppa:cappelikan/ppa -y
* sudo apt update
* sudo apt install mainline
* sudo mainline --install-latest
* sudo reboot

2020-05-13

WSL 重設密碼

前言

一段時間沒開啟 wsl 中的 ubuntu, 結果忘記了密碼, 沒辦法更新...

重設方式


  • 開啟一個 powershell 視窗
  • 輸入 wsl -u root
    • 如果有安裝多個子系統 (我就裝了 Ubuntu 跟 Kali), 則輸入
      wsl -d [子系統名稱] -u root
    • 如果不確定字系統名稱是甚麼, 則可以用下面指令查詢
      wsl -l
    • 不帶參數 -d 的話, 會使用預設的子系統
  • 進入後, 直接透過 passwd 重設密碼


2018-10-12

透過 python 建立 ftp service 跟 SMB service 的方式

前言

在 kali 上做一些測試, 有時需要將 windows 上的資料回傳到 kali 上.

但是又不想要直接安裝 samba 開 share folder 或是直接開個 ftp 的 service.

想要用python 直接開個簡易的服務可以暫時接檔案.


FTP

需先安裝 pyftpdlib

pip install pyftplib

執行方式

python -m pyftpdlib -w -p 21 -d ~/home/foldername

參數說明

-w : 設定允許匿名登入

-p : 指定 port

-d : 指定 ftp 使用的目錄


SMB service (share folder)

這功能需要使用到 impacket (https://github.com/SecureAuthCorp/impacket)

不過在 Kali 上已經有了,

所以直接執行下面指令, (如果沒有的話,直接clone上面的github專案)

python /usr/share/doc/python-impacket/examples/smbserver.py sharename ~/home/foldername

參數說明

sharename : 要顯示的 share folder 名稱

~/home/foldername : 在 Kali 上要分享出來的資料夾

2018-09-19

移除 docker 中沒有 tag 的image


移除有 <none> 字串的 images

docker rmi $(docker images| grep "<none>" | awk '{print $3}')

說明 :

docker images : 列出 images (不包含 intermediate images)

grep "<none>" : 列出包含<none>的

awk '{print $3}' : 取第三欄, 也就是images id

docker rmi $() : 移除指定id的image


移除特定repository名稱,而且沒有tag的 (有<none>字串)

docker rmi $(docker images| grep -E "^test.*<none>" | awk '{print $3}')

說明 :

grep "^test.*<none>" : 列出開頭為test且包含<none>的

2018-05-04

Ubunutu 上安裝python2, 3, pip 跟virtualenv

# 安裝 python2, python3 (ubuntu 17.04已經預設安裝python3, 但沒有python2)

sudo apt install python python-dev python3 python3-dev


# 安裝 pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
sudo python get-pip.py

# 安裝 virtualenv
sudo pip install virtualenv

# 檢查版本
python –-version
python3 –-version
pip –-version
virtualenv –-version

# 透過 virtualenv 建立 python3 的開發環境
virtualenv –-python python3 devenv

# "進入"開發環境
source devenv/bin/activate

# "離開"開發環境
deactivate

2018-04-24

vmdk 轉換成 vhd

先下載跟安裝 Microsoft Virtual Machine Converter 3.0 : https://www.microsoft.com/en-us/download/details.aspx?id=42497

安裝完後, 使用管理者權限開啟powershell視窗 (Run as administrator)

然後先載入剛剛安裝的Cmdlet

Import-Module 'C:\Program Files\Microsoft Virtual Machine Converter\MvmcCmdlet.psd1'

載入後再執行下列指令執行轉換

ConvertTo-MvmcVirtualHardDisk -SourceLiteralPath d:\VM\VM-disk1.vmdk -VhdType DynamicHardDisk -VhdFormat vhdx –destination d:\VM\

執行完後,可以在指定的資料夾取的同樣名稱的vhd檔


ref: https://blogs.msdn.microsoft.com/timomta/2015/06/11/how-to-convert-a-vmware-vmdk-to-hyper-v-vhd/

2018-04-09

Ubuntu 17.10 使用固定ip

Ubuntu 17.10已經不再使用 /etc/network/interfaces 設定ip了.
取而代之的是netplan
所以要修改網卡設定的話, 開啟 /etc/netplan/01-netcfg.yaml
修改如下

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    ens3:
      dhcp4: no
      dhcp6: no
      addresses: [192.168.8.101/24]
      gateway4: 192.168.8.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]

修改完後, 執行下列指令測試
sudo netplan --debug generate
沒問題的話, 執行下列指令套用
sudo netplan apply

ref : https://askubuntu.com/questions/967695/ubuntu-17-10-will-not-accept-static-ip?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

2016-08-05

Asp.net URL Rewriting

需求

如果User在網址上輸入特定路徑但是任意檔名的時,皆下載同一個檔案

例如:

http://localhost/Files/zip001.zip 或是 http://localhost/Files/zip002.zip

都是下載 [WebRoot/ZIPFiles/A.zip]

http://localhost/Files/txt001.txt 或是 http://localhost/Files/txt002.txt

都是下載 [WebRoot/TXTFiles/A.txt]

 

解決方式

這樣的需求基本上就是用URL mapping或是URL rewriting就可以了.

下面就是使用 URL Rewriting 的設定方式

 

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="ZIP file handler" stopProcessing="true">
          <match url="^Files/?(.*).zip$" />
          <action type="Rewrite" url="/ZIPFiles/A.zip" redirectType="Permanent"/>
        </rule>
        <rule name="TEXT file handler" stopProcessing="true">
          <match url="^Files/?(.*).txt$" />
          <action type="Rewrite" url="/TextFiles/A.txt" redirectType="Permanent"/>
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

2015-06-08

將 windows live writer 的草稿存在網路磁碟上

一直都是在用 windows live writer 寫部落格.

雖然已經非常久沒有寫甚麼東西了...

不過我還是每台電腦都有裝.桌機或是筆電...

而writer的儲存都是存在 My Documents\My Weblog Posts 下,

如果你想要在每台上都可以編輯,如果不是直接存到server上當草稿,

就是要將local的檔案複製來複製去,

前兩天看到一個修改儲存路徑的方式,

因為可以修改儲存路徑,所以就可以直接將草稿存到網路磁碟上,

像是存在 OneDrive, DropBox 或是 Google drive 上了.

而修改的方式如下:

  1. 開啟regedit
  2. 將左側樹狀結構切換到下面路徑
    HKEY_CURRENT_USER\Software\Microsoft\Windows Live\Writer
  3. 然後在右側內容中按滑鼠右鍵,新增一個字串值(String Value),內容如下
    Name : PostsDirectory
    Data : {你要儲存的路徑}
  4. 關閉regedit, 結束

改完後,當你再開啟windows live writer時, 他就會在你指定的路徑下產生 Drafts 跟 Recent Posts 的資料夾,這樣就完成了...

 

ref. Syncing Windows Live Writer Drafts to the Cloud (Dropbox) and other bug fixes

2015-04-02

asp.net專案使用SignalR

SignalR 到現在也已經到了2.2.0

從 1.x 的時候就偶爾玩一下,

2.0 開始只支援 .net framework 4.5,

所以 1.x 要到 2.0 就要整個專案有個升級.

不然就是停留在 1.x 就好了.

 

但是網站並沒有用 MVC, 所以照網路上的一些教學弄,總是弄不起來…

ref : Upgrading SignalR 1.x Projects to version 2

 

症狀 : "Signalr/hubs" not found

 

2.0後,不需要在 global.asax 中的 Application_Start 設定 RouteTable.Routes.MapHubs() 了.

改成需要加個 Startup.cs 設定.

不過我的專案是一般的 asp.net 專案, 它似乎不認得或是不知道要執行這個檔案

經過 google 後才發現,要在 web.config 中加上一個設定

 

<add key="owin:AutomaticAppStartup" value="true" />

 

另外,如果加了後還是沒有執行,

或許是因為他不知道要執行這個 startup, 所以就在加上下面這個設定.

 

<add key="owin:AppStartup" value="SingalRBase.Startup" />

 

ps. SignalRBase.Startup 是 startup.cs 中的 namespace 跟 class name

2011-07-06

[KB]遠端桌面連window vm時只有黑色螢幕

前言

因為需求,所以會建一些vm的環境來共同開發,而最近,有一台vm不知怎麼了,
用遠端桌面連指出現黑色畫面,但是一些服務看起來都很正常,
在另一台主機上透過服務的主控台都還可以去設定那些服務.
連線它的資料夾也都沒問題.
就只有遠端桌面一片漆黑.也看不到登入視窗.

解決方式

在網路上搜尋了一下,看來似乎是跟改了windows color scheme的關係.
(雖然已經忘了是不是有改過,不過改完後確實就可以用了…)

  1. 在另一個相同作業系統中匯出下面路徑的registry.(匯出預設的設定)
    [HKEY_USERS\.DEFAULT\Control Panel\Colors]
  2. 使用Registry編輯器連線到有問題的主機.
  3. 將剛剛匯出的設定,匯入到有問題的主機.
  4. 重該有問題的主機.(可以使用shutdown的指令去重啟遠端的主機,例 : shutdown /r /m \\remote-server)
  5. 等待重開機,完成!

參考網頁:

Black screen in a Windows VM or an a physical server

2011-03-23

[MSSQL]兩個insert的語法

1.將view或是tableB的資料匯到table A


insert into tableA (field1,field2,field3)
select F1,F2,F3 from
tableB
where F4=0

這個方式之前就有了,在這只是記錄一下.

 

2.insert大量資料 (new feature of SQL 2008)


insert into tableA (field1,field2,field3) 
values
('xxxa','xxxxb','xxxxc'),
('xxxa','xxxxb','xxxxc'),
('xxxa','xxxxb','xxxxc'),
('xxxa','xxxxb','xxxxc')


這個是SQL 2008的新功能.


不過用這樣的語法,一次最多只能新增1000筆.


如果要一次新增更多,可以使用BULK INSERT.


 


參考資料:


SQL SERVER – 2008 – Insert Multiple Records Using One Insert Statement – Use of Row Constructor
http://blog.sqlauthority.com/2008/07/02/sql-server-2008-insert-multiple-records-using-one-insert-statement-use-of-row-constructor/


BULK INSERT to table with specific columns
http://beyondrelational.com/blogs/madhivanan/archive/2010/03/17/bulk-insert-to-table-with-specific-columns.aspx

2011-03-21

[Asp.Net]在沒有SMTP的情況下確認發信的程式

.Net 2.0之後提供了一個specifiedPickupDirectory的功能,
讓你在沒有SMTP server的情況下使用資料夾來儲存發信的內容.

使用方式就是在web.config中加入以下的設定

<system.net>
 <mailSettings>
  <smtp deliveryMethod="SpecifiedPickupDirectory">
   <specifiedPickupDirectory pickupDirectoryLocation="C:\MailPickup\" />
  smtp>
 mailSettings>
system.net>

設定完後,發送的信件就會存在指定的資料夾中.

update [2012/02/23] :

如果你是使用在.net 4.0的話,有可能設定完後出現下面這錯誤

The SMTP host was not specified.

這是個已知的問題 :
http://connect.microsoft.com/VisualStudio/feedback/details/539160/smtpclient-reports-invalidoperationexception-when-disposed-immediatelly-after-sending-mail-and-pickup-directory-is-used

而臨時的解決的方式是在Smtp的tag下加個


<network host="localhost" />

完整範例 :
<system.net>
 <mailSettings>
   <smtp deliveryMethod="SpecifiedPickupDirectory">
     <network host="localhost" />
     <specifiedPickupDirectory pickupDirectoryLocation="C:\MailPickup\" />
     smtp>
 mailSettings>
system.net>



2010-11-15

[Tips]Javascript-判斷變數,物件是否存在

在JavaScript中判斷變數是否存在

if (typeof(_varName) == 'undefined')

  …the variable is not exist.

在jQuery中判斷下拉選單裡是否有特定value的option存在

if (jQuery("#" + _objId + " option[value='" + _value + "']").length > 0)

2010-10-23

[Tips] Entity Framework and JSON

需求

提供JSON的格式資料,但是不要將所有的entity欄位都輸出.

 

方式

 

輸出所有欄位

   1: using (MyStockEntities entities = new MyStockEntities())
   2: {
   3:     JavaScriptSerializer js = new JavaScriptSerializer();
   4:     return js.Serialize(entities.CodeStocks);
   5: }

 


輸出需要的欄位



   1: using (MyStockEntities entities = new MyStockEntities())
   2: {
   3:     JavaScriptSerializer js = new 
   4:     JavaScriptSerializer();
   5:     var results = from cols in entities.CodeStocks
   6:         select new
   7:         {
   8:             StockId = cols.StockId,
   9:             StockName = cols.StockName,
  10:             StockType = cols.StockType
  11:         };
  12:     return js.Serialize(results);
  13: }

2010-03-23

[code snippet]清除html tag並清除多餘的空白

//清除Html Tag
string stripped = Regex.Replace(content, @"<(.|\n)*?>", string.Empty);

//清除多餘的空白
Regex r = new Regex(@"\s+");
stripped = r.Replace(stripped,@" ");

2008-02-18

玩玩asp.net 2.0的caching系列二 - RemoveOutputCacheItem

在asp時代,要作cache通常是用application來存資料,
要完整一點的.就是自己寫個class來操作application控制要cache的資料.

但是在asp.net,頁面要cache變得簡單許多.
只要一行

<%@ OutputCache Duration="60" VaryByParam="None" %>

就可以了,
但是,現在問題又來了,
客戶希望後台新增完後他要立即可以從前台看到更新的資料.
先前在網路上看到是有說只要頁面有修改outputcache就會被清除.
但是...這是在測試時候的方式,
在production環境的頁面應該是不能讓客戶每次更新完就去動一下頁面.
要解決這問題,
可以使用HttpResponse.RemoveOutputCacheItem
用法如下 :

HttpResponse.RemoveOutputCacheItem("/default.aspx");

假設你的default.aspx有設定了outputcache,那你可以新增一個管理cache的頁面.
在那個頁面上有個按鈕,點下後呼叫上面的程式.
而RemoveOutputCacheItem所帶的參數就是你的頁面的絕對路徑(不能使用"../"這種相對路徑).

測試網址:

OutputCache頁面 : http://vip.blueshop.com.tw/ajun/cachetest.aspx
Cache管理頁面 : http://vip.blueshop.com.tw/ajun/cachemanager.aspx

outputCache頁面在上一篇介紹過了,而管理的頁面中有兩個功能,
remove cache才是這次的測試範例.

只要確定網址正確,按下remove cache後,該頁面的outputcache就會被清除,
再次瀏覽outputcache的頁面後就會是被更新後的資料了.

問題到這大致上已經ok了,
但是...還是有點狀況,
因為後台維護的資料是最新消息,
而除了首頁外,還有其他的頁面也都會顯示最新消息,
所以如果要用RemoveOutputCacheItem一筆一筆清除cache似乎有點麻煩,
所以下一篇將會是說明怎麼處理這樣的問題.
ps.範例中有這個的程式碼,如果等不及想要知道解決方案的話,可以直接看code.

範例下載:
http://ajunlee.googlepages.com/CacheTest.rar

當開發機是Windows on ARM...

 在MacOS上要使用windows去編譯一些程式常常會遇到一些plamform的問題... - cmake build failed 當使用 cmake -S . -B build 要建立 build system files 原本的專案是在x64上, 所以直接執行會直接使用A...