Monthly Archives: February 2016

new vs non-new object creation–net-21117


The Global Object

When a function is called without an owner object, the value of this becomes the global object.

In a web browser the global object is the browser window.
This example returns the window object as the value of this:

standalone Function (notice no new!)

The reason why logs Cody Lindley is because the ‘this’ inside the function references the window global object. Hence when we attach the attribute name to this, it attaches name to the window object. the ‘this’ has nothing to do with the object Person.

new Object

Now, when we use new Object, we create an object on the heap, and this in our function refers to that object. IT IS NOT connected to the (global or window) object anymore

Hence, when we log, it works because cody is that object in the heap. The this in the function, refers to cody.

We assign name attribute to the object cody.

Also, take note that the this properties are public because there is no closure. If we create a closure (by creating inner functions), then the properties attached to this will then be private.

Another example:

const object, changing attributes

Const will only prevent re-assigning

It will not prevent modification of the attributes of the object.

For example, this will give you an error because you are trying to reassign the variable car to another object.

But if you were to change the attribute of the object, it is valid:

You’d see honda, white

Another example:

However, bear in mind that const in ES6 notation does not make the variable immutable.

is a completely valid program and a will become [1, 2, 3]. const will only prevent you from reassigning a, so that you can’t do a = [] or a = {} or whatever once const a = [1, 2]; already defined (in that particular scope).

Read Only Variable

ref –

if you’re looking for a read-only variable, you simulate that with something like

and then use it like

Installing JSLint in sublime

ref –

First, make sure you install the jslint npm package

npm install -g jslint

Install Package control

In your sublime, View > Console.
Then copy and paste this into the console and press enter:

Then after that, In Sublime,

Tools > Command Palette

type “Install” and type enter.
You will t hen see a menu popup with all the packages.

Look for SublimeLinter-jslint

Logging Cron Job

ref –

Getting started with Cron
  • In Terminal: crontab -e.
  • Press i to go into vim’s insert mode.
  • Type your cron job, for example:

    30 * * * * /Users/rickytsao/Desktop/run_email_to_admin >> /Users/rickytsao/Desktop/chron-log.txt
  • Press Esc to exit vim’s insert mode.
  • Type ZZ (must be capital letters).
  • You should see the following message: crontab: installing new crontab. You can verify the crontab file by using crontab -l.
Logging Cron jobs

30 * * * * /Users/rickytsao/Desktop/run_email_to_admin >> /Users/rickytsao/Desktop/chron-log.txt


ref –

curl http://localhost:6680/results -GET

to send a HTTP request

Download a Single File

The following command will get the content of the URL and display it in the STDOUT (i.e on your terminal).

$ curl

ryh:Desktop rickytsao$ curl

301 Moved Permanently

301 Moved Permanently


ryh:Desktop rickytsao$

Download file and store in file

To store the output in a file, you an redirect it as shown below. This will also display some additional download statistics.

$ curl > centos-org.html

self does not hold strong ref to dispatch_async

ref –

Examples of non-cycles

      Using dispatch_async as the example is misleading as self does not hold a strong reference to it so, there is no threat of a retain cycle.

    • The block retains self, but self doesn’t retain the block. If one or the other is released, no cycle is created and everything gets deallocated as it should.

    How you get into trouble

    Where you get into trouble is something like:

    Now, your object (self) has an explicit strong reference to the block. And the block has an implicit strong reference to self. That’s a cycle, and now neither object will be deallocated properly.

Badminton Events App notes

Sort database by date

Sort the database by date


Script to send admin result email

curl http://localhost:6680/results -GET


to run: ./send_admin_email_script

attaching files to gunemail

DB manipuluation

show dbs
use BadmintonEventsDatabase


To Drop an Event

db.badmintonEvents.remove({“_id” : ObjectId(“5704d3df5b4e17c2a90b558c”)});


When moving over to production

change ip and port in config
change ip and port in client.js

to get results

to get registeration page

Mongod Address already in use for socket


Last login: Fri Feb 12 10:54:07 on ttys002
ryh:~ rickytsao$ mongod
2016-02-13T11:07:24.914+0800 E NETWORK [initandlisten] listen(): bind() failed errno:48 Address already in use for socket:
2016-02-13T11:07:24.914+0800 E NETWORK [initandlisten] addr already in use
2016-02-13T11:07:24.941+0800 W – [initandlisten] Detected unclean shutdown – /data/db/mongod.lock is not empty.
2016-02-13T11:07:25.001+0800 I STORAGE [initandlisten] exception in initAndListen: 98 Unable to lock file: /data/db/mongod.lock errno:35 Resource temporarily unavailable. Is a mongod instance already running?, terminating
2016-02-13T11:07:25.004+0800 I CONTROL [initandlisten] dbexit: rc: 100


Check to see what mongo database instance is running on port 27017

ryh:~ rickytsao$ sudo lsof -i :27017

mongod 442 rickytsao 5u IPv4 0xd82daecd96900a0b 0t0 TCP *:27017 (LISTEN)

ryh:~ rickytsao$ KILL -9 442

Then, start up your mongo database

ryh:~ rickytsao$ mongod

2016-02-13T11:10:14.375+0800 W – [initandlisten] Detected unclean shutdown – /data/db/mongod.lock is not empty.
2016-02-13T11:10:14.384+0800 I JOURNAL [initandlisten] journal dir=/data/db/journal
2016-02-13T11:10:14.384+0800 I JOURNAL [initandlisten] recover begin
2016-02-13T11:10:14.408+0800 I JOURNAL [initandlisten] recover lsn: 16539606
2016-02-13T11:10:14.408+0800 I JOURNAL [initandlisten] recover /data/db/journal/j._2
2016-02-13T11:10:14.408+0800 I JOURNAL [initandlisten] recover skipping application of section seq:14612540 < lsn:16539606 2016-02-13T11:10:14.408+0800 I JOURNAL [initandlisten] recover skipping application of section seq:14662560 < lsn:16539606 2016-02-13T11:10:14.408+0800 I JOURNAL [initandlisten] recover skipping application of section seq:14761940 < lsn:16539606 2016-02-13T11:10:14.411+0800 I JOURNAL [initandlisten] recover cleaning up 2016-02-13T11:10:14.411+0800 I JOURNAL [initandlisten] removeJournalFiles 2016-02-13T11:10:14.411+0800 I JOURNAL [initandlisten] recover done 2016-02-13T11:10:14.480+0800 I JOURNAL [durability] Durability thread started 2016-02-13T11:10:14.480+0800 I JOURNAL [journal writer] Journal writer thread started 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] MongoDB starting : pid=85510 port=27017 dbpath=/data/db 64-bit 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] db version v3.0.7 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] git version: 6ce7cbe8c6b899552dadd907604559806aa2e9bd 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] build info: Darwin 12.3.0 Darwin Kernel Version 12.3.0: Sun Jan 6 22:37:10 PST 2013; root:xnu-2050.22.13~1/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_49 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] allocator: system 2016-02-13T11:10:14.480+0800 I CONTROL [initandlisten] options: {} 2016-02-13T11:10:14.503+0800 I NETWORK [initandlisten] waiting for connections on port 27017