2016年5月16日 星期一

在 ABC pdf 中嵌入造字

真是太感動了,好不容易,在 ABC pdf 中,成功的嵌入造字。

參考連結:
使用者自造字(EUDC)成功轉到 PDF 的方式
https://dotblogs.com.tw/rainmaker/2016/03/11/140808

把自造字轉成 ttf
https://dotblogs.com.tw/rainmaker/2016/03/09/232711

需要軟體 FontForge。

將造字檔,例如 Skfont_20071106.TTE。使用下面這段程式碼,把它轉成 ttf。
==========================================================
#Open EUDC TTE
Open("Skfont_20071106.TTE", 4)
# CHANGE TTFNAME 2 EUDC
SetTTFName(0x409,1,"EUDC")
SetTTFName(0x409,2,"EUDC")
SetTTFName(0x409,3,"EUDC")
SetTTFName(0x409,4,"EUDC")
SetTTFName(0x404,1,"EUDC")
SetTTFName(0x404,2,"EUDC")
SetTTFName(0x409,3,"")
SetTTFName(0x404,4,"EUDC")
SetFontNames("EUDC", "EUDC", "EUDC", "Regular", "655", "1.0.0")
Generate("Skfont_20071106.ttf")
Generate("Skfont_20071106.woff")
Close()
#fontforge -script font-TTE2Others.pe
==========================================================

然後,再用 FontForge 將已有的字型檔,例如 kaiu.ttf,與所產生的造字檔合併成新的字型檔,例如 Kai-eudc。再把它安裝到伺服器上。

在 ABCpdf 中,使用內嵌指令,注意,要用 Unicode 才會出來。
theDoc.Font = theDoc.EmbedFont("Kai-eudc", "Unicode", false, true);

Happy!

2016年2月23日 星期二

14歲炒股為父買奧迪,《最強大腦》最美姑娘分享炒股獨門絕技!

http://ww.happies.news/cat53/node912841/151654
 
外表甜美的90後美女周紫卉熱愛金融,特別對股票情有獨鍾。她擁有8年的炒股的經驗, 
現在可以稱為老股民了。她曾經參加《最強大腦》,挑戰她最熟悉的股票分時圖,
快速報出股票名稱、時間和代碼,精彩的表現讓在場的嘉賓讚嘆。
大家原以為這位 金融界的「女超人」即會晉級中國戰隊時,Dr. 魏卻只給出 5 分的難度分,
周紫卉只得遺憾離場。隨著節目播出,據了解到,周紫卉其實是個老股民,
14歲就開 始炒股的她,曾用賺來的30萬為父親買了一輛奧迪車。 
 
迄今為止,雖然在股市馳騁多年,她的生活卻從未被股市「套牢」。
目前就讀於美國東北大學念大四,正在世界500強的基金公司里實習,
平時愛好養豬遛鵝無所不玩。下面為大家介紹美女股神的獨門絕技:異動漲停買入法
 
1、漲停股:動不動就拉漲停的股才是好股。幾乎所有牛股都是從漲停開始走牛的。
2、放量假大陰:大幅放量高開低走股,日線收一根陰線,實際漲幅在3%左右。
注意區分頂部區域的烏雲蓋頂、穿頭破腳。
3、長上影倒錘頭:重點是階段底部區域的倒錘頭,有仙人指路的味道,是向上試盤動作,
後期往往會走好,最好在5日線以上形成跳空缺口。連續大漲後頂部區域的倒錘頭,
要重點迴避,是避雷針,說明拋壓沉重。
4、高換手股:換手>10%,重點是階段底部區域的。
5、高量比股:量比>3%,往往比高換手管用,因為突然放量總比老是放量好,
特別是底部區域的高量比;
 6、高振幅股:振幅>12%,往往有操作手法兇悍的主力。
