From Crockford's "Javascript: The Good Parts".
"When a function object is created, the Function constructor that produces the function object runs some code like this:
this.prototype={constructor:this};
The new function object is given a prototype property whose value is an object containing a constructor property whose value is the new function object."
Say what? This is an example of completely ridiculous technical writing. What makes it even more egregiously bad is throughout his book Javascript: The Good Parts, Crockford uses railroad diagrams to illustrate Javascript's grammar. Yet the above quoted sentence, which might best be expressed via a diagram, is rendered in nearly impenetrable prose.
Joanne Programmer is writing her first useful Javascript program. When the program is run it will print the words "Jello, Whirled." She decides she will try to use a function to print the message and writes: function jelloWhirled(){ console.log("Jello Whirled!"); } She runs the program, and it works!! She is very excited. When the thrill wears off, a few seconds later, she wonders, how did the Wizard of JS do that?
The Wizard, it turns out, has some code of his own. It is not visible to Joanne, as it is embedded in the interpreter, but when Joanne writes function () {} the Wizard's code creates a function object for Joanne.
This function object the Wizard creates for Joanne has some properties. One is a prototype property. The prototype property will allow Joanne to add properties and methods to her function. If that's confusing, check out this excellent example
What is the value of the prototype property in Joanne's function? After all, properties usually have a value. According to Crockford, the value is basically a piece of code that can be used by Joanne's function to invoke itself (I think). Does the reader need to know more? Possibly, it's hard to tell from what Crockford writes.
Sunday, July 10, 2011
Wednesday, April 6, 2011
Restarting Sphinx with a new conf file
Resetting the Sphinx search daemon to change the index it runs against is a multi step process.
1. Of course you need to either edit the existing .conf file or create a fresh one that contains the new data source and index information.
2. The search daemon process should be killed.
3. The new index should be created:
./indexer --config /path/to/conf/sphinx.conf --all
4. Restart the search daemon
./searchd -c /directory/to/config/file/sphinx.conf
1. Of course you need to either edit the existing .conf file or create a fresh one that contains the new data source and index information.
2. The search daemon process should be killed.
3. The new index should be created:
./indexer --config /path/to/conf/sphinx.conf --all
4. Restart the search daemon
./searchd -c /directory/to/config/file/sphinx.conf
Sphinx: Unknown local index error
One possible source of the unknown local index error generated by Sphinx is a mismatch in the index definition section. It seems as if the name of the index must be the same as the destination name of the path to the index.
So if the index is defined as
#############################################################################
## index definition
#############################################################################
# local index example
#
# this is an index which is stored locally in the filesystem
#
# all indexing-time options (such as morphology and charsets)
# are configured per local index
index musicReviews {
Then the path should be:
path = /path/to/index/data/musicReviews
So if the index is defined as
#############################################################################
## index definition
#############################################################################
# local index example
#
# this is an index which is stored locally in the filesystem
#
# all indexing-time options (such as morphology and charsets)
# are configured per local index
index musicReviews {
Then the path should be:
path = /path/to/index/data/musicReviews
Monday, February 28, 2011
Sphinx: A dumb newbie error
When first creating the index for my data on Sphinx, I made a mistake. I ran the command:
./indexer --config /path/to/conf/sphinx.conf --rotate --all
The result?
Files (data indexes) were created in the var/data directory. When I tried to search the indexes from the command line, no results were returned.
The solution was to run the command as follows:
./indexer --config /path/to/conf/sphinx.conf --all
I believe the rotate flag only applies when an index already exists and it is being updated.
./indexer --config /path/to/conf/sphinx.conf --rotate --all
The result?
Files (data indexes) were created in the var/data directory. When I tried to search the indexes from the command line, no results were returned.
The solution was to run the command as follows:
./indexer --config /path/to/conf/sphinx.conf --all
I believe the rotate flag only applies when an index already exists and it is being updated.
The Sphinx configuration file
Sphinx uses data in a MySQL table to index and search. Before it can do this though it needs to consult its configuration file. The configuration file tells Sphinx where the data is stored, how to connect to the database to get it, what query to use to retrieve the data, where the index should be stored, whether stemming is allowed, and so on. Without a configuration file, Sphinx lacks the instructions to do its job. For anyone setting up a Sphinx search, then, knowing what to put in the configuration file is important.
Monday, February 7, 2011
Excellent instructions for removing an image from its background in Photoshop
Short and sweet:
http://www.pegaweb.com/tutorials/separation/separate-image-from-background.htm
http://www.pegaweb.com/tutorials/separation/separate-image-from-background.htm
Wednesday, January 26, 2011
Facebook Fanbox streams may stop working if you merge your FB page with a place or places
A possible fix if your Facebook Fanbox stream has stopped working and you have merged your Facebook Page with a Place or Places. This method worked for me, and was also used successfully by a page admin who reported it here.
http://www.facebook.com/unmerge
Simply unmerge your Facebook page from the Facebook places it was merged to. You should be able to do this using the Unmerge with Places link on your Facebook Page.
http://www.facebook.com/unmerge
Simply unmerge your Facebook page from the Facebook places it was merged to. You should be able to do this using the Unmerge with Places link on your Facebook Page.
Subscribe to:
Comments (Atom)