Always Trust .rvmrc File

使用Octopress的时候目录里默认存在一个.rvmrc文件,

1
rvm use 1.9.3

目测是指定ruby版本用的。每次进入目录都会有Do you wish to trust this .rvmrc file?的提示,需要手动确认。 还是挺烦的…

其实,rvm list 可以看到我机子上只有这一个版本

1
2
3
rvm rubies

=> ruby-1.9.3-p327 [ x86_64 ]

所以这个 .rvmrc 是毫无意义的,可以删掉… 或者在~/.rvmrc里写入export rvm_trust_rvmrcs_flag=1

Hylang

发现一个极好玩的项目,hylang,结合 List 跟 python 的写法…

Lisp and Python should love each other. Let’s make it happen.

https://github.com/hylang/hy

  • Code: https://github.com/hylang/hy
  • Docs: http://hy.rtfd.org/
  • Quickstart: http://hy.rtfd.org/quickstart

社区

https://github.com/hylang

以及由此发现的 python 实现语法词法分析相关的东东

`python setup.py` Install vs. `pip Install .`

一些坑。

Distutils

http://docs.python.org/2/distutils/setupscript.html#installing-package-data

setuptools & pip

Building and Distributing Packages with Setuptools

https://pypi.python.org/pypi/setuptools/ http://www.pip-installer.org/en/latest/usage.html#pip-install http://www.pip-installer.org/en/latest/logic.html#git http://stackoverflow.com/questions/6947988/when-to-use-pip-requirements-file-versus-install-requires-in-setup-py https://groups.google.com/d/msg/python-virtualenv/1eI6Z9_XRHE/cj6CCHvmS10J http://stackoverflow.com/questions/2087148/can-i-use-pip-instead-of-easy-install-for-python-setup-py-install-dependen

requirements.txt

from pip.req import parse_requirements

http://stackoverflow.com/questions/14399534/how-can-i-reference-requirements-txt-for-the-install-requires-kwarg-in-setuptool?answertab=votes#answer-16624700

Require pip>=1.2, as lower versions have a bug https://github.com/erikrose/peep/commit/65367f66b777f17b1223569e1cd2f6250a820e99

尽管提供了dependency_lins依然默认安装PyPi版本的坑

http://stackoverflow.com/questions/17366784/setuptools-unable-to-use-link-from-dependency-links/17442663#17442663 http://www.pip-installer.org/en/latest/logic.html#requirements-file-format

Writing a Package in Python

Pip Uninstall Editable Pkgs

http://stackoverflow.com/questions/17346619/how-to-uninstall-editable-packages-with-pip-installed-with-e

At {virtualenv}/lib/python2.7/site-packages/

  • remove the egg file (e.g. distribute-0.6.34-py2.7.egg)
  • from file easy_install.pth, remove the corresponding line (it should be a path to the source directory or of an egg file).

Setup Raspberry Pi on OS X

折腾了下树莓派,买了 PL2303串口TTL下载线,跟一个8G C10的TF带SD卡套。

只能串口访问,没买usb无线,没有多余网线。。不能SSH、开VNC。。不幸福

等能联网了再来折腾吧 →_→


setup the SD card

  • 用DiskUtil把sd卡erase成ExFat格式
  • 执行 df -h 来获得sd卡的设备路径
  • 将系统img写入sd卡
1
2
3
4
5
tclh123@tclh123MBP ~ $ sudo dd bs=1m if="/path/to/2013-09-25-wheezy-raspbian.img" of=/dev/rdisk2
Password:
2825+0 records in
2825+0 records out
2962227200 bytes transferred in 168.735466 secs (17555451 bytes/sec)

And you can use killall -INFO dd to check the status of dd in progress (link)

串口通信

  • 下载PL2303串口驱动

http://www.prolific.com.tw/US/ShowProduct.aspx?p_id=229&pcid=41 安装完需要重启。。

  • 下个minicom

brew install minicom

ps. 我不知道为什么直接用screen连 screen /dev/tty.usbserial 9600 会乱码加卡死。。

Solve A+B Problem in Python & One Line

Classical ACM/ICPC Problem

one test case is easy, how to support multi- test cases?

ex.

1
2
3
4
5
6
7
# Input
1 2
2 4

# Output
3
6

in python 2.x

1
from __future__ import print_function; import sys; map(lambda x: print(sum(x)), [map(int, line.split()) for line in sys.stdin]);

You can test it on the Online Judge. :)

Use Pandoc and LaTeX on OS X

Installing

For PDF output, you’ll also need LaTeX. We recommend installing BasicTeX (64M), and using the tlmgr tool to install additional packages as needed.

Just download and run the pkg files.

Then add /usr/texbin to your $PATH(export PATH=${PATH}:/usr/texbin;).

Now, you get them installed.

1
2
3
pandoc --version

pdflatex -v

Install tlmgr

tlmgr - TeX Live package manager

