Sunday, January 26, 2014

CodeIgniter is Out and Laravel is In!



While working on some projects developed codeigniter more than a year ago I also had issues with the session component not working properly on IE, not sure if they solved that issue. Too bad that codeigniter framework is not developed anymore because as far as I know there are a lot of PHP web applications using codeigniter.

Sunday, January 19, 2014

Thursday, January 2, 2014

Git stash

Using git stash

Sometimes we are working on a new feature on a project using the git version control and we are requested to fix a bug or just check some piece of code on another branch. We would not want to commit a half way done feature, also we would not like to delete the changes to the branch. Well we can use git stash, by just running this command the changes are stashed until we later need them, if we run git status we can see that no changes appear to the branch and we can change branches without the need to commit unstable code and messing our project history. After we finished fixing the bug we checkout the original branch at which we started the feature and we can run git stash apply to add back the changes to the branch.

Other scenarios

There are other scenarios when we might use git stash. For example we started to implement a new feature on a wrong branch. Again git stash helps us, we can run this command and create a new branch using git checkout -b some_new_branch or on an existing branch using git checkout some_existing_branch, now we can run git stash apply and the code which was not commit on the previous branch appears now on the new one.

We can also stash multiple set of changes and you can see them using git stash list, if we want to apply changes from a specific stash we can do git stash apply stash@{stash number}





Sunday, October 27, 2013

Prolog: Insert an element on a given position

%Insert an element onto the n-th position of a list.
domains
element=integer
list=element*

predicates
insert(list, element, integer, integer, list)

clauses
%If initial list is empty(no elements in the list and CurrentPosition is still 1 because it was not incremented)
insert([], Element, InsertionPosition, 1, [Element]).

%We reached the moment in which the initial list is empty, but CurrentPosition is not 1(case handled above)
insert([], Element, InsertionPosition, CurrentPosition, []).

%Reached the case in which CurrentPosition is equal to InsertionPosition so we ll insert the element!
insert(List, Element, InsertionPosition, InsertionPosition, [Element| ResultedListTail]):-
CurrentPositionCopy = InsertionPosition + 1,
insert(List, Element, InsertionPosition, CurrentPositionCopy, ResultedListTail).

%By default we should copy element from initial list to resulted list and increment currentPosition
insert([Head| Tail], Element, InsertionPosition, CurrentPosition, [Head| ResultedListTail]):-
CurrentPositionCopy = CurrentPosition + 1,
insert(Tail, Element, InsertionPosition, CurrentPositionCopy, ResultedListTail).


goal
%We will insert element 2 on position 2
insert([1, 3, 4, 5, 6, 7], 2, 2, 1, ResultedList),
write(ResultedList).

Monday, October 7, 2013

Installing phpunit/PHP_Timer issue

After uninstalling phpunit/PHP_Timer and trying to install another version I was getting the message
No releases available for package "pear.phpunit.de/PHP_Timer" install failed
But I did not have PHP_Timer installed at all, the solution for this was to run
pear clear-cache
After that command to install phpunit/PHP_Timer pear install phpunit/PHP_Timer ran successfully!

Saturday, August 24, 2013

Symfony2 routing tip

Symfony2 routing tip

Did you ever needed to make the default value to NULL of a routing parameter when using XML for symfony2?
Here is a sample configuration
<route id="acme_user_show" pattern="/{id}">
    <default key="_controller">AcmeUserBundle:User:show</default>
    <default key="id" xsi:nil="true" />
</route>