Category Archives: OS

在Mac里安装单独的python

mac已经自带了python了,版本也还比较新。如果想自己控制python的版本的话,可以用brew来安装单独的python.

brew install python

brew安装的命令会在/usr/local/bin里面,如果系统自带了一些工具在/usr/bin里,那么brew安装的可能无法被使用到。所以需要将/usr/local/bin放到 /usr/bin前面去

brew doctor会提供修复的命令:

Consider setting your PATH so that /usr/local/bin
occurs before /usr/bin. Here is a one-liner:
    echo 'export PATH="/usr/local/bin:$PATH"' >> ~/.zshrc

修改之后source ~/.zshrc就可以使用最新版的python了

➜  python --version
Python 2.7.11
➜  which python
/usr/local/bin/python

 

 

enable xtrafinder to work under OS X 10.11 El Capitan

据说是OSX 10.11开启了一个System Integrity Protection的功能,所以Xtrafinder就无法正常工作了。

解决的方法,就是部分关闭SIP的功能,具体看:

How to modify System Integrity Protection

You must boot into the Recovery OS. You do this by restarting your machine, and holding COMMAND + R until the Apple logo appears.

Then select Terminal from the Utilities menu. It looks like this:

In the window that opens, type csrutil enable --without debug and press return.

This turns off the part of SIP that XtraFinder needs to run, and OS X complains that it is an unsupported configuration.

Now type reboot and press return to restart your machine.

 

MBP合上盖的时候不自动Sleep

当关上MBP的盖子的时候,机器就自动进入休眠状态了,如果这时候有啥活动的term/ftp等连接,都会被断掉。这个很不爽!

幸好有软件可以禁止apple的这个行为:

InsomniaX

http://semaja2.net/insomniaxinfo

Description:
It always has been a missing feature: disabling the sleep mode on a Apple Laptop. Who does not want to use it as a big juke-box or go warwalking. The best looking server ever, especially at about one inch height. This small utility is what you will want, this small utility acts as a wrapper to the Insomnia kernel extension.

macosx-nosleep-extension

https://code.google.com/p/macosx-nosleep-extension/

Close your MacBook without putting it to sleep

Projects consists of kext and userspace tools that help to manage sleep behavior.

NoSleep makes closing of your MacBook lid possible without going to a sleep mode. Now you shouldn’t have to plug your mouse and monitor to stay computer awake – just activate it by clicking a menu bar icon or check a tick in the System Preferences and continue downloading huge files and watching favorite movies over the network with lid closed.

Caffeine

Caffeine is a small, free app for Mac users by lighthead software. You can download it from their site or from the Mac App Store. Once installed, Caffeine sticks a small coffee cup icon in your menu bar, and presents you with its preference screen.

 

mac下的文件比较工具

Kaleidoscope

据说是可以媲美windows下beyond compare的工具,不过够贵,69.99$

http://www.kaleidoscopeapp.com/

VisualDiffer

据说也不错,Mac app store有,才4.99$, 便宜多了

http://visualdiffer.com/

Beyond Compare

Windows下面的工具,现在移植到了Mac下,处于beta中,应该也不错吧

http://www.scootersoftware.com/beta.php

 

 

Mac下Clipboard的增强器ClipMenu

ClipMenu represents the best combination of simplicity and power that I’ve found in a clipboard manager. It has all the features I need: a completely customizable history, support for text and image clips and a keyboard activated pop up window. It even has some really powerful options that I now couldn’t live without such as a snippets manager and a robust actions system that allows you to manipulate strings of text (change the case, wrap with tags, etc.).

The thing that really makes me love ClipMenu is that it doesn’t even really feel like an app. Instead it feels like a natural extension of OS X. I’ve tried some really expensive and fancy options that I didn’t like half as much. If you’re in the market for a clipboard manager, start here.

http://www.clipmenu.com/

 

Mac的delete键

mac下的delete键相关的快捷键:

1、按 delete 键,实现 Windows 键盘上退格键(Backspace)的功能,也就是删除光标之前的一个字符;
2、按 fn+delete 键,删除光标之后的一个字符,相当于传统Windows的delete键;
3、按 option+delete 键,删除光标之前的一个单词(英文有效);
4、按 command+delete 键,删除光标之前整行内容;
5、选中文件后按 command+delete,删除掉该文件.

 

Mac的窗口管理工具

Mac下面窗口大小的调整、窗口的最大化等操作,跟Windows比起来有点麻烦。尤其是多个显示器的时候,Windows 7以后有快捷键 Shift + Win + ->,可以很方便的将当前窗口移动到下一个显示器。这样做演示的时候尤其方便,不需要用鼠标慢腾腾的将窗口拖过去。Mac本身是没有这种快速切换显示器的功能的。

比较了很久,发现了不少Mac下面的窗口管理软件,归类如下:

收费的软件

cinch,sizeUP, divvy,moom 等
http://www.irradiatedsoftware.com/sizeup/
http://mizage.com/divvy/
http://manytricks.com/moom/

1. SizeUP

sizeUP是定义了很多快捷键,每个快捷键对应了窗口的一种位置和大小,使用的时候,直接按快捷键,就可以将窗口改变到相应的位置和大小;支持将窗口移动到下一个显示器。但是比较贵,要14$

2. divvy

divvy使用的时候,使用快捷键将一个布满方格子的小窗口呼出,然后在小窗口里划出一片区域,程序窗口就会被改变到相应的位置和大小,用起来也很方便。可以参考介绍视频:

3. Moom

Moom很强大,具体参见介绍文章:http://www.macappbox.com/software/Moom/

Moom的几个快捷键:

cheatsheet

视频介绍:

免费的软件

https://github.com/jigish/slate
https://github.com/fikovnik/ShiftIt

4. slate

slate的介绍是:

A window management application (replacement for Divvy/SizeUp/ShiftIt)

雄心不小,但是需要自己配置很多东西。不过好在有一些预置好的配置,不需要从头开始。

这里有一个配置文件的教程,看起来还是很复杂:

http://thume.ca/howto/2012/11/19/using-slate/

Slate is a keyboard-driven window management program for Mac OSX. It is highly configurable and has tons of features. It has permanently changed the way I use my Mac. Not only is it better than other popular programs like Divvy, SizeUp and Moom, it beats their prices at being free. Slate is the VIM/Emacs of window managers: it is less of a window manager than a workflow changing tool you will never give up.

Slate has so much functionality that I think of it more as a shortcut-based productivity tool than a window manager. Here is a sample of what it can do:

  • Move/Resize/Shift windows: this can be done based on different screen size fractions and even mathematical formulae. There are commands for practically every window operation you can think of. It also supports the Divvy style sizing grid.
  • Switch Windows: Slate can act as a complete replacement for command+tab in many ways. I will talk about this more in the “Window Switching” section.
  • Manage multiple monitors: Slate can move windows between monitors as well as detecting your monitor configuration and automatically moving windows around when you plug in an external monitor.
  • Save window layouts: Slate has a feature called “snapshots” that allows you to save your current window layout and restore it at any time. This is handy for having different layouts for different projects/tasks.

5. ShiftIt

ShiftIt和sizeUP有点类似,使用很多快捷键来操作窗口。

Mac的神器Alfred

都说Mac的神器是Alfred, 可以极大的提高工作效率。使用了一下,确实如此。

收费版中才有的功能 workflow,相当于给自己经常做的事情加上快捷键,所以能节省很多时间。

推荐一个Workflow的集锦网站:

http://www.alfredworkflow.com/

建议安装一个workflow search, 然后就可以直接找自己需要的workflow了,比较方便

 

另外一个免费的launcher, QuickSilver据说也很不错,如果不想花钱的话,也是一个不错的选择:

http://qsapp.com/

 

Android里Odex和Deodex的含义

一句话: odex文件是为了加速程序的运行,但是制作custom rom的时候,会麻烦一点;所以就有了deodex的机制出来,把odex文件重新塞回到APK里面去。

优化好了的话,两个的速度应该没啥明显差别。

What do “Odex” and “Deodex” mean? The All Inclusive Explanation

by Jim Farmer on 
tagged 

Show of hands, how many of you reading this have been browsing forums looking for ROMs only to come across a term completely foreign. Hey, it’s OK, I’ve been there too. In particular, the terms Odex and Deodex notoriously cause budding Android modders’ eyes to glaze over. So, what are they talking about?

To better understand deodex, you first need to know about odex.

Stock Android implements an odex file structure, with odex meaning “optimized” dalvik executable file. As your likely aware, Android apps on your device are packaged as .apkfiles. That all being said, what this means is that for pretty much all of your apks there is a corresponding odex file. This goes for the framework files in .jar format as well.

For instance, on this non-rooted Galaxy Nexus you’ll find

system/app/Phone.apk

as well as

system/app/Phone.odex

But what exactly are these odex files?
Well, when the Android OS needs to run your apps or utilize framework components, it has to parse (read/interpret) the compressed data stored in the .apk and/or .jar files. Having an odex file structure expedites this process by utilizing another file, the .odex file, which includes only the most critical data in an uncompressed format so the Android OS can quickly interpret that important information before parsing through the rest of the data held within the compressed .apks and .jars. Therefore, not all of the components of an app or framework are present in one file in an odexed sile system. I’ll elaborate on why I stress that in a moment. The goal of this scheme is to boot up faster,  and generally load applications more quickly and smoother.

Ok so what is deodex?
The odexed file structure works well as an optimization tool, except for in the case of theming. Odexed apps and frameworks present a unique problem to those wanting to theme because the aspect they want to theme is broken up into two files. Typically theming involves swapping out images for home made ones, however this is simply impossible in an Odexed environment. The solution is to DeOdex the file system and reunite all of the uncompressed critical data of an app or framework back into the compressed .apk or .jar file

On this rooted Galaxy Nexus running a custom ROM we see

system/app/Phone.apk

but no longer the corresponding .odex file. The reassembled files become classes.dex

So which should you run?
The fact of the matter is DeOdexing is really only useful for theming. It won’t speed up your phone any.Technically it should slow it down, but in reality the difference is unnoticeable. In my experience, all custom ROMs come pre-DeOdexed, and they also zipalign your apps at boot. Zipaliging is the process of reorganizing the manner in which the .apk is packaged to optimize it for being parsed faster by the Android OS. The funny thing is, it is comparable if not better than the odex file structure, so you get the best of both worlds; a themed ROM and the speed of an optimized file structure. So really the only considerable difference lies in theming capability, and that’s where the choice is yours.

Find and kill a process in one line using bash and regex

http://stackoverflow.com/questions/3510673/find-and-kill-a-process-in-one-line-using-bash-and-regex

grep的时候,里面对p加一个中括号,很简洁有效!

In bash, you should be able to do:

/bin/ps aux | grep "/usr/local/bin/[p]ython2.7 /home/miniui/fw_dinners/main.py" | awk '{print $2}' | xargs kill -9

Details on its workings are as follows:

  • The ps gives you the list of all the processes.
  • The grep filters that based on your search string, [p] is a trick to stop you picking up the actual grepprocess itself.
  • The awk just gives you the second field of each line, which is the PID.
  • The $(x) construct means to execute x then take its output and put it on the command line. The output of that ps pipeline inside that construct above is the list of process IDs so you end up with a command likekill 1234 1122 7654.

Here’s a transcript showing it in action:

pax> sleep 3600 &
[1] 2225
pax> sleep 3600 &
[2] 2226
pax> sleep 3600 &
[3] 2227
pax> sleep 3600 &
[4] 2228
pax> sleep 3600 &
[5] 2229
pax> kill $(ps aux | grep '[s]leep' | awk '{print $2}')
[5]+  Terminated              sleep 3600
[1]   Terminated              sleep 3600
[2]   Terminated              sleep 3600
[3]-  Terminated              sleep 3600
[4]+  Terminated              sleep 3600
pax> _

and you can see it terminating all the sleepers.


Explaining the grep '[p]ython csp_build.py' bit in a bit more detail:

When you do sleep 3600 & followed by ps -ef | grep sleep, you tend to get two processes with sleepin it, the sleep 3600 and the grep sleep (because they both have sleep in them, that’s not rocket science).

However, ps -ef | grep '[s]leep' won’t create a process with sleep in it, it instead creates grep '[s]leep' and here’s the tricky bit: the grep doesn’t find it because it’s looking for the regular expression “any character from the character class [s] (which is s) followed by leep.

In other words, it’s looking for sleep but the grep process is grep '[s]leep' which doesn’t have sleep in it.

When I was shown this (by someone here on SO), I immediately started using it because

  • it’s one less process than adding | grep -v grep; and
  • it’s elegant and sneaky, a rare combination 🙂