頭日收藏的異動股,次日開盤半個小時內應重點關注,其後至少應該每半個小時關注一次,
分時走得較好的或漲幅在2-3%以上的個股應重點關注。一旦突破介入價位,
隨時準備按買點要求介入。
當然上述4種異動股形態也有失敗的案例,介入後失敗怎麼辦?
正確的做法就是兩個字:止損。
每天將手中個股次日的止損位寫在紙上,記在心理,並嚴格執行。切記!切記!!
千萬不要有以下一些錯誤止損意識:
1、當日介入即被套,或者次日大幅低開遠低於自己的止損位,就無動於衷了,
所謂死豬不怕開水燙。
2、剛破位下跌時因存有僥倖心理未及時止損,然後死抱不放,直至心灰意冷。
最後,當股價經過幾波下跌已經跌到位,股價都在18層地獄了,剛有一點反彈,
就立馬止損出局,生怕後面還有下跌。可當你剛一止損股價卻一飛沖天。
若有上述錯誤止損意識,正確的做法應該是:
1、次日大幅低開並慣性下沖後,分鐘短期指標乖離過大,往往有個上沖糾偏過程,
這時就非常關鍵了,如果漲勢無力,應果斷止損而出。
2、既然股價都在18層地獄了,抱了那麼久,為何又急在這一時?既然是死豬,就要死到底。

2016年2月17日 星期三

IIS 6 的環境,PHP 無法設定 cookie

今天,發生一件奇怪的事。使用 Laravel 5.0 開發的應用程式,在用 Firefox 和 Chromium 登入時,總是會發生 "TokenMismatchException in VerifyCsrfToken.php" 的錯誤。但使用 IE 則不會有錯誤。

使用的環境是 IIS 6,Windows 2003,PHP 5.4.31。觀察 cookie,發覺沒有寫入 Laravel session 的 cookie,因而每次 refresh 時,都會開啟新的 session。

寫個小程式測試,發現 PHP 的 session 功能正常,但無法設定 cookie。再更進一步測試,是有設定 timeout 時,無法設定 cookie。但不設定 timeout 時,也就是 "Expires: At end of session",則能成功設定 cookie。

對策,修改 config/session.php 中的「'expire_on_close' => true,」即可。原為 false。

2016年1月13日 星期三

在 Gentoo 使用 Teamviewer

安裝
# emerge -av =net-misc/teamviewer-11.0.53191

 * Messages for package net-misc/teamviewer-11.0.53191:

 * TeamViewer from upstream uses an overly-complicated set of bash
 * scripts to start the program.  This has been simplified for Gentoo
 * use.  Any issues should be reported via bugzilla.
 *
 * Due to bug #552016, when using system wine, one is not able to
 * share one's own screen.  At this time, this may be remedied by
 * toggling the system-wine USE flag.
 *
 * The end-user client requires running the accompanying daemon,
 * available via init-scripts.
>>> Auto-cleaning packages...

它在 Linux 下,透過 Wine 來使用。安裝時,USE 為 system-wine 時,使用系統安裝的 wine。


啟動 service
# systemctl start teamviewerd11.service

2016年1月4日 星期一

熱水器專用加壓馬達使用心得

住在頂樓,一定得加裝加壓馬達,才能使用熱水器。但是傳統加壓馬達,壓力開關很難調到適當,洗個澡,加壓馬達開開關關,實在惱人。更恐怖的是,某天水管爆掉,屋頂淹大水,小孩先回家,已把馬達關掉了,我回家只看到地上的汪洋一片。此後就一直想要在頂樓自己裝個小水塔。

後來,自行裝個 250 公升的小水塔,避免加壓馬達不停的開開關關。 小水塔和熱水器之間的高度大約為 4公尺,普通用水,只要忍受水小一點,即無所謂,但熱水器根本就不能用。


 

工作時,都會聽台北愛樂的廣播,不時聽到葛蘭富的熱水器專用加壓馬達的加壓馬達,應該有用。但不肯定,後來在露天網拍買了較便宜的 APP JA-80 來試用,果然有用。只不過,經過一個夏天,都沒用熱水之後,到了天涼要用熱水器時,就變得不穩定了。

