Tuesday, January 28, 2014

How to delete a remote git repository from github web page

In order to delete a git repository from github web page, first log on to github site and select the git repository, once inside the git repository you want to delete, select the settings button on top left of the page, then scroll to the bottom of the page called "Danger Zone", it has button to allow you to make it public or private, transfer the repository to others, or delete the repository.

By the way, if it fails to clone a git remote repository to local or push it to remote, you will need to set the SSH keys from settings page in github web site. You need first generate the private and public key and then load the public key from ~/ssh/id_rsa.pub to github web site's SSH key settings.

Wednesday, January 22, 2014

Understanding ios ARC and CFRefType

1. Why ARC does not handle CFRefType?
CFRefType basically is a "void *" type, it point to a core foundation object that handles CFRelease and CFRetain, but not retain and release as objective-c object does. So CFRefType is not managed by ARC. That is why when casting between Objective-c type and CFRefType, you need to tell ARC who owns the object.

__bridge: no ownership transfer
NSMutableString * string1 = [[NSMutableString allocinitWithFormat:@"First : %@"@"adb"];
 CFStringRef cfString = nil;
 cfString = (__bridge CFStringRef )string1;

 string1 = nil; //at this moment, cfString is also set to nil


__bridge_retained or CFBridgingRetain: transfer ownershjp of  Objective-C object to Core Foundation pointer, and need to call CFRelease to collect the object
 NSMutableString * string1 = nil;
 CFStringRef cfString = nil;
 string1 = [[NSMutableString allocinitWithFormat:@"First Name: %@"@"adb"];
 cfString = (__bridge_retained CFStringRef )string1;

 string1 = nil//at this moment, cfString is still hold the original string, as it has been retained

__bridge_transfer or CFBridgingRelease: transfer ownership of core foundation object to ARC, ARC will release the object when it is no longer referenced
NSMutableString * string1 = nil;
 CFStringRef cfString = CFSTR("Hello, world.");;
 string1 = (__bridge_transfer NSMutableString*)cfString;
 CFRelease(cfString); //at this moment string1 still hold the valid string data

2. Ownership transfer for Objective C property and variable for ARC
When assigning values to objective c property or variable, it implies the ownership transferring, the receiver either become the owner of the assigned object or not depending on the variable qualifier:
__strong: the receiver becomes the new owner. (default)
__weak: the receiver is not the owner, and the object may become nil anytime
__unsafe_unretained: the receive is not the owner, and not set to nil if the object is deleted.
__autoreleasing: the receiver is retained and autoreleased.  is usually used for declaring by reference  parameter, it should always used within an autorelease. Most of time, the arced object is released when the variable is set to nil or the variable is out of definition scope. __autoleasing will allow to collect an object when the thread ends or the autorelease pool close, so it uses thread instead of variable scope to control the object's life time.

3. CFRefType ownership transfer
If a method contains copy or create and return a CFRefType object, then it transfers the ownership to caller, and caller needs to CFRelease it.

4. Objective C ownership transfer
If the object transfer the ownership to caller and needs ARC to release the object, then the method needs to start with alloc, copy, mutableCopy or new. Otherwise, ARC will not collect it when it is no longer referred.

5. id and void*
id represents an Objective C object, which responds to retain and release method, while void * is just an memory blob.  A lot of objective C API accepts id as parameter, but not void*, so void* cannot be cast as id.



Wednesday, January 8, 2014

npm package folder on mac

The npm package may be installed on the following folders on mac
1.  ./node_modules
If the package is installed locally, the folder is in the current folder's ./node_modules of the current package. You should install the package locally, if the package will be loaded into your js app with require() method.

2.    /usr/local/lib/node_modules folder
If the package is installed globally, i.e, installed with -g flag, then it is installed in
 /usr/local/lib/node_modules folder

3. ~/.npm 
There will be another copy in your home directory's ~/.npm folder, it is a cache that npm uses to avoid re-downloading the same package multiple times. There's no harm in removing it. You can empty it with the command:
npm cache clean


To uninstall a local npm package, use
npm rm

to uninstall a global npm package, use
npm rm -g

To check an installed npm package version, use
npm view packagename

Thursday, January 2, 2014

Terminal command shortcut for Windows, Mac and Visual Studio Code

For Windows

start .
open Windows File Explorer at the current folder of command line console. 

code .
open Visual Studio Code at the current folder of command line console.

 
For MAC

Command+T
create a new tab

Command+D
split terminal window

Command+shife+D
unsplit terminal window

Command+option +D
hide or show dock bar

open .bash_history
open terminal history in editor

history
display all terminal history

alias name='command text'
Create a command alias for current terminal session. The alias must be the first word when run from the terminal. Set the alias to profile if the alias is used for every terminal window.

Note, when running .sh file from mac terminal, first you need to set it executable file attribute with
chmod +x myshell.sh
In addition, bash command does not search the current directory for the file to run, so you need to specify the full path to run it as below (assume the shell file is in the current directory)
./myshell.sh


For Visual Studio Code OnWindows

Shortcut for visual studio code on Windows
to open a file in new VS code window, first select the file, then Ctrl + K, and O

Comment a block of code in visual studio code on Windows
select the block of code, then Ctrl + K + C to comment,
Ctrl + K + U to uncomment.


For Chrome Debugger on Windows

Ctrl + O to open the javascript source file based on file name.