分類
Linux 软件

nano文本編輯器

nano是一個方便易用的命令行文本編輯器,相對於vi等文本編輯器勝在學習成本低廉而且linux平臺基本自帶(甚至android的busybox都有)。用nano常用的命令就是Ctrl+O寫入文件,Ctrl+X關閉文件,Ctrl+W查找文字。其他功能也很容易找到幫助,很適合不經常用linux的用戶(vi不常用的話,命令真的忘的好快)。

nano的複製粘貼也是很方便的。常用的就是CRTL+6用來選擇,ALT+6用來複製,CTRL+U用來粘貼。複製當前行的話直接ALT+6即可。

如果想把nano設置為默認的文本編輯器,比如使用crontab -e時,可以在~/.bashrc最後添加

export EDITOR=nano
export VISUAL=nano

如果要在多個文件間複製粘貼,可以用nano -F file1以多文件模式打開。打開之後,複製完按CTRL+R開啟另一個文件,就可以粘貼進去了。文件間的切換用ALT+,和ALT+.。

本文更新於 2017/03/22。

分類
Linux

Host a Debian in Win7 VirtualBox

正常的安裝就是在VirtualBox裡添加虛擬機,掛載下載好的Debian鏡像,即可安裝完成,最後安裝VirtualBox的附加組件,一路應該很順利。實際感覺是Debian比Ubuntu要稍微麻煩些。

apt的設置

如果你在安裝系統的時候就設置好了且工作正常,則不用設置。設置軟件源

nano /etc/apt/sources.list
我的是
deb http://ftp.debian.org/debian stable main contrib non-free
deb-src http://ftp.debian.org/debian stable main contrib non-free

給apt設置代理

nano /etc/apt/apt.conf.d/70debconf
#ubuntu下是/etc/apt/apt.conf
我的是在底部添加
Acquire::http::proxy "http://192.168.1.2:8123/";
Acquire::ftp::proxy "http://192.168.1.2:8123/";
這是的代理是Win7里運行的Shadowsocks。

安裝VirtualBox附加組件

轉自Installing Guest Additions on Debian。安裝完成後就可以共享剪切板和自由縮放屏幕大小了。

  1. Login as root;
  2. Update your APT database with apt-get update;
  3. Install the latest security updates with apt-get upgrade;
  4. Install required packages with apt-get install build-essential module-assistant;
  5. Configure your system for building kernel modules by running m-a prepare;
  6. Click on Install Guest Additions… from the Devices menu of VirtualBox, then run mount /media/cdrom.
  7. Run sh /media/cdrom/VBoxLinuxAdditions.run, and follow the instructions on screen.

添加中文支持

dpkg-reconfigure locales
空格選擇,回車確認。我選擇了這幾個
  • zh_TW BIG5 - 繁體中文(台灣),使用 Big5 碼
  • zh_TW.UTF-8 UTF-8 - 繁體中文(台灣),使用 UTF-8 碼
  • zh_HK.UTF-8 UTF-8 - 繁體中文(香港),使用 UTF-8 碼
  • zh_CN GB2312 - 簡體中文,使用 GB2312-80
  • zh_CN.GBK GBK - 簡體中文,使用 GBK
  • zh_CN.UTF-8 UTF-8 - 簡體中文,使用 GB18030
然後首選項選擇了zh_CN.UTF-8。

安裝字體:

apt-get install ttf-arphic-uming  xfonts-intl-chinese  xfonts-wqy

安裝輸入法:

apt-get install fcitx-sunpinyin
apt-get install im-switch

重啟就好了。


Debian使用systemd開機啓動

我裝的是Debian8,似乎已經不再支持rc.local了。以ss爲例,開機啓動可以這麼添加:首先新建開機服務文件

nano /lib/systemd/system/ss.service
內容爲
[Unit]
Description=ss

[Service]
Type=simple
ExecStart=/usr/local/bin/ss-local -c /etc/shadowcksB.json > /home/$YOURNAME/.sslog 2$
PrivateTmp=true

[Install]
WantedBy=multi-user.target
ss用到的文件/home/$YOURNAME/.sslog需要自己新建touch下。

將服務設置爲開機啓動:

systemctl enable ss.service

測試服務是否正常:

systemctl start ss.service

查看當前服務狀態:

systemctl status ss.service -l

順便再貼一個polipo的開機啓動文件

[Unit]
Description=polipo
After=network.target

[Service]
Type=forking
ExecStart=/etc/init.d/polipo start
ExecReload=/etc/init.d/polipo restart
ExecStop=/etc/init.d/polipo stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target

安裝flashplayer

Debian自帶的瀏覽器和火狐都沒有Flash,可以按照如下步驟安裝:
1, Lauch the browser and download the Flash Player in a seperate folder.Download link = http://get.adobe.com/flashplayer/
2, tar xzvf yourdownloadedfilename.tar.gz
3, cp libflashplayer.so /usr/lib/mozilla/plugins/

