Friday, January 31, 2014

Use 'sips' to manipulate images in CLI.

sips (scriptable image processing system) is a prebundled command tool which can used to manipulate images. There are two advantages:

- it is prebundled, you don't need to download and install it.
- it uses CoreImage so it is very fast.

Here are some examples:

1. Get Image size
$sips --getProperty pixelWidth  xxx.jpg
  pixelWidth: 3264

$sips --getProperty pixelHeight xxx.jpg
  pixelHeight: 2448

2. Resize an image
$sips -z 100 100 xxx.jpg
  resize xxx.jpg to 100x100

$sips --resampleWidth 100 xxx.jpg
  resize xxx.jpg 's width to 100, and resize the height to keep its ratio.

$sips --resampleHeight 100 xxx.jpg
  resize xxx.jpg's height to 100, and resize its width to keep the original ratio.

You can check its man page here: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/sips.1.html

src

Monday, January 20, 2014

Something about proxy.

First, you'll need to purchase a VPS (or something else) as your proxy server.

1. Using SSH tunnel.

1.1 Prepare your ssh keys (on your computer).
1.2 Log in your VPS (with user name, for example, tom), in folder ~/.ssh/, edit the file: authorized_keys, add your public key there.
1.3 On your computer, use:

ssh -N -D 1080 tom@(IPAddress Of your VPS)

Now you get a sock5 proxy on port 1080 and you can use it on your browser.


2. Use shadowsocks

1. How to install shadowsocks on your VPS is simple: https://github.com/clowwindy/shadowsocks
2. Configure shadowsocks with Supervisor, so it will restart if crash, very useful: https://github.com/clowwindy/shadowsocks/wiki/Configure-Shadowsocks-with-Supervisor
3. However, on Mac OS, python 'pip' may have problems. You may need to use:

sudo easy_install --upgrade pip

to upgrade pip to the latest version.

4. Now you can use (on your computer):

sslocal -c [path to your config.json]

to open the SOCK5 proxy.

3. Convert SOCK5 proxy to HTTP proxy.

1. Use brew to install privoxy:

brew install privoxy

2. The config file is on /usr/local/etc/privoxy:

vim /usr/local/etc/privoxy/config

uncomment this line:

forward-socks5     127.0.0.1:8008

Here, change 8008 to the actual port your SOCKS5  uses.

Saturday, January 18, 2014

(Node.js) Use --harmony with supervisor

Currently I'm working on a web project and I'm using Node.js for it.

When testing it on my local computer,  I use supervisor (npm install -g supervisor) instead of using node directly. That is, to start my script, I use:
supervisor app.js
instead of:
node app.js
However, since I'm using the harmony mode (for keyword such as 'let'), supervisor seems can't start node with the '--harmony' flags, I must modify the script myself.

  • Using 'find . | grep supervisor' to find the location of the script: /usr/local/share/npm/lib/node_modules/supervisor
  • Edit ./lib/supervisor.js.
  • In 'function run (args)' :
Add:
function run (args) {
  var arg, next, watch, ignore, program, extensions, executor, poll_interval, debugFlag, debugBrkFlag, debugBrkFlagArg, harmony;
  while (arg = args.shift()) {
    if (arg === "--help" || arg === "-h" || arg === "-?") {
      return help();
    } else if (arg === "--quiet" || arg === "-q") {
      debug = false;
      util.debug = function(){};
      util.puts = function(){};
    } else if (arg == '--harmony') {
      harmony = true;

    } else if (arg === "--verbose" || arg === "-V") {
      verbose = true;
And:
  if (debugBrkFlag) {
    program.unshift(debugBrkFlagArg);
  }
  if (harmony) {
    program.unshift('--harmony');
  }
Save, and that's all.


Now I can use:







supervisor --harmony app.js

to start my project :)