Posts

Showing posts from March, 2013

Implementing Monads in JavaScript

UPDATE: This post has been updated to a new post. All the code has been refactored and redone in the new post. http://functionaljavascript.blogspot.in/2013/07/monads.html Consider the problem of doing a series of computations (calling a series of functions), and you want each successive computation to have access to the results of the previous computations. We will write a function called doComputations , and here is how a call to doComputations would look like. var result = doComputations( "a", function(scope) { return 2; }, "b", function(scope) { with (scope) { return a * 3; } }, function(scope) { with(scope) { return a + b; } } ); The arguments to doComputaions are one or more "string - function" pairs and the last argument is just a "result" function. The string is a variable name which will be assigned the value returne...

Architecting scrum

Thoughts on Engineering Design and Analysis phase, specific to running sprints. Thoughts are based on assumption that PO is ready with sprint items. I. Pre-requisites: -      Understanding sprint requirements: New User Stories Story Specifications Walk through (PO, QA, Dev) Understanding Acceptance Criteria Wireframes walkthrough (where available) Gathering performance and security requirements Walk through of issues to be resolved in sprint and their priorities II. Architecting Process   -      Technical Impact Analysis  (Very Important for running sprints) – Identifying impact on existing application against implementation thought for new stories/issues  -       Planning implementation of any technical change in process/technology based on previous sprint review, retrospective meetings or any feedback from client -        Decision Analysis & Resolution  – Identifying ...

PHP password hash with salt

It is more secure to stora a password hashed with added static (or even dynamic salt). To achieve static salt in password just append a string when calculating a hash. Example below shows dynamic salt, most secure: function getHash( $pass , $login ) { $salt = substr( md5( $login ) , 0 , 10 ); return hash( 'sha256' , $pass . 'ThEStAtIcSaLe' . $salt ); } Remeber to use same function when checking user credentials.It will be also more secure to use slower hashing/crypting function

Inheritance in PHP

Inheritance (extending classes) is realised in PHP with extends keyword: class albumController extends MfStandardController { Now, object of class albumController will be of type albumController, but also of type MfStandardController, because MfStandardController is a parent of this class

Sample smarty loop with images

If you want to print several images on your site, you must assign array of those images to smarty variable. Then, you can iterate over this array in smarty and show img tags for each image. Rember about good path: {foreach from=$sm_photos item=item} <img src="/content/photophoto/1/{$item.file}"> {/foreach} If your path will not target image file, you can get 404 error, but typically image will be just hidden

Introduction to Functional JavaScript

JavaScript was a functional programming language even before it got its name! Back in 1995 Netscape Communications the makers of the Netscape Browser realized that their browser needed a scripting language embedded in HTML. They hired Brendan Eich to embed the Scheme programming language in HTML. Scheme was a full fledged functional programming language. To his dismay “the powers that be” encouraged Brendan to come up with a more traditional programming language. His first cut was a language called “Mocha” in May 1995, and it retained that name till December 1995. It was first renamed “LiveScript” and soon after that Netscape and Sun did a license agreement and it was called “JavaScript”. But by then Brendan Eich had sneaked in some “functional programming” features into JavaScript. The story gets more complicated, and we will delve into it. Because this story will tell you why JavaScript is what it is today. Brendan Eich claims that hiring him to embed the Scheme language, might actu...

Why stackoverflow is really important for PHP programmers and developers

It is really a tough question for PHP programmers who actually don't familiar with stackoverflow.com. This site is a very popular site for developers and programmers who love to write PHP code and function(Not only PHP programmers but also for all kinds of programmers). It is a platform and a programmer and expert based community who loves to help others.  I am a PHP programmer, I can't imagine my development life without stackeoverflow .  There are bunch of questions have arises in my mind when I thought about this and the importance of stackoverflow . Here I come with some idea with suggestions for new PHP developers who want to develop real life project and why stackoverflow is a big mouth for you. At first we need to know what is stackoverflow.com. Stack Overflow is very famous website and it is one of the flagship question and answer site of the Stack Exchange Network. It discusses wide range of topics related on Computer Programming such as Android, PHP, Java, ASP.NET et...

PHP: Get last element of array

Often you need to get the last element of PHP array. This is easy to achieve with using count() function, wich counts all elements in array. Because PHP arrays are indexed from 0, you must remeber to get "count()-1" element of an array, not "count()" element: $exampleArray = array( 3,6,8,11,14 ); $lastElement = $array[ count($exampleArray) - 1]; echo $lastElement; // prints 14 This is the obvious way for some begginer developers. But more experienced developers will know, that there is a function defined especially for this purpose: echo end( $exampleArray ); // prints 14 Because this function will move internal array pointer to the end, you can reset it if you are currently iterating over this orray, for example: reset( $exampleArray ); // prints 14 If you are afraid about non set array, or set as other type than array, you can use function is_array() to check if this variable is defined as array. You can also get a last key of an array in several ways: echo ...

How to quote in echo or print in PHP?

If you are creating applications in PHP, even if you are beginner, you definatelly see echo function already. Echo function just outputs it's argument to a user browser or to a console/terminal if PHP script is running in the CLI mode. The trouble rises, when you have to put ' or " sign in a echo, because you have to use one of this characters just to begin and terminate echo literal. To embed such characters in displayer string, you need to use escape sequence . It is a special characters combination, that makes some special sense in string literal. So, if you want to send quote sign to user, not to terminate echo string, use \" escape sequence. If your sequence is terminated by single quotes ('), then you can also include this character in string by escape sequence \'. See examples below: echo "This example shows \"escape sequences\" in php string, like quotes etc"; echo 'This example shows \'escape sequences\' in php string, ...

How to do SMARTY foreach loop to present array values from PHP?

SMARTY is a very good template engine that helps you decompose application view and model. If you want to create a SMARTY foreach loop, you need to have assigned array first. If you want only to present array values, then it can be a usual PHP array without special keys. But SMARTY foreach, same as foreach in PHP, can present keys for array items. The basic construction of foreach loop in smarty, together with PHP array assigment to present in view, you can see below: // In PHP: $array = new array( 'key1' => 'val1' , 'key2' => 'val2' ); $smarty->assign('someAssignedArray' , $array ); // In SMARTY: {foreach from=$someAssignedArray key=keyOfItem item=itemValue} The key of this item is: {$keyOfItem}<br> The value of this item is: {$itemValue}<br> {/foreach} As you can see, we have to have defined array first. Example above shows custom keyed array, but this array can also have standarized default keys like 0,1,2,3,4 etc. ...

PHP Login, Logout and Registration System with Sample Code

Image
Login, Logout and Registration system is an essential features for any web application. This is simple PHP based application that I will describe with sample PHP code. You can add this common application in your PHP project. This tutorial is for beginners, and also it is very easy to understand. So first of all take a look at the contents that you should learn throughout this brief tutorial.  PHP Login, Logout and Registration Tutorial: Introduction Basic Requirements Creating MySQL Database MySQL Database Connection using PHP Database Selection and Closing Some Fundamental SQL Query Creating HTML Layout using Twitter Bootstrap Creating Registration Form and Login Form Handling Registration Form using PHP PHP Login and Logout Handling  Consolidating All Parts  Conclusion  That's are the thing I will describe throughout the whole tutorial. So let's start Introduction:  Using this application a user can be a registered member through a registration form. Only ea...

Call superclass method in object oriented PHP application

You can call parent methods using :: operator, as in example below: parent::init( 'aaa' ); This situation works also, when dealing with static methods.

Call parent constructor in PHP

You can call constructor of the superclass of your class. Why to do that? It's important if you write your own constructor. If you derive from a class and write custom constructor then, when object is creating o only yours constructor will be called. This can casue a situation, when object isn't propably initialised. For example, some fields can be not set, null valued etc. To prevent those situations it is a good practice to call parent construtor in your class constructor as the first line like example below: public function __construct() { parent::__construct( 11 ); } In this situation you prevents errors like uninitialised class variables, uncalled other initialisation methods etc. As you can see, there is also a posibility to pass some variables to parent conscturctor. This is common case - if you derive from a class, wich have some variables in constructor, then you have to pass those variables in parent constructor call. If you are afraid, that some developer who wil...

Best PHP Frameworks for Your Project

For a web application developer it is very difficult to stay organized if they don't have a clear structure for their apps. Starting with app development from scratch is a very tough and tedious task, so several developers select a framework and start development according to it. Many developers want to initiate their work with PHP frameworks but they don't have the required knowledge about the best PHP frameworks which can be really useful for their projects. The knowledge about the best PHP frameworks comes in handy. Frameworks are great assistance to PHP developers as they help in structuring the codes so they can function as a streamlined and logical application. Frameworks were introduced long time back but it was only with the advent of Ruby on Rails that developers started adopting frameworks for their projects. Nowadays a majority of frameworks follows the model-view-controller pattern. MVC pattern deals with the presentation of your data. So, now we have a little ov...