要換新的,想說用名牌的,是否會比較好,就買了葛蘭富 UPA 15-90。好不容易裝好了,結果讓人失望,竟然水壓開關無法自動開啟。而且,就算強制開啟,也無法讓熱水器點火。所以,國外知名品牌,東西不一定實用。而且,JA-80 在安裝上,也較為方便。

只好用舊的再頂著用,同時買新的,APP JA-80S。裝上新的  APP JA-80S,仍有時無法自動啟動,但只要變化熱水的大小幾次,改變水流,可以讓其啟動。啟動後,就可以舒服的洗澡。

附圖為 APP JA-80 的流動開關,顯然的,對於微弱的水流,其仍然靈敏可靠。在使用一段時間後,因為水中的雜質會黏附在浮筒上,使得靈敏度降低,可以依照說明書拆開清潔。




一些整理

禾申公司~★☆和川牌120W 1520
2.7kg , 最高揚程 : 10M (1.0kg / cm2) , 輸入功率 :120W , 最大流量 : 2.4 m3 / hr (40L / min) ◎

葛蘭富 UPA 15-90
機體淨重 :2.7kg, 輸入功率 :120W, 輸出功率 :40W, 最大流量 : 1.6 m3 / hr (26.6L / min)

Wilo 熱水器 加壓馬達 PB-088LA, 2800, 60W, 最大流量 : 2.1m3/h 35L / min
出水孔徑 1/2

APP(JA-80~S) 不銹鋼, 馬力(1/10HP ~ 80W), 出水孔徑 3/4, 3.5KG
App ja80 好
進水1.2尺,出水2尺,熱水器 1尺
濾網,要清
安裝較方便

請注意這種裝在熱水器一端的加壓馬達,輸出壓力不能太大,不然會熱水從蓮蓬頭灌回冷水管,甚至從馬桶冒出來。以上是從網路上得到的知識,個人並未驗證,參考一下。


熱水器不點火 (2019 年 1 月)

用了一年後,水越來越小,又一直無法點火,直到最後,完全不點火。用強制啟動,加壓馬達一直轉一直轉,熱水器還是無動於衷。抓問題很麻煩,已經打算要上網再買一個新的,整組換掉,比較省事。後來,想想還是拆下來,看看濾網是不是堵住了。結果,是接加壓馬達進水端的軟管,有一堆沉積物,把水管堵住了,使得水壓不夠。換一根新的,一切OK。




2015年12月31日 星期四

龜毛的 HP server

今天重裝一台 HP 的 server,HP ProLiant DL360p Gen8。把一些手邊的硬碟都拿過來用,開開關關重裝了一整天,每次開機後不久,就會風扇狂轉,溫度過高 (OVER TEMP) 的警示燈一直閃。

以為是風路被阻擋,重排硬碟的位置,甚至把光碟機也拔掉,但情形還是未見改善。也到 BIOS 中,改變溫度相關的選項,情況還是沒改善。

後來,回憶在整理硬碟時,把硬碟一顆一顆插上去時,插到某一顆,風扇就開始提昇。的確,在設 Disk Array 時,一直有兩顆硬碟顯示警告訊息,說非認證的硬碟,那兩顆就是 Toshiba 的產品,有 5 年保固。後來,把那兩顆換掉,又恢復安靜無聲的狀態。

HP 的 SAS 硬碟,真的是超級貴的啊,已經買它的 server 了,還要用這一賤招來卡使用者。將來,要評估一下,還有那家的伺服器可以買,不然真的會被它卡的死死的,任其宰割啊。

2015年11月8日 星期日

複製 (Clone) Linux 系統 (包括 Gentoo, CentOS)

完整複製 (clone) 整個檔案系統

下面是使用 cpio 完整複製檔案系統的指引

[引用原來的文章]

HOWTO: Using cpio to Copy a Partition in Linux

Using cpio to copy everything from one partition to another in Linux, maintaining all file permissions, symlinks, and timestamps.