1
2
3
curl http://ftp.ctex.org/mirrors/CTAN/systems/texlive/tlnet/update-tlmgr-latest.sh -O
chmod a+x update-tlmgr-latest.sh
./update-tlmgr-latest.sh
My Output
1
2
3
4
5
6
7
8
9
10
Verifying archive integrity... All good.
Uncompressing TeX Live Manager Updater...........................................................................................................................................................................................
./runme.sh: updating in /usr/local/texlive/2013basic...
./runme.sh: tlmgr version says this is TeX Live 2013
./runme.sh: proceeding with tlmgr update.
D:tlmgr:main: ::tldownload_server defined
D:Using shipped /usr/local/texlive/2013basic/tlpkg/installer/wget/wget.x86_64-darwin for wget (tested).
D:Using shipped /usr/local/texlive/2013basic/tlpkg/installer/xz/xzdec.x86_64-darwin for xzdec (tested).
D:Using shipped /usr/local/texlive/2013basic/tlpkg/installer/xz/xz.x86_64-darwin for xz (not tested).
./runme.sh: done.

and you can check the version by tlmgr --version

setting default package repository
1
sudo tlmgr option location http://mirror.ctan.org/systems/texlive/tlnet/

Simple Usage

1
pandoc test1.md -s -o test1.pdf

TO be continued

Reference

  • https://github.com/mwhite/resume
  • http://tug.ctan.org/
  • http://www.ctan.org/tex-archive/fonts/tex-gyre/
  • http://www.ctan.org/tex-archive/macros/latex/contrib/titlesec
  • http://tex.stackexchange.com/questions/10706/pdftex-error-font-expansion-auto-expansion-is-only-possible-with-scalable
  • http://www.tug.org/mactex/morepackages.html
  • http://www.tug.org/texlive/
  • http://cmwelsh.com/beautiful-resumes-with-markdown-and-latex
  • http://sysadvent.blogspot.jp/2011/12/day-14-write-your-resume-in-markdown.html

Python Plugin/MixIn/Monkey-patching

自从到豆瓣实习后,基本就博客就没更了,在github上的活动也都转到了code上…

Reference

折腾Chrome Secure Shell

最近的觉悟是自己写代码太慢,对IDE的依赖是累积的,各种恶性循环(不足够了解语言,不熟悉项目结构)。半天憋不出几行代码,这种状态让人厌恶…以前对此持观望态度,各种纵容自己,现在发现这已经成为自己的一大瓶颈…

这东西上次hack day的时候看 atupal用过,印象蛮深。今天挖出来玩玩。

商店安装的时候,提示This application is not supported on this computer. Installation has been disabled.,安装按钮直接变灰了。Google无果,看了下自己的Chrome版本,22…(mbp买来到现在没更过的节奏…),然后用”关于”里的自动更新报Error 12(以前也是这样所以一直没更吧..)。

OS X下更新Chrome遇到Error 12

试了官方提供的方法,木有用。。Google出来的也大致都是删掉SoftwareUpdate然后再装一遍的意思,以及各种偏方,无果。

然后想是不是因为现在版本太低(22->28)的缘故,最后直接把最新的下来覆盖了。后来发现完全无痛啊,因为现有的东西包括Extensions的localStorage都是放在Application Support/里的么。。

配置Secure Shell

然后很舒服地用着最新版,顺利地把Secure Shell装上了。

然后其实也不用什么配置是吧,输个<username>@localhost就好了。。结果报Connection refused。。用iTerm试了下ssh localhost同样是Connection refused(sshd服务没开的节奏…)

启动sshd服务
1
sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist # unload是停止服务
查看是否启动
1
2
3
sudo launchctl list | grep ssh
...
-   0   com.openssh.sshd # 看到这个说明成功启动了

ok,现在已经可以顺利ssh到本地了。

另外,还可以直接授权publickey,这样就不用每次都输密码了(但是还是要输一次id_rsa私钥的密码,后面貌似shell会记住)。

直接把id_rsa.pub写入authorized_keys文件就行了
1
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

配置SSH root用户登陆

用自己的账户登陆是ok了,但是尝试用root登陆时提示Permission denied (publickey,keyboard-interactive)错误。

先是加了/etc/sshd_config里的PermitRootLogin yes(开始把ssh_config跟sshd_config搞错了。。图样)。还是不行。

后来发现是OS X默认没有开启root用户,我输入的密码也只是a valid sudoer password,根本不是root的密码。

设置root的密码
1
sudo passwd

之后就可以用root账户登陆了。

其他

Chrome Secure Shell 用起来很方便也很爽。但是我发现ls的时候中文目录名会乱码,中文文件内容可以正常显示。

还有就是不能输入中文(输入法无效。。)。

http://git.chromium.org/gitweb/?p=chromiumos/platform/assets.git;a=tree;f=chromeapps/hterm,这个据说是前端的源码,可以拿来研究下(kido参考)。但是clone了半天搞不下来。。= =(噗。。现在看了一下貌似死在3%了..)

Reference

  • https://discussions.apple.com/thread/1141223?start=0&tstart=0
  • http://blog.smitec.net/posts/setting-up-a-git-server-on-osx/
  • http://superuser.com/questions/555810/how-do-i-ssh-login-into-my-mac-as-root

ImportError Using Flask

巨二。

以后别把包名取做site,import的时候会跟python标准库里的site.py冲突。。