本文更新於 2016/05/19。

分類
Linux

shadowsocks client and firefox on Ubuntu 12


Shadowsocks Client

下載Shadowsocks-libev:https://github.com/madeye/shadowsocks-libev
unzip解壓至/home/me/Downloads/AppSrc/shadowsocks-libev cd到此目錄,運行

./configure
sudo make install

如果運行configure提示ssh header error,請安裝libssl-dev。Centos、Fedora下請安裝zlib-devel。如果提示ssl有問題,Fedora下可安裝openssl-devel。

新建配置文件

sudo nano /etc/shadowcks.json

粘貼進下面文本並保存

{
"server":"服务器的ip",
"server_port":服务器的端口,
"local_port":你的本地端口,默认1080,
"password":"密码",
"timeout":600,
"method":"加密方式"
}

運行下面命令啓動shadowsocks服務

ss-local -c /etc/shadowcks.json

如果提示隨機數不足,可以安裝rng-tools

yum install -y rng-tools
systemctl start rngd
systemctl status rngd
systemctl enable rngd

加入開機自動啟動:

#先建一個log文件
touch /home/me/.sslog
#将下面一行加入/etc/rc.local
/usr/local/bin/ss-local -c /etc/shadowcksB.json > /home/me/.sslog 2>&1 &

Firefox

從這裏下載firefox,或者通過市場安裝。火狐市場好像還沒被干擾,所以直接進插件市場搜索FoxyProxy安裝並重啓。點擊FoxyProxy圖標,新建代理服務器,選擇手動配置代理服務器,輸入127.0.0.1和端口,選中socks v5。URL模式勾選不要對內部網絡選項。保存後轉到訂閱模式,添加新的訂閱模式,訂閱網址http://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txthttps://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt,代理服務器選擇剛剛新建的。Format選AutoProxy,Obfuscation選Base64。確定保存,如果訂閱添成功此時前面URL模式中應該多了很多項。最後將工作模式設置爲使用基於其預定義模板,就可以自動分流了。

18年09說06日,Firefox ESR版本也自動升級到了Quantum(版本號>60)。新版對於附加原件有較大改動,以至FoxyProxy老版本不能運行。雖然FoxyProxy作者開發了新版本,但是試用之後沒有找到導入gfwlist.txt的地方。搜了一下,發現SwitchOmega有了火狐的插件,雖然是測試版,用起來卻很好用。在auto swith中導入https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt就能自動分流,而且有加載不到的資源還可快速加入白名單,真實非常方便。


家裏長城寬帶按照上述方法無效。多數內容複製了+McNulty Gracie的帖子。

讓命令行通過shadowsocks的socksv5代理聯網

安裝proxychains

sudo apt-get install proxychains

修改配置文件/etc/proxychains.conf,更改如下4行:

dynamic_chain
#strict_chain
#socks4         127.0.0.1 9050
socks5    127.0.0.1 1234 #你的本地代理地址和端口

測試下proxychains:

proxychains wget -O - http://myip.dnsdynamic.org/ | more
#如果成功會顯示出你代理服務器的IP

Ubuntu搭建Shadowsocks

安裝

sudo apt-get install python-pip python-m2crypto supervisor
sudo pip install shadowsocks

编辑 /etc/shadowsocks.json

#sudo nano /etc/shadowsocks.json
{
"server":"0.0.0.0",
"server_port":服务器的端口,
"local_port":1080,
"password":"密码",
"timeout":600,
"method":"aes-256-cfb"
}

编辑 /etc/supervisor/conf.d/shadowsocks.conf

#sudo nano /etc/supervisor/conf.d/shadowsocks.conf
[program:shadowsocks]
command=ssserver -c /etc/shadowsocks.json
autorestart=true
user=nobody
#如果端口 < 1024,把上面的 user=nobody 改成 user=root

在 /etc/default/supervisor 最后加一行:

ulimit -n 51200

reboot或者

service supervisor start
supervisorctl reload

Ubuntu或CentOS分享Shadowsocks給局域網用戶

安裝polipo

sudo apt-get install polipo

在配置文件/etc/polipo/config的末尾貼上下面的配置信息

proxyAddress = "0.0.0.0"

socksParentProxy = "127.0.0.1:1080"
socksProxyType = socks5

chunkHighMark = 50331648
objectHighMark = 16384

serverMaxSlots = 64
serverSlots = 16
serverSlots1 = 32

重啟polipo

/etc/init.d/polipo restart

現在就可以在局域網設備上使用http代理了,主機為運行ssclient的ip地址,端口為8123。

本文更新於 2024/04/19。

分類
网站

沃通免费数字证书试用

