Thursday, June 16, 2011

My answer to "Application details don't register"

This is my answer to a Question on Support site for LampCMS project


It will be easy to add other types of databases. MySQL is used only for the search feature. Ideally no database will be needed at all when we start using real search engine like Lucene or Sphinx.

If you want to write sqlite plugin then you need to implement 2 interfaces: Search and Indexer
Then edit SearchFactory class to return your own objects that implement these 2.

The class for creating tables if tables don't exists is just a helper class specifically for mysql. You are not required to implement it but then you will be required to pre-create all your SQLite tables in advance. I prefer when there is that helper class that detects that table does not exist and creates it.

Later I should probably refactory this a little so that every search provider is in its own namespace, for example
\Lampcms\Modules\Search\Mysql\Indexer.php and \Lampcms\Modules\Search\Mysql\Search.php

Then it will be easy to define your prefered search provider in !config.ini by just defining the name of search provider.

Monday, June 13, 2011

My answer to "Big improvement to comments system - now comments can have replies!"

This is my answer to a Question on Support site for LampCMS project


Everything looked good, I also updated the Email Notifier script to notify original commentor when someone replies to their comment.
I pushed all the updates to github today, you can try it now.

Sunday, June 12, 2011

Big improvement to comments system - now comments can have replies!

My Question on Support site for LampCMS project

This is a pretty big update to the comments system.
Here is the deal: Often a comment is a reply to another comment. It's not easy to keep track of these replies.
On most other site like StackOverflow for example, the best one can do is to include the @user in the beginning
of a comment to indicate that this is a reply.

But this only tells that it's a reply to a comment by @userA. It is not very helpful when userA made more than one comment. How do you know which one of these comments this reply is referring to?

I thought I can do better. Here is goes: Now every comment has a "reply" link. Want to reply to a comment - just use that magic link. No need to manually type @userA - the system will figure out that this is a reply to @userA and more importantly which one of @userA comments

Then when looking at comments all the replies will automatically include @user - and these are underscored with a dashed line.

Now the best part - when you mouse over these @user labels - the comment for which this is a reply will become highlighted - you in case instantly see the message for this this is a reply. You can even click on that @user label in which case BOTH - the original and this reply are highlighted. Clicking it again will toggle the highlighing on/off

And now I'm going to post a simple comment and a reply, and you are welcome to also post replies to comments and just test it out. If this works well, I'll push it to github soon.

I don't think you'll find this feature anywhere else because I thought of it myself. I think it's pretty useful addition.

Click here to post your reply


Friday, June 10, 2011

My answer to "Dmitri: is this agile development? do you have your idea / plan documents?"

This is my answer to a Question on Support site for LampCMS project


One more programming tip I can share, but this is a top secret trick, dont tell anyone.

Sometimes I just create an new blank php file, give it the name of class it's going to be, then just write some comments in the comments block describing what it's going to do, including as much details as possible and then just save it and it will just sit there for awhile.
I may even include a few methods with no body, just comment blocks.

For example

protected function main(){
        $this->getInput()
        ->parseData()
        ->validate()
        ->saveData()
        ->updateUser()
        ->sendEmails();
}


This could be all I need to later take it from there. This is actually the important part, the actual methods can be written later but the main() methods I have to write as I think about the steps involved in this one feature. This is called a top-down design. This may be a true secret to being a good programmer. This is certainly what separates a good programmer from a beginner. Beginners don't do a top-down design, they tend to do the opposite - sometimes refereed to as bottom-up design, which is the wrong way of doing things

A little blank php file, not doing anything but waiting for me to implement it when I get to it.

My answer to "Dmitri: is this agile development? do you have your idea / plan documents?"

This is my answer to a Question on Support site for LampCMS project


Once I wrote the base classes and basically wrote the framework, adding new features is not that hard, actually quite fast. It probably took me about 6 months or so before I even released the first commit to github, but it goes much faster now that all the base classes are solid and "bulllet-proof", I mean bug-free and have test cases.

Also abandoning MySQL and going with Mongo resulted in much faster development, and also alot of unpleasant parts of defining new tables and modifying existing tables and thinking of complex table joins are gone.

Yes, I did have all written down in a simple text file, like a todo list.

Also when I have another idea I now adding it to github issue tracker as a "todo" item, sometimes even including some implementation details. Often when I think of some new feature I also think of how this feature is going to be done, what classes, what database model has to be added. I now if I don't write it down I will forget all the details.

So right now there are a few things on the "todo" list and I don't really want to even adding new ideas before at least some of the "todo" items are completed.

Important items now are "Internationalization" class. I am thinking of the best way to implement it right now.

Also want to add option the "reply" to comment so that it will be clear that a comment is a reply to @user
On StackOverflow you have to explicitely type @user when you replying. I want to simple add a "reply" link and then it will automatically add the @user and maybe even visually indicate that comment B is a reply to comment A

At the same time I am not in the process of writing the API. Most of read API is already done. Next I want to start writing OAuth2 based write API. I've never done this before, so it may not be as fast.

It's perfectly fine for me to switch tasks and just write the comments reply feature for now and then come back to OAuth API thing. I find this task switching is easier on my brain sometimes.


I know there are many more features I want to add, but I also see that the "todo" features list is not infinite. I pretty much know what else has to be done before I can call this a finished program.

These other things are "messaging system" that would include sending system and private user-to-user messages and also a custom SESSION storage class so that a large site that has multiple front-end servers can store session data somewhere on a dedicated server. Also SESSION class will make it easy to show "who's online" and "what they are doing now"

Agile is slightly different. TDD is also different. I mean, I do write test cases but usually not before the classes. In TDD you write test case first, then write code untill it passes your test. I don't do this yet, maybe in the future I will. I don't have any plans to use UnitTests for the documentation. This is a whole other pattern and I don't really like it. I like to just add descriptive comments to all my classes and methods. This is then easy for new developers and also for me to go back and read my own documentation in case I forget what I was thinking at the time I wrote something.

Lampcms REST API update

My Question on Support site for LampCMS project

Hello!
Just want to share some progress of the LampCMS API work:

Any good API must have a way for developers to quickly register their APP and get a unique API KEY.

I have added this feature. This is how it works: most api calls can be made without the API KEY but the daily rate limit will be low without the key. With the valid API KEY the daily limit is much higher. All these limits are configures from !config.ini

So this is how it works: If you want to add API to your Lampcms powered site you need to tell developers how to register their app. All you do is point them to /viewapps/ url
If use does not have any apps yet, then user is redirected to the form to create new app, otherwise user sees the list of all registered apps and can view and edit any app.

You are welcome to try it here http://support.lampcms.com/viewapps/

Once you have the api key you just add &apikey=somekey to all the API requests

For example: http://support.lampcms.com/api/api.php?a=questions&tags=feature&starttime=1306360958&apikey=yourkey

Replace "youkey" with your new valid key or you will get an error, just as you should in case of invalid api key

Several api controllers are ready. Controllers are identiried by the value of the 'a' param which stands for "action"

So in previous example url the "a" is "Questions"

Other controllers are "users" - get info on any user(s) by passing comma-separated values of "uids" param
You can also just call /api/api.php?a=users with no params to get all users and can user pageID and limit params to paginate results. Results can also be sorted using sort= and dir=
for example sort=i_rep&dir=desc to sort by reputation in descending order

Another controllers:


"tags" to get tags data,

"relatedtags" to get related tags - pass tag=sometag to get related data of "sometag"

"usertags" to get tags user's active tags. Pass userID in uid param

"isfollowing" to check if user identified by uid is following another user (or tag or question) identified by "val"
For example: /api/api.php?a=isfollowing&uid=3&t=q&val=125
Will return is_following = true if user with id 3
is following question with id 125

For example /api/api.php?a=isfollowing&uid=3&t=u&val=23
Will return is_following = true IF user with id 3 IS FOLLOWING
user with id 23 (false if not following)

I will push all the latest stuff to github soon so you can examine the API controllers for yourself.





Click here to post your reply


Thursday, June 9, 2011

My answer to "This is a multi-browser test for tag auto-compete"

This is my answer to a Question on Support site for LampCMS project


This is strange. What you describing is a buggy behaviour of the orifinal widget.
You can see it on the original widget demo page

http://rgrove.github.com/node-tokeninput/examples/example-autocomplete.html

(try apple, banana, cherry)

But since I applied a fix the bug is gone, you can select the autosuggested tag with a mouse (or with keyboard) now. I mean it works for me on this site using Chrome on Windows.

I am not sure about other browsers. Maybe it's different on Mac?

Have you reloaded the "Ask" page while holding down the shift key to update browser cache? I mean, is it possible that you were still using the old version of javascript file?