function post($url, $post){
$context = array();
if (is_array($post)){
ksort($post);
$context['http'] = array(
'method' => 'POST',
'content' => http_build_query($post, '', '&')
);
}
else{
$context['http'] = array(
'method' => 'POST',
'content' => $post
);
}
return @file_get_contents($url, false, stream_context_create($context));
}
miniconda 安裝
安裝 miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
路徑設定
echo 'PATH="$HOME/miniconda/bin:$PATH"' >> ~/.bash_profile
chmod +x ~/.bash_profile
PATH="$HOME/miniconda/bin:$PATH"
generate random string on mac/ubuntu bash script
macos/ubuntu supported
rand_str=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 16)
echo $rand_str
macos unsupported
rand_str=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
echo $rand_str
vscode中,git push的快速鍵
開啟[偏好設定]中的[鍵盤設定]
點選左上角的{}
加入
[
{
"key": "ctrl+alt+p",
"command": "git.push"
}
]
就可以用ctrl+alt+p來推送.
git windows 換行問題
git在windows下對於pull下來檔案的換行有三種處理方式:
- true: check out時自動將\n轉換成\r\n,commit時將\r\n轉成\n.
- input: check out時不轉換\n,commit時將\r\n轉成\n.
- false: 不做任何轉換
若不清楚目前設定是哪一種,可以用下列指令查詢:
git config core.autocrlf
若要修改成input,則可用下列指令修改(請用超級管理者執行命令提示字元)
git config --system core.autocrlf input
或是(一般使用者)
git config --global core.autocrlf input
chmod 設定權限
設定test資料夾下的所有檔案權限
find test -type f -exec chmod 644 {} +
設定test資料夾下的所有資料夾權限
find test -type d -exec chmod 755 {} +
generator & list on python
generator不同於list,沒有list,且只能遊走一次.
下面的code可以發現generator的元素是在被用的時候才產生.
import time
b=[time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) for i in range(3)]
time.sleep(1)
print("A:",time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
time.sleep(1)
for ii in b:
print("B:",ii)
time.sleep(1)
###########################################################################
b=(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) for i in range(3))
time.sleep(1)
print("C:",time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
time.sleep(1)
for ii in b:
print("D:",ii)
time.sleep(1)
地震預警的構想
筆記
1868年 Copper提出的地震預警的構想
San Francisco Daily Evening Bulletin of 3rd November 1868
Earthquake Indicator
EDITOR BULLETIN.
Since the Japanese magnet indicator has proved a failure, we are now obliged to look for some other means of prognosticating these fearful convulsions, and I wish to suggest the following mode by which we may make electricity the means, perhaps, of saving thousands of lives in case of the ccurrence of more severe shocks than we have yet experienced. It is well known that these shocks are produced by a wavemotion of the surface of the earth, the waves radiating from a center just as they do in water when a stone is thrown in. If this center happens to be far enough from this city, we may be easily notified of the coming wave in time for all to escape from dangerous buildings before it reaches us. The rate of velocity, as observed and recorded in Dr. J. B. Trask’s work on Earthquakes in California from 1800 to 1864, is 61.5 (six and one fifth) miles per minute, or a little less per hour (40 miles) than the tidal wave is reported to have traveled across the ocean to this port from the Sandwich Islands or Japan. A very simple mechanical contrivance can be arranged at various points from 10 to 100 miles from San Francisco, by which a wave of the earh high enough to do damage, will start an electric current over the wires now radiating from this city, and almost instantaneously ring an alarm bell, which should be hung in a high tower near the center of the city. This bell should be very large, of peculiar sound, and known to everybody as the earthquake bell. Of course nothing but the distant undulation of the surface of the earth should ring it. This machinery would be self-acting, and not dependent on the telegraph operators, who might not always retain presence of mind enough to telegraph at the moment, or might sound the alarm too often. As some shocks appear to come from the west, a cable might be laid to the Farallone Islands, 25 miles distant, and warnings thus given of any danger from that direction. Of course there might be shocks, the central force of which was too near this city to be thus protected, but that is not likely to occur once in a hundred times.
J.D. COOPER, M.D.
Ubuntu 16.04 架設HylaFAX筆記
1.首先需要一個USB Modem以及一台Ubuntu(這邊是在iMac下用Parallels Desktop跑Ubuntu 16.04)
2.設定ttyACM相關權限
編輯udev
sudo vim /etc/udev/rules.d/70-ttyusb.rules
加入下面設定:
KERNEL=="ttyUSB[0-9]*",MODE="0666"
KERNEL=="ttyACM[0-9]*",MODE="0666"
以及透過chmod修改權限
sudo chmod o+rw /dev/ttyS0
3.安裝
sudo apt-get update
DEBIAN_FRONTEND=noninteractive sudo apt-get install -y cu hylafax-server hylafax-client
4.測試USB Modem
sudo cu -l ttyS0
出現connected.既可按兩下“.離開
5.設定HylaFAX
sudo faxsetup
6.設定撥號前按下0
sudo vim /var/spool/hylafax/etc/config.ttyACM0
修改ModemDialCmd設定:
ModemDialCmd: ATX3D0T%s # press 0 before dialing
7.傳真a.pdf至11223344
sendfax -n -d 11223344 a.pdf
8.查看
#歷史狀態
faxstat -d
#接收狀態
faxstat -r
#傳送狀態
faxstat -s
9.刪除job 1
faxrm 1
10.清除所有傳送資料(如果隔一陣子想要清除所有傳送資料的話)
sudo service hylafax stop
sudo rm -rf /var/spool/hylafax/docq/*
sudo rm -rf /var/spool/hylafax/doneq/*
sudo rm -rf /var/spool/hylafax/info/*
sudo rm -rf /var/spool/hylafax/log/*
sudo rm -rf /var/spool/hylafax/sendq/*
sudo service hylafax restart
faxstat -d
install nodejs on macos with nvm
#安裝nvm
brew install nvm
#設定路徑
echo "source $(brew --prefix nvm)/nvm.sh" >> ~/.bash_profile
. ~/.bash_profile
#查看版本
nvm ls-remote
#安裝8.x
nvm install v8.15.1
#顯示已安裝版本
nvm ls
#切換版本
nvm use v8.15.1
#設定PATH
echo "PATH=$PATH:$(dirname $(nvm which v8.15.1))" >> ~/.bash_profile
. ~/.bash_profile