# File: copy_partition.notes
# Auth: burly
# Date: 03/20/05
# Desc: A method of copying everything from one
#      partition to another
 
# Change directories to the top level of the
# partition you want to copy
cd /part
 
# Use find to locate all objects and cpio to copy them
find . -mount -print0 | cpio -0dump /path/to/new/part

How to move your filesystem to a new hard drive

ref: http://www.greenfly.org/tips/filesystem_migration.html

Despite the best planning, it eventually happens. You start to run out of space on your linux system. While there are many different ways to copy files from one hard drive to another, some work better than others when transferring the full / directory. Below I will outline a method I have used about 50 times to transfer full systems and partitions from one machine to another.

Why this can be complicated

When you are copying a full linux system from one partition to another, there are a few issues you need to consider:

  • Preserving permissions - If your files aren't owned by the same people, and with the same permissions, your system won't run as expected to say the least.
  • Properly handling special files - Certain methods of copying a system don't properly handle the /dev and /proc filesystems, as a result, you will boot on the new drive only to find you have no device entries listed.
  • Spanning filesystems - When you are copying one filesystem to another, especially the root filesystem, you don't want to span across filesystems. That is, say you have the new hard drive mounted at /mnt/temp, if you recursively copy / to /mnt/temp and allow spanning filesystems, you could end up in a situation where /mnt/temp is copied into /mnt/temp/mnt/temp and /mnt/temp/mnt/temp is copied into /mnt/temp/mnt/temp/mnt/temp (not to mention the rest of the filesystem you have copied into /mnt/temp). To avoid this, most copying programs have some sort of option to only copy the mounted filesystem it is started from, and not to continue onto other filesystems.

What to do

With all these in mind, the best method I've found for copying the / filesystem is as follows (assuming for the example the new drive is mounted at /mnt/temp):

cd /; find ./ -xdev -print0 | cpio -pa0V /mnt/temp

注意,一定要到 source 的目錄下,才能成功執行。也要用管理者的身份,不能用 sudo。

到 source 的目錄下,再執行備份指令
find ./ -xdev -print0 | cpio -pa0V /mnt/temp
產生的 cpio 指令為
cpio: /mnt/temp/./usr/share/icons/Adwaita/24x24/actions/mail-mark-unread.png

假如使用下面的指令
find / -xdev -print0 | cpio -pa0V /mnt/hdd
執行 cpio 指令就會失敗,錯誤訊息如下
cpio: /mnt/hdd not created: newer or same age version exists
When you run this command, it will recursively copy everything on the / filesystem, without crossing over into other mounted partitions. (上述指令只會複製單一分割區,不會跨越掛載的其他分割區。) It will properly handle any special files, and it will completely preserve permissions.

If you have other filesystems mounted on other partitions, you do something somewhat similar. Say I had /boot mounted on a different filesystem, and I wanted to back it up onto /mnt/temp:

cd boot; find ./ -xdev -print0 | cpio -pa0V /mnt/temp

You simply would mount each new partition you want to copy onto, to /mnt/temp and repeat this above operation for each of those. Upon execution, you will see a series of dots fly across the screen. Each dot represents a file that is being copied. I often will go to another terminal and run watch df to watch the progress.

After all the filesystems have been copied, you probably won't actually have a bootloader. What I usually do, is go ahead and move the new drive into the place of the old one, and boot up on a Knoppix disc. Then I mount the new drive, say at /mnt/hda1, and then run grub-install –root-directory=/mnt/hda1 /dev/hda to copy my new bootloader to the new hard drive. You could probably do something similar just from your old install.

Backup and Restore

You can also use this method for a backup and restore. For example, say you want to back up your current / on machine1 onto a different Linux machine, machine2, temporarily at /home/foo/drivebackup/ (to resize your current partition or perhaps to format to a new filesytem). First take the drive from machine2 to machine1, mount machine2's drive at /mnt/temp, and run:

find / -xdev -print0 | cpio -pa0V /mnt/temp/home/foo/drivebackup