申请了沃通的免费数字证书,现在网站也可以用https访问了。申请很方便,只需要提供个邮箱就可以了,而且很快就能拿到手。网站所有权我用的是上传文件的方式验证的,也算方便。Vesta面板在SSL方面设计很方便,可以手动生成CSR,然后把生成的证书请求粘贴给沃通,自己把其他部分都存起来。证书下来后,解压for Other Server.zip,在Vesta面板SSL配置区中,SSL证书就粘进去4_yoursite.crt;SSL Key就粘前面生成CSR时生成的RSA PRIVATE KEY;SSL证书颁发机构这个虽然写的可选,实际是必填项,需要依次粘入3_issuer,2_cross,1_root。这样就完成了。

wordpress在settings-general里把两个链接前都改为https,后台就是https了。前台直接写https访问就是https,否则还是http。


之前填写错误,导致PC端没问题,手机端一直提示不被信任。后来找客服,客服态度非常好,折腾几下没成功后来直接远程给我操作了!

本文更新於 2015/01/14。

分類
网站

nginx和yii2

记录下Ubuntu12.04安装nginx遇到的问题。

nginx安装好后打开php遇到File not found

修改/etc/nginx/conf.d/default.conf文件。首先在server下添加root,然后修改fastcgi_param为SCRIPT_FILENAME $document_root$fastcgi_script_name;

server {
    listen       80;
    server_name  localhost;
    root         /usr/share/nginx/html;

    #charset koi8-r;
    ...
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
    ...

php升级到5.5

新版Yii要求php5.4或更高,但Ubuntu12.04库中的默认版本是5.3.所以我就直接添加PPA升级了。

sudo apt-get update && sudo apt-get install python-software-properties  
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update && sudo apt-get dist-upgrade

升级后打开php页面出现502 Bad Gateway,把/etc/php5/fpm/pool.d/www.conf中listen = /var/run/php5-fpm.sock替换成listen = 127.0.0.1:9000就好了。可能是升级后/var/run/php5-fpm.sock被删除了。更多升级到5.5导致502 Bad Gateway,请参考Fix “502 Bad Gateway” error on NGINX server after upgrading PHP

安装phpmyadmin

sudo apt-get install phpmyadmin  
sudo ln -s /usr/share/phpmyadmin/ /usr/share/nginx/html/phpmyadmin

如果nginx配置文件没有加index.php会出现403错误。应该把/etc/nginx/conf.d/default.conf中字段配置为这样:

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

安装Composer

curl -sS https://getcomposer.org/installer | php  
sudo mv composer.phar /usr/local/bin/composer

通过Composer安装yii

首先切换到网站目录下,如/opt/lampp/htdocs。安装basic版:

sudo php composer.phar create-project yiisoft/yii2-app-basic basic 2.0.1

安装advanced版

sudo php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.1

本文更新於 2015/04/04。

分類
其它

Xpera Z刷入原版印度4.4.4系统

国行Z编号为C6602,目前XDA论坛有印度原版系统可供下载,参见:[STOCK ROM][FTF] Xperia Z (C6602) 10.5.1.A.0.283 Generic IN (India)。根据帖子先去下载位于MediaFire的FTF文件。问题来了,goagent是搞不定,用手机上的SuperVPN和Psiphon也搞不定,最后找到一个网站可以帮忙中转下载。访问http://premium4.us/把MediaFire的网址直接放进去,就能获得下载地址速度还很快!我是从免费高会中转站列表找到的premium4这个网站。

FTF下载好了,接下来就好办了。按照[GUIDE] How to package and flash stock roms with Flashtool,安装那两个软件,然后按照图示一步一步做就可以了。图示是我见过最详细的图示了!

刷这个系统我是单纯为了Google框架。而且刷机后,不影响原来的数据。有个小插曲是,我之前直接在国行刷的google框架,但是老是弹出错误,后来待同步完联系人和获取到一些软件的认证后我就把google框架用Link2SD给冻起来了,结果刷机前没有解冻,导致新刷的框架也是冰冻状态。不过也没什么大问题,root后用Link2SD解冻就好了。

分類
其它

大众点评的抽奖号算法

抽奖号计算方法

开奖当日收盘时的上证指数×深证成指×恒生指数=12位数,取整(指数以证交所公布数字为准)
将此12位的数字倒序排列后(如首位是0,则直接抹去),再除以前一天截止24:00本次活动的人数(每个抽奖号为一个人数),得到的余数加1即为1个获奖号码
(余数是指整数除法中被除数未被除尽部分。例如27除以6,商数为4,余数为3)
每逢股市停盘,顺延到股市开盘后按上述算法计算后除以截止到周日24点的参加人数,得到的余数加1即为第一个中奖号码。
(若抽到点评网的员工及家属,则继续加1,若加上后数字溢出,则用溢出后的数字除以人数,再取余数加1,得到获奖号码)

例如:
抽奖时间为10月13日--10月14日 ,10月15日 16:00抽取中奖号码
假设截止到10月14日的24:00,抽奖人数共148652
10月15日收盘的上证指数为2749.15,深证指数为11795.33,恒生指数23881.51
2749.15*11795.33*23881.51=774408864460.179
取整数,倒序064468804477
除以148652,余数67249,67249+1=67250
所以本期中奖号码为67250