Simple SCP notes

SCP: Copies files over the network securely; uses ssh for data transfer, using the same authentication and providing the same security as ssh.

Using:

scp [-p] [-v] [-r] [[username@]host:] file_or_dir [[username@]host:]file_or_dir

  • Putting:

scp mydata.dat [email protected]:Newname.dat

scp -r FileFolder [email protected]:/home/

  • Gettiing:

scp [email protected]:remote.data /home/local.dat

scp -r [email protected]:FileFolder /home/

Weighted random choice

Python 带权重的随机选择。via

import random

def windex(lst):
    '''an attempt to make a random.choose() function that makes weighted choices
    accepts a list of tuples with the item and probability as a pair
    like: >>> x = [('one', 0.25), ('two', 0.25), ('three', 0.5)]
    >>> y=windex(x)'''

    n = random.uniform(0, 1)
    for item, weight in lst:
        if n < weight:
            break
        n = n - weight
    return item

Quickly and powerful

新系统的开发环境在 Mac 本地部署会很麻烦,所以就直接 ssh 到远程服务器就行修改操作;而 ssh 到服务器实施环境进行 coding 响应速度又跟不上,看着终端上字符一顿一顿的就焦急,配合 svn 快速而又安全的搞定。

本地 svn ci 代码到 svn 代码库,远程服务器 svn co 到实施环境,而后,就可以在本地进行 coding,完后 svn ci 提交代码,之后 ssh 到服务器实施环境 svn up 一下即可在实施环境部署最新代码。

通过 svn 代码库进行中间代码中转,这样 coding 的时候不受网络速度影响;通过 svn 又可以进行代码托管,保证代码安全,而且可以很方便的在实施环境切换、回滚代码版本。

唯一的一个小不足就是因为无法在本地进行 debug,有时候可能为了一个小问题 svn ci 好多次,代码库里会多好多个版本。

ImageMagick Notes

  • 尺寸缩放

convert -resize 640x960 input.jpg  output.jpg

convert -resize 75% input.jpg  output.jpg

  • 去除多余 Exif 等信息

convert -strip input.jpg output.jpg

  • 调节压缩比例

convert -quality 75% input.jpg output.jpg

Happy in life

及时行善,能帮别人的时候就伸手帮一把,对你来说是举手之劳,对别人就是暖心之举。

及时行乐,善待自己,不必要那么累。

py2exe notes

Python 2.6 以上版本报错:

error: MSVCP90.dll: No such file or directory

Python 2.5 及以下运行时需要的 runtime DLL 是 MSVCR71.dll,这个打包时候会自动包含进来;Py2.6 及以上运行时需要的 runtime DLL 是 MSVCR90.dll,这个需要手动加载。在 setup.py options 字典添加 “dll_excludes”: [“MSVCP90.dll”] 解决。via

几个 options 参数 via

  • optimize:2 => extra optimization
  • includes:list of module names to include
  • compressed:1 => create a compressed zipfile
  • bundle_files:1 => bundle everything, including the Python interpreter

application failed to initialize properly (0xc0000142) 应用程序正常初始化(0xc0000142)失败

在 setup.py data_files 添加 (“Microsoft.VC90.CRT”, [‘MSVCR90.dll’,’Microsoft.VC90.CRT.manifest’]),留意 Microsoft.VC90.CRT.manifest 只能有 msvcr90.dll。 [via](http://www.py2exe.org/index.cgi/Tutorial#Step521)

Yes I Can!

接下来的工作学习方向:

  1. iPhone/Android 开发。
  2. Python/PHP Web 开发。
  3. Web 前端尤其是 JavaScript 的学习。

谨记:

  • 多沟通,一个小时解决不了的问题就问,节省时间,提高效率。
  • 做事有计划。
  • 多写文档。

One month in Beijing

真快,一个月一闪而过。

很宽松的工作环境,没有打卡没有限时,敏捷快速的开发模式,要的就是个效率。

团队人很好,很照顾我这个年龄最小工作经验最少的。每天下午的水果时间,每周三的北语羽毛球,玩的很 high.

用自己喜欢的东西做一些有意思的东西,把兴趣和工作结合起来无疑是一种幸福。

自己技术上还很弱,整体结构设计把握不住,细节实现考虑不足,还有很多要学。

Keep moving.

os.walk() digging into the specified level

os.walk() 指定递归遍历深度。

def walklevel(some_dir, level=1):
  some_dir = some_dir.rstrip(os.path.sep)
  assert os.path.isdir(some_dir)
  num_sep = len([x for x in some_dir if x == os.path.sep])
  for root, dirs, files in os.walk(some_dir):
      num_sep_this = len([x for x in root if x == os.path.sep])
      if num_sep + level <= num_sep_this:
          del dirs[:]

重点是 del dirs[:],置空 dirs,递归到此结束。

BaseHTTPServer serving Gziped content

BaseHTTPServer 使用 gzip 压缩处理 html/xml 文档。

import cStringIO, gzip
zbuf = cStringIO.StringIO()
zfile = gzip.GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
zfile.write(xmlstring)
zfile.close()

compressed_content = zbuf.getvalue()

self.send_response(200)
self.send_header("Content-Type", "text/xml")
self.send_header("Content-Length", str(len(compressed_content)))
self.send_header("Content-Encoding","gzip")
self.end_headers()
self.wfile.write(compressed_content)
self.wfile.flush()