Once you do whatever it is you need to do on machine1, take the hard drive to machine2 (as repartitioning or formatting would have blanked it obviously) mount that hard drive on /mnt/temp and then run:

cd /home/foo/drivebackup; find ./ -xdev -print0 | cpio -pa0V /mnt/temp/

This will copy all the data back onto your old drive.

使用 dd

Cloning a partition \ From physical disk /dev/sda, partition 1, to physical disk /dev/sdb, partition 1:

# dd if=/dev/sda1 of=/dev/sdb1 bs=64K conv=noerror,sync status=progress

使用 tar

參考 https://help.ubuntu.com/community/BackupYourSystem/TAR

cd / 
tar -cvpzf /mnt/hdd/root_backup.tar.gz --one-file-system \
    --exclude=/proc \
    --exclude=/tmp \
    --exclude=/mnt \
    --exclude=/dev \
    --exclude=/sys \
    --exclude=/run \
    --exclude=/media \
    --exclude=/var/log \
    --exclude=/var/cache \
    --exclude=/var/run   / 

To understand what is going on, we will dissect each part of the command.

  1. tar - is the command that creates the archive. It is modified by each letter immediately following, each is explained bellow.
    • c - create a new backup archive.
    • v - verbose mode, tar will print what it's doing to the screen.
    • p - preserves the permissions of the files put in the archive for restoration later.
    • z - compress the backup file with 'gzip' to make it smaller.
    • f <filename> - specifies where to store the backup, backup.tar.gz is the filename used in this example. It will be stored in the current working directory, the one you set when you used the cd command.
  2. –exclude=/example/path - The options following this model instruct tar what directories NOT to backup. We don't want to backup everything since some directories aren't very useful to include. The first exclusion rule directs tar not to back itself up, this is important to avoid errors during the operation.
  3. –one-file-system - Do not include files on a different filesystem. If you want other filesystems, such as a /home partition, or external media mounted in /media backed up, you either need to back them up separately, or omit this flag. If you do omit this flag, you will need to add several more –exclude= arguments to avoid filesystems you do not want. These would be /proc, /sys, /mnt, /media, /run and /dev directories in root. /proc and /sys are virtual filesystems that provide windows into variables of the running kernel, so you do not want to try and backup or restore them. /dev is a tmpfs whose contents are created and deleted dynamically by udev, so you also do not want to backup or restore it. Likewise, /run is a tmpfs that holds variables about the running system that do not need backed up.
  4. It is important to note that these exclusions are recursive. This means that all folders located within the one excluded will be ignored as well. In the example, excluding the /media folder excludes all mounted drives and media there.
    • If there are certain partitions you wish to backup located in /media, simply remove the exclusion and write a new one excluding the partitions you don't want backed up stored within it. For example: –exclude=/media/unwanted_partition
  5. / - After all options is the directory to backup. Since we want to backup everything on the system we use / for the root directory. Like exclusions, this recursively includes every folder below root not listed in the exclusions or other options.

Linux file system 選擇

複製的目標檔案系統不需和原來的一樣,可以挑想要的檔案系統

關於 file system 的效能,可以參考 http://www.phoronix.com/scan.php?page=article&item=linux-40-hdd&num=1

  • XFS: 有不穩定的傾向,不要試了
  • ReiserFS: 一直留在 Gentoo 安裝指引的名單上,讓我一直想試。唉,試過之後,發現不支援 fstrim,在 SSD 上,會有問題。只好重新 format 成 ext4,最保險了。
  • Ext4 is the recommended all-purpose all-platform filesystem. 選它,大概就是一個四平八穩的方案。

目前硬碟的使用情形如下

/,根目錄,目前用了大概  40GB,就設 80GB 吧
/boot,使用 30MB,設 120 MB 吧。
swap,先前沒設? 好像也沒問題,就不需要了嗎

mkfs.ext4 /dev/sdb1
mkfs.ext4 /dev/sdb2

要 copy 整個 partition,有幾種作法,包括 dd,rsync,cpio。在下面的網址找到 cpio 的作法,就用它吧。
http://greenfly.net/tips/filesystem_migration.html

因為在 root 目錄下,有一些是目錄是 mount 其他 partition,所以,就再重新 mount 在另外的目錄下,再進行 copy。

mount /dev/sda2 /mnt/org
mount /dev/sdb2 /mnt/temp
cd  /mnt/org
find ./ -xdev -print0 | cpio -pa0V /mnt/temp
umount /mnt/org
umount /mnt/temp

mount /dev/sda1 /boot
mount /dev/sdb1 /mnt/temp
cd /boot
find ./ -xdev -print0 | cpio -pa0V /mnt/temp
umount /mnt/temp

執行 GRUB,我還是用舊的 0.97 版,其缺點是不支援 gpt,也就是硬碟超過 2TB 會有問題。但目前還可用,就將就著吧。
硬碟代碼,sda = hd0,sdb = hd1,sdc = hd2。
進入 grub 後,執行安裝指令
grub> root (hd1,0)
grub> setup (hd1)
grub> quit

接下來,就週整硬碟順序,就 OK 了。

假若是進 chroot 來 cpio 系統,然後要用 chroot 進新的磁碟,/mnt/gentoo/proc 可以直接 umount,但使用 mount --rbind 來掛載的 sys 和 dev,要用下面的方式 umount。
# grep /mnt/gentoo/sys /proc/mounts | cut -f2 -d" " | sort -r | xargs umount -n
# grep /mnt/gentoo/dev /proc/mounts | cut -f2 -d" " | sort -r | xargs umount -n


複製 CentOS 系統

以下針對 CentOS 7.9,而且沒有使用 lvm。參考 [Basic System Recovery]。

分割區的規劃如下。

# df -h
檔案系統        容量  已用  可用 已用% 掛載點
/dev/sdb3        74G  5.7G   64G    9% /
/dev/sdb1       926M  226M  637M   27% /boot
/dev/sdb5       375G  5.5G  351G    2% /home
掛載 及 chroot 指令。
# mkdir /mnt/sysimage
# mount /dev/sdb3 /mnt/sysimage
# mount /dev/sdb1 /mnt/sysimage/boot
# chroot /mnt/sysimage
掛但這樣是不夠的,在執行 grubs-install 指令時會出錯。
# grub2-install --target=i386-pc /dev/sdb
Installing for i386-pc platform.
grub2-install:錯誤: cannot find a device for /boot/grub2 (is /dev mounted?).

參考 Gentoo 的安裝指引。

# mount --types proc /proc /mnt/sysimage/proc
# mount --rbind /sys /mnt/sysimage/sys
# mount --make-rslave /mnt/sysimage/sys
# mount --rbind /dev /mnt/sysimage/dev
# mount --make-rslave /mnt/sysimage/dev
#
# chroot /mnt/sysimage /bin/bash
# source /etc/profile
# export PS1="(chroot) ${PS1}"

再次執行安裝 grub 指令,就不會出錯了。

# grub2-install --target=i386-pc /dev/sdb
Installing for i386-pc platform.
Installation finished. No error reported.

接下來要設定開機選單。

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-1160.25.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.25.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.21.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.21.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-3.10.0-1160.6.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-1160.6.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-ed726d3da8c142da88e77d06804e9ef0
Found initrd image: /boot/initramfs-0-rescue-ed726d3da8c142da88e77d06804e9ef0.img
done

列出產生的開機選單。

# awk -F\' '$1=="menuentry " {print i++ " : " $2}' /boot/grub2/grub.cfg
0 : CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-1160.21.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-1160.6.1.el7.x86_64) 7 (Core)
3 : CentOS Linux (0-rescue-ed726d3da8c142da88e77d06804e9ef0) 7 (Core)

檢查前次開機項次。

# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-1160.25.1.el7.x86_64) 7 (Core)

最後,看新硬碟是否可以成功開機,若不成功,再重複檢查上述步驟。


網誌存檔