SQL, 帳號密碼查詢的建議做法

測試資料:

INSERT INTO `test` (`user`, `pswd`) VALUES ('test', 'ABcd+1234');

一般常見做法

SELECT `user` FROM `test` WHERE `user`='test' and `pswd`=sha1('ABcd+1234')

較安全做法,但是會增加DB CPU的功耗!

SELECT `user` FROM `test` WHERE `user`='test' and sha1(CONCAT(`pswd`,9999))=sha1(CONCAT(sha1('ABcd+1234'),9999))

centsos 基本安裝參考指令

#更新
yum update -y && yum autoremove -y

#安裝常用工具,如vim/wget/openssh-server/nslookup/ping/ifconfig
yum install -y git vim wget openssh* nfs-utils nfs-utils-lib open-vm-tools net-tools bind-utils iputils yum-utils

#設定ssh
mkdir -p ~/.ssh
cat <<EOF > ~/.ssh/config
Host *
    StrictHostKeyChecking no
EOF

#關閉swap
SWAPLINE=$(cat /etc/fstab | grep swap | awk '{print $1}' | sed 's/\//\\\//g')
sed -i "s/$SWAPLINE/#$SWAPLINE/g" /etc/fstab 
swapoff -a
free -m

#關閉SELINUX
setenforce 0
sed -i s/^SELINUX=.*$/SELINUX=disabled/ /etc/selinux/config
systemctl disable firewalld.service
systemctl disable libvirtd.service

#Forward Policy
iptables -P FORWARD ACCEPT

#關閉防火牆
iptables -P FORWARD ACCEPT
systemctl stop firewalld
systemctl disable firewalld

#NTP校時
yum install ntp ntpdate ntp-doc -y
cat > /etc/ntp.conf  <<EOL
restrict 127.0.0.1
restrict ::1
server time.stdtime.gov.tw  minpoll 1 maxpoll 3
server tock.stdtime.gov.tw  minpoll 2 maxpoll 3
server watch.stdtime.gov.tw minpoll 3 maxpoll 4
server clock.stdtime.gov.tw minpoll 4 maxpoll 5
server tick.stdtime.gov.tw  minpoll 5 maxpoll 6
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EOL

systemctl stop ntpd
ntpdate time.stdtime.gov.tw
systemctl enable ntpd
systemctl start ntpd
ntpq -p

[code] post

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"

git windows 換行問題

git在windows下對於pull下來檔案的換行有三種處理方式:

  1. true: check out時自動將\n轉換成\r\n,commit時將\r\n轉成\n.
  2. input: check out時不轉換\n,commit時將\r\n轉成\n.
  3. 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.