Chris Fu
Coding today & Prospecting Tomorrow
Thursday, April 17, 2014
Wednesday, April 9, 2014
Update your OpenSSL on Mac Mavericks
Before beginning check your current version of OpenSSL by opening a terminal and typing:
openssl versionYou should get back the following if you have not updated OpenSSL since installing Mavericks:
OpenSSL 0.9.8y 5 Feb 2013STEP 1: Download the Source Code from the OpenSSL website (http://www.openssl.org/source/). STEP 2: In your Terminal cd to ~/Downloads:
cd ~/DownloadsSTEP 3: Configure the build by typing
./configure darwin64-x86_64-ccSTEP 4: Type
makeSTEP 5 (make sure): Test that everything was created correctly:
make testSTEP 6: Install the newly built OpenSSL:
sudo make install(Type password when prompted) STEP 7: cd to the directory where the old openssl is installed:
cd /usr/binSTEP 8: Rename the old openssl file to another name so that you can go back to it if you need to:
sudo mv openssl opensslOldSTEP 9: Create a link to the new openssl file
sudo ln -s /usr/local/ssl/bin/openssl opensslSTEP 10: Test that everything worked by typing:
openssl versionIf it all worked you should now see OpenSSL 1.0.0c 2 Dec 2010
Monday, April 7, 2014
NodeJs, Mongoose with preexisting data
First we assume there is a collection which is called test in db.test
First we have to create connection
First we have to create connection
var mongo = require('mongodb'); var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'connection error:'));then open the connection and create Schema to match the existing collection's schema, and put the existing collection as the third params in mongoose.model(), like this: mongoose.model('User', userSchema, 'test');
db.once('open', function callback() { var userSchema = new mongoose.Schema({ _id: mongoose.Schema.ObjectId, a: Number }); var User = mongoose.model('User', userSchema, 'test'); User.find(function(err, users){ if(err) return console.err(err); console.log(users); }) })And it is working great.
Sunday, April 6, 2014
Fix for homebrew permission denied issues
1) installing and fixing node.JS
brew install node
~ chrisfu$ brew install node ==> Downloading http://nodejs.org/dist/v0.10.4/node-v0.10.4.tar.gz Already downloaded: /Library/Caches/Homebrew/node-0.10.4.tar.gz ==> ./configure --prefix=/usr/local/Cellar/node/0.10.4 ==> make install Warning: Could not link node. Unlinking... Error: The `brew link` step did not complete successfully The formula built, but is not symlinked into /usr/local You can try again using `brew link node' ==> Summary /usr/local/Cellar/node/0.10.4: 951 files, 14M, built in 73 seconds2) brew link node
~ chrisfu$ brew link node Linking /usr/local/Cellar/node/0.10.4... Warning: Could not link node. Unlinking... Error: Could not symlink file: /usr/local/Cellar/node/0.10.4/lib/dtrace/node.d Target /usr/local/lib/dtrace/node.d already exists. You may need to delete it. To force the link and delete this file, do: brew link --overwrite formula_name To list all files that would be deleted: brew link --overwrite --dry-run formula_name3) brew link --overwrite node
Linking /usr/local/Cellar/node/0.10.4... Warning: Could not link node. Unlinking... Error: Permission denied - /usr/local/lib/dtrace/node.d4) sudo chown -R whoami /usr/local as sudoing homebrew is a bad idea (and doesn't work either) we have to reset the permissions within /usr/local
~ chrisfu$ sudo chown -R `whoami` /usr/local Password: ~ chrisfu$ brew link --overwrite node Linking /usr/local/Cellar/node/0.10.4... 5 symlinks created~ chrisfu$ sudo chown -R `whoami` /usr/local is the key step 5) STEPS brew update brew upgrade brew cleanup brew install node brew link --overwrite node sudo chown -R whoami /usr/local
OC Memory Management
Reference counting
the counting number means the number of users who is using it.
1. each object has its own retain counting.
2. reference counting is 1 when object is created.
3. sending retain message, object's reference counting add 1.
4. sending release message, object's reference counting minus 1.
5. dealloc is revoked when object's reference counting is 0.
example:
the counting number means the number of users who is using it.
1. each object has its own retain counting.
2. reference counting is 1 when object is created.
3. sending retain message, object's reference counting add 1.
4. sending release message, object's reference counting minus 1.
5. dealloc is revoked when object's reference counting is 0.
example:
Person *person = [[Person alloc] init]; NSLog(@"%ld", [person retainCount])& // 1 [person retain] ; NSLog(@"%ld", [person retainCount])& // 2 [person retain] ; NSLog(@"%ld", [person retainCount])& // 3 [person release] ; NSLog(@"%ld", [person retainCount])& // 2 [person release] ; NSLog(@"%ld", [person retainCount])& // 1 [person release] ; NSLog(@"%ld", [person retainCount])& // 0
Subscribe to:
Posts (Atom)