Monday, March 17, 2014
Thursday, March 13, 2014
How to Reset MACOS Password
- Restart the Mac holding down the Command+S keys
- You’ll need to check the filesystem first:
- Next, you must mount the root drive as writeable so that changes will save:
- Now, type the following command exactly, followed by the enter key:
fsck -fymount -uw /rm /var/db/.applesetupdoneshtudown -h nowTuesday, March 11, 2014
Friday, March 7, 2014
WebService ZF2 (RESTful)
RESTful Services made easy with ZF2.
Thera are many ways (technologies) to implement a web-services.
ZF2 Fundamentals:
• PHP 5.3.3+ (and tested on 5.4, as well as upcoming
5.5)
• Modular & flexible (ModuleManager)
• Event-driven (EventManager)
• Leverage Inversion of Control (ServiceManager)
• Re-written MVC, Forms, I18n, Db, and more
Event Example by Rob Allen:
Simple example
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
};
$events = new EventManager();
$events->attach('eventName', $callback);
echo "\nRaise an event\n";
$events->trigger('eventName');
LISTENER
Listeners
Just a function (Any callback)
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
var_dump($event->getTarget());
var_dump($event->getParams());
};
$events = $someObject->getEventManager();
$events->attach('eventName', $callback);
Thera are many ways (technologies) to implement a web-services.
- Representation State Transfer or REST , that it has been preferred for web services used in web applications.
- SOAP web service, also know as WS-* Stack, is also popular alternative.
But REST has been more popular over web developers.
What is REST:
According to Abeysinghe "
REST is a software architecture style that can be followed while designing software systems. REST is an ideal design style to be followed for web services based software applications."
The key REST principles in brief:
- Provide every resource with a unique ID, for example, a URI Link resources with each other, establishing relationships among resources
- Use standard methods (HTTP, media types, XML)
- Resources can have multiple representations that reflect different application states
- The communication should be stateless using the HTTP
Rob Allen said that principal Constraints are:
- Client/Server
- Stateless
- No client context stored between requests. This means no sessions.
- Cacheable
- Non-idepoment methos should allow client to cache responses.
- Clients should honor HTTP headers with respect to caching.
- Layered system
- Client should not care whether it is connected.
- Uniform Interface
- Identification of resources
- Manipulation of resources through representations
- Self-descriptive messages
- Hypermedia as the engine of application state.
• PHP 5.3.3+ (and tested on 5.4, as well as upcoming
5.5)
• Modular & flexible (ModuleManager)
• Event-driven (EventManager)
• Leverage Inversion of Control (ServiceManager)
• Re-written MVC, Forms, I18n, Db, and more
Event Example by Rob Allen:
Simple example
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
};
$events = new EventManager();
$events->attach('eventName', $callback);
echo "\nRaise an event\n";
$events->trigger('eventName');
LISTENER
Listeners
Just a function (Any callback)
$callback = function($event) {
echo "An event has happened!\n";
var_dump($event->getName());
var_dump($event->getTarget());
var_dump($event->getParams());
};
$events = $someObject->getEventManager();
$events->attach('eventName', $callback);
TARGET
Compose an EventManager within a class…
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
class MyTarget
{
public $events;
public function __construct()
{
$this->events = new EventManager();
}
… and trigger actions within methods.
public function doIt()
{
$event = new Event();
$event->setTarget($this);
$event->setParam('one', 1);
$this->events->trigger('doIt.pre', $event);
// do something here
$this->events->trigger('doIt.post', $event);
}Typical usage
$callback = function ($event) {
echo "Responding to doIt.pre!\n";
var_dump(get_class($event->getTarget()));
var_dump($event->getName());
var_dump($event->getParams());
};
$target= new MyTarget();
$target->events->attach('doIt.pre', $callback);
$target->doIt();
Compose an EventManager within a class…
use Zend\EventManager\EventManager,
Zend\EventManager\Event;
class MyTarget
{
public $events;
public function __construct()
{
$this->events = new EventManager();
}
… and trigger actions within methods.
public function doIt()
{
$event = new Event();
$event->setTarget($this);
$event->setParam('one', 1);
$this->events->trigger('doIt.pre', $event);
// do something here
$this->events->trigger('doIt.post', $event);
}Typical usage
$callback = function ($event) {
echo "Responding to doIt.pre!\n";
var_dump(get_class($event->getTarget()));
var_dump($event->getName());
var_dump($event->getParams());
};
$target= new MyTarget();
$target->events->attach('doIt.pre', $callback);
$target->doIt();
Thursday, March 6, 2014
Dont Forget .htaccess
How to read a file .htaccess over apache
If your RootDirectory is
/var/www directory.
use to active
$ sudo a2enmod rewrite
command and that should work, right?
Well, not really… Even though the issued command creates the symlink for the rewrite.load file at /etc/apache2/mods-enabled, you still have to manually edit your /etc/apache2/sites-enabled/000-default file and change the AllowOverride directive from None to All at the /var/www Directory section.
So the section that looks like:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None # change this line
Order allow,deny
allow from all
</Directory>
Should look like:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All # now it will read .htaccess
Order allow,deny
allow from all
</Directory>
Restart the service
service apache2 restart.
With AllowOverride directive to All , you are tell' the WebServer to read .htaccess and load. Otherwise it wont read (AllowOverride None).
If your RootDirectory is
/var/www directory.
use to active
$ sudo a2enmod rewrite
command and that should work, right?
Well, not really… Even though the issued command creates the symlink for the rewrite.load file at /etc/apache2/mods-enabled, you still have to manually edit your /etc/apache2/sites-enabled/000-default file and change the AllowOverride directive from None to All at the /var/www Directory section.
So the section that looks like:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None # change this line
Order allow,deny
allow from all
</Directory>
Should look like:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All # now it will read .htaccess
Order allow,deny
allow from all
</Directory>
Restart the service
service apache2 restart.
With AllowOverride directive to All , you are tell' the WebServer to read .htaccess and load. Otherwise it wont read (AllowOverride None).
Subscribe to:
Posts (Atom)