Yi's Blog

不图新奇,但问优劣

Fix Soft Links in an Archived File

OS X 10.8 sdk was not included in Xcode 6.1, so if you want to use that sdk, you have to add it to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ yourself. For me, the reason I needed 10.8 sdk was I wanted to compile objc runtime source code with it so I can debug the code.

How to get the previous sdks

You can extract previous sdks from old versions fo Xcode. Or you can get them more efficently from this repository(phracker/MacOSX-SDKs) by using git or just downloading the zip file.

But if you choose downloading the zip file, the zip format will break all the soft link by changing them into plain text files.

How to fix it

In order to fix it, I wrote several lines of python. Here is the code:

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# vim: set et sw=4 ts=4 sts=4 ff=unix fenc=utf8:
# Author: Jeswang<wangyi724@gmail.com>
#         http://blog.jeswang.org
# Created on 2014-10-22 13:03:12

import os

def file_exists(filename):
    try:
        with open(filename) as f:
            return True
    except IOError:
        return False

def folder_exists(foldername):
    try:
        os.walk(foldername).next()
        return True
    except StopIteration:
        return False

def generateSoftLink(realfile, linkfile):
    print("%s -> %s" % (linkfile, realfile))
    os.symlink(realfile, linkfile)

def generateSoftLinkForPath(path):
    list_of_files = {}
    for (dirpath, dirnames, filenames) in os.walk(path):
        for filename in filenames:
            print filename
            linkfile = dirpath+"/"+filename

            if os.path.islink(linkfile) or os.path.getsize(linkfile) > 200:
                continue

            f = open(linkfile)
            relpath = f.readline()
            f.close()

            if len(relpath) == 0:
                continue

            relpath = relpath.replace("\n", "")

            if len(relpath.replace("/", "")) == 0:
                continue

            realfile = dirpath+"/"+relpath

            if file_exists(realfile) or folder_exists(realfile):
                os.remove(linkfile)
                generateSoftLink(relpath, linkfile)

if __name__ == "__main__":
    generateSoftLinkForPath("/Users/jeswang/Downloads/MacOSX-SDKs-master")

The tricky part is, under mac os x python’s function os.path.exists can’t deal well with soft links, so you have to test whether there is a file or folder in given path by trying to read the file or list the folder.

Because of the recursion of references, you may need to run this script several time to make sure all the soft link have be changed back.

- EOF -

(++a)+(++a)+(++a) 的计算结果

今天被问到如下代码的输出是多少:

#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
    int a = 0;
    int b = (++a) + (++a) + (++a);
    cout<<b;
    return 0;
}

面试中被问到的 iOS 开发相关的问题

说来惭愧,已经面了几个公司的 iOS 开发岗位,几次被问倒——有些问题回答得比较含糊,有些问题只知道结果,不知道原理。根据回忆,梳理一下不太明白的一些问题,尽管对问题的解答只是点到为止,也算为以后的学习留点线索。

LeetCode for iOS 1.1 版

leetcode-1.1

1.1.0 版发布说明:

  • 新功能:
    • 查看每道题给出的样例解法了
    • 支持 iPhone 6/6 Plus
  • 修正 Bug:
    • iPad 上的搜索动画修复

树的后续遍历

题目:树的后序遍历

解法:

一共尝试了 3 种解法:

  • 使用两个 Map 记录是否访问过了左右子树(当然也可以放到一个 Map 中来)
  • 只用一个栈以及上次访问的节点做后序遍历
  • 传统的递归方法,用于验证

我的软件工具箱 - MAC 软件列表

用 Mac 系统有一段时间了,也逐渐积累了一些好用、不折腾的软件,列表如下:

便捷使用

社交应用

网页浏览:

  • Chrome [link]
  • Firefox [link]
  • Reeder 2(查看订阅的 feed) [link]
  • 知了(查看知乎日报) [link]

整理思路

  • Mindnode pro [link]
  • Omnigraffle(原型设计) [link]
  • Omnifocus(计划清单) [link]
  • Byword(Markdown 写作) [link]
  • Scrivener(写作工具,可以用来写小说,但是需要学习一下如何使用) [link]

程序设计

设计

  • Sketch [link]
  • Photoshop
  • Illustrator
  • Ember(收集、浏览素材用)[link]

变身很酷的命令行使用者

  • iTerm2(替代自带 Terminal) [link]
  • Oh-my-zsh(用 zsh 替代自带的 bash)[link]
  • Brew(Mac 开发者的工具箱)[link ]

前前后后花钱买的这些软件里就属 Adobe Design Suite CS6 最贵,花了 ¥900 买的教育优惠版。虽然不是最新版,但是相比 CC 的按月付费,心里还是舒服得多。

最后,还是推荐没有用过的 Mac 的同学有机会尝试一下,大部分软件界面风格统一,功能小巧实用,你会喜欢上它们的。

- EOF -