Sunday, November 10, 2013

How to show long variable's full text value when debugging node js app with node inspector

When debugging with node inspector, the long variable's value will be truncated and shows as ....

In order to show the full text of the variable value, one workaround is using console.log(variablename) from Node inspector's console window. However, the output of the variable content will not show in the node inspector's console window, it is shown in the terminal app that starts the node application. It is much better if it can show in both places. 

Friday, November 8, 2013

Run xcode 4.6.3 and xcode 5 side by side

Following the following steps to run xcode 4.6 and xcode 5 side by side
1. copy existing xcode 4.6 to a different folder, for example /Applications/Xcode46/Xcode.app
2. install xcode 5 at the default location: /Applications/Xcode.app
3 when switching between xcode 4.6 and xcode 5, also need to switch command line tool to the corresponding version:

To xcode 5:
sudo xcode-select --switch /Applications/Xcode.app
 
To xcode 4.6
sudo xcode-select --switch /Applications/Xcode46/Xcode.app

To verify the command line 
xcode-select --print-path











 


Wednesday, November 6, 2013

Set proxy for python and easy_install downloading on mac

If you get an error when using easy_install or "python ez_setup.py" behind a proxy as
"nodename nor servname provided, or not known -- Some packages may not be found!", then you will need to add the proxy settings as below:

export http_proxy=http://proxy:8080

export https_proxy=http://proxy:8080

If you get an error of "Permission denied", then you will need to use sudo command, but for sudo with easy_install, it also requires to use -E option to preserve the proxy settings

sudo -E easy_install sqlalchemy==0.7.10

Set breakpoint at the first line of code when starting node js application using node-inspector

In order to debug short living node js application, the debugger needs to be attached to the js app and  break on the first line of code, so that the app can be debugged before exiting.

The following command can be used for this purpose

1. From mac's terminal app, starting debugger and the node app
node --debug-brk mynodeapp.js arguments...

for example:
To debug an global npm package, run the application from package's bin folder:
node --debug-brk /usr/local/bin/cordova compile ios

To debug an local npm package, run the js source file
node --debug-brk /usr/local/lib/node_modules/projecteditor/srcib/projecteditor.js -addentitlement /Users/i826633/Documents/SMP3/TestApps/Automation/platforms/ios /Users/i826633/Documents/SMP3/Resource/Common/platforms/ios/MCIM.entitlements

2. start another terminal app and start node-inspector
node-inspector

3. start chrome browser and visit the url of 
http://127.0.0.1:8080/debug?ws=127.0.0.1:8080&port=5858
it should break on the first line of the code

Node, in order to edit and save the javascript change from node-inspector debugging, edit file /usr/local/lib/node_modules/node-inspector/config.json to set saveLiveEdit to true as below

saveLiveEdit": true,

For details please refer to
https://github.com/node-inspector/node-inspector


Set and reset proxy for git and npm connection

Depending on whether the connection is behind a proxy or not, the proxy settings will need to set/reset correspondingly when using npm and git.

The command to set  the proxy are

# Set proxy for npm:
npm config set proxy http://proxy:8080
npm config set https-proxy http://proxy:8080

# Set proxy for git:
git config --global http.proxy http://proxy:8080
git config --global https.proxy http://proxy:8080


The command to reset proxy for npm 
npm config rm proxy
npm config rm https-proxy


# reset proxy for git
git config --global --unset http.proxy
git config --global --unset https.proxy

# get proxy setting for git
git config --global --list
npm config get list
npm config get proxy
npm config get https-proxy


The command to set proxy for windows 8.1 command line terminal
Set proxy for all apps from terminal
netsh winhttp set proxy proxy:8083

Reset proxy for all apps from terminal
netsh winhttp reset proxy

Show proxy settings
netsh winhttp show proxy

Set proxy for windows 
in pc settings, go to network->prxoy settings to change the proxy settings.

Monday, November 4, 2013

Node and npm

Node is a new way of programming using javascript without running in a browser, it uses javascript libraries from google V8 javascript engine same as other language like C# using .net framework to support different functions. The node app can run as client or server app.

The important thing about Node is the application can only have a single thread. At first thought, that seems an extreme limitation as a developing language. But actually it is not once you change the view about multithread programming. The key is the event driven programming model using the callback methods. So when a method is called, it will not immediately return its result to caller, instead the method allows developers to provides one or few callback methods as the parameter to handle the result later. A major benefit is developers are forced to use asynchronous method invocation, the method call will return immediately without being blocked while waiting for the result. And once the result is finally available, it will be handled by the callbacks method automatically. This callback model simplifies the asynchronous programming model and helps developers to handle asynchronous naturally. The only drawback is it does not provide the callstack as synchronous request, which should be overcome by adding call history in the callback method object.

The node application can run on console with command line parameter of js file name
node appName.js

npm is one of node application, it manages the node apps as packages, and provides a generic way to manage the third party node libraries.

If a npm package is only download to use by node's require method, then download it locally.
If a npm package is used from command line console, then download it globally

A npm package includes the main js file invoked by node, it also include package.json for its configuration and dependent information.

The following link is a good tutorial to create a npm package
http://www.anupshinde.com/posts/how-to-create-nodejs-npm-package/

Friday, November 1, 2013

Xcode project file structure

The root item is a dictionary whose key is "objects", all other items are children of this root item. Each subitem has a ias property to indicate the item's type. The ias may include the following item types:

Items showing in project navigation page:

PBXFileReference
Represent each file item in the project, those items show in the project navigation view.

PBXBuildFile
Represent each file in the settings's build phase page, it references the file in PBXFileReference group

PBXGroup
Represent each folder in project navigation view, it includes items in PBXFileReference group


Items show in project build settings page:
PBXProject
Represent the build project, it includes the subitem of PBXNativeTarget, and XCConfigurationList

PBXNativeTarget
Represent the build target, it includes the subitem of XCConfigurationList, and different build phase

XCConfigurationList
Represent the list of build settings for project or target, it contains subitems of XCBuildConfiguration

XCBuildConfiguration
Represent build settings

Items show in build phase page, they are linked to a target:
PBXTargetDependency
Represents each item in build phase dependency section

PBXFrameworksBuildPhase
Represents each library showing in the build phase "Link Binary with Library" page

PBXResourcesBuildPhase
Represents each item showing in "Copy bundle Resource" page

PBXSourcesBuildPhase
Represent each item showing in "Compile sources" page

The whole xcode project file is a plist file connecting all items under root object.