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.
Monday, January 24, 2011
Don't Try To Call Facebook
I tried to telephone Facebook to maybe speak with a human about the Fan Box issue. Ha. No matter which option I chose a recorded voice referred me to an email address. This is a company that is being valued in the private market at many billions of dollars?? What a joke.
Friday, January 21, 2011
Integrating Facebook social apps into your website puts you at the mercy of Facebook
Some time ago we did a web site redesign. As part of the redesign we decided to incorporate a Facebook fanbox on the home page. We enabled streaming in the Facebook Fanbox so that anything posted on the organization's Facebook page wall would also appear on the homepage. While I was not deeply involved in that part of the decision making, I believe the idea was to keep things fresh and interesting on the home page and increase traffic between the organization's Facebook presence and web site. Mysteriously today the Facebook stream on the home page isn't loading. Empty box. So far no luck in tracking down the problem. Facebook has a developer forum but no formal help system to speak of, and the admittedly small sample of Facebook documentation I've used has been so so.
My experience with Facebook so far has been mixed, and this is one instance of why I don't have particularly warm feelings towards the company. Let me jump back a couple of months. A sister organization of the one I work for, which also has a presence on the same web site, asked me to do a Facebook Fan Box for them as well. When I went to generate the Fan Box code, surprise surprise, Facebook was no longer supporting Fan Boxes. They'd changed them to "Like" Boxes, and what's more they'd removed access to the documentation for Fan Boxes. Indeed it seemed as if the company tried to expunge all references to Fan Boxes. So much for supporting features that they themselves created.
This is apparently what the company means in its user agreement when it says things can change at any time and there is squat the user can do about it. Fair enough. Thing is the only reason Facebook exists is because people and developers use it. When Facebook yanks support for its own features, buries documentation, can't be bothered to help developers track problems, and the like it says to me that I need to be careful in buying in to their system.
My experience with Facebook so far has been mixed, and this is one instance of why I don't have particularly warm feelings towards the company. Let me jump back a couple of months. A sister organization of the one I work for, which also has a presence on the same web site, asked me to do a Facebook Fan Box for them as well. When I went to generate the Fan Box code, surprise surprise, Facebook was no longer supporting Fan Boxes. They'd changed them to "Like" Boxes, and what's more they'd removed access to the documentation for Fan Boxes. Indeed it seemed as if the company tried to expunge all references to Fan Boxes. So much for supporting features that they themselves created.
This is apparently what the company means in its user agreement when it says things can change at any time and there is squat the user can do about it. Fair enough. Thing is the only reason Facebook exists is because people and developers use it. When Facebook yanks support for its own features, buries documentation, can't be bothered to help developers track problems, and the like it says to me that I need to be careful in buying in to their system.
Thursday, January 6, 2011
Getting searchd to run in Sphinx
Yesterday I tried to run searchd in Sphinx. To run searchd you use the ./searchd command and give it a path to your sphinx.conf file.
On the command line I wrote:
./searchd --config=/directory/to/config/file/sphinx.conf
The result was a message that looked very much like this.
using config file '/sphinx/conf/sphinx.conf'...
listening on all interfaces, port=9312
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
A fatal error ensued. This morning after a second consult of the Sphinx forum, the problem was clarified. The Sphinx searchd program cannot be activated using the --config=// syntax. The correct syntax is ./searchd -c /path/to/conf/file/sphinx.conf
Once I wrote:
./searchd -c /directory/to/config/file/sphinx.conf
It worked.
In Sphinx the correct syntax for starting the search daemon differs from the correct syntax for running the indexer.
In the case of the indexer you use the --config=// syntax.
In the case of searchd you use -c // syntax.
Not sure why Sphinx was designed this way.
On the command line I wrote:
./searchd --config=/directory/to/config/file/sphinx.conf
The result was a message that looked very much like this.
using config file '/sphinx/conf/sphinx.conf'...
listening on all interfaces, port=9312
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
bind() failed on 0.0.0.0, retrying...
A fatal error ensued. This morning after a second consult of the Sphinx forum, the problem was clarified. The Sphinx searchd program cannot be activated using the --config=// syntax. The correct syntax is ./searchd -c /path/to/conf/file/sphinx.conf
Once I wrote:
./searchd -c /directory/to/config/file/sphinx.conf
It worked.
In Sphinx the correct syntax for starting the search daemon differs from the correct syntax for running the indexer.
In the case of the indexer you use the --config=// syntax.
In the case of searchd you use -c // syntax.
Not sure why Sphinx was designed this way.
Labels:
open source,
search engines,
searchd,
sphinx,
user assumptions
Subscribe to:
Comments (Atom)