Skip to content

Instantly share code, notes, and snippets.

@notomato
notomato / elasticsearch
Created July 21, 2011 09:02
Elastic search init.rd
#! /bin/sh
### BEGIN INIT INFO
# Provides: elasticsearch
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts elasticsearch
# Description: Starts elasticsearch using start-stop-daemon
### END INIT INFO
@notomato
notomato / gist:3331560
Created August 12, 2012 11:59
Custom environment variables example
// This can go in a custom bootstrap file
use lithium\core\Environment;
Environment::set('foo.com', array(
'something' => array(
'filename' => 'foo.yml'
)
));
@notomato
notomato / gist:3331564
Created August 12, 2012 12:00
Example session bootstrap
use lithium\storage\Session;
Session::config(array(
'default' => array(
'adapter' => 'Cookie',
'strategies' => array(
'Encrypt' => array('secret' => 'somesecretstring')
)
)
@notomato
notomato / session.php
Created August 17, 2012 02:24
Encrypt and sign cookies
Session::config(array(
'default' => array(
'adapter' => 'Cookie',
'strategies' => array(
'Hmac' => array(
'secret' => '$f00bar$'
),
'Encrypt' => array(
'secret' => '$f00bar$'
)
@notomato
notomato / routes.php
Created August 17, 2012 02:33
Nested/continued routes
<?php
Router::connect('/admin/{:args}', array('admin' => true), array('continue' => true));
Router::connect('/{:locale:en|de|jp}/{:args}', array(), array('continue' => true));
Router::connect('/{:args}.{:type}', array(), array('continue' => true));
@notomato
notomato / errors.php
Created August 17, 2012 02:56
Error handling example
<?php
$method = array(Connections::get('default'), 'read');
ErrorHandler::apply($method, array(), function($error, $params) {
$queryParams = json_encode($params['query']);
$msg = "Query error: {$error['message']}";
Logger::warning("{$msg}, data: {$queryParams}");
return new DocumentSet();
@notomato
notomato / gist:3376793
Created August 17, 2012 07:38
Securing forms
// View
<?= $this->form->create(); ?>
<?=$this->security->requestToken(); ?>
<?=$this->form->field('title'); ?>
<?=$this->form->submit('Submit'); ?>
<?=$this->form->end(); ?>
// Controller
public function add() {
if ($this->request->data && !RequestToken::check($this->request)) {
@notomato
notomato / gist:3376825
Created August 17, 2012 07:50
Example li3_access configuration and use
<?php
// config/bootstrap/access.php
Access::config(array(
'asset' => array(
'adapter' => 'Rules',
'allowAny' => true,
'default' => array('isPublic', 'isOwner', 'isParticipant'),
'user' => function() { return Accounts::current(); },
'rules' => array(
@notomato
notomato / gist:3376832
Created August 17, 2012 07:54
Make sure you return on redirect
<?php
// Make sure you return on redirect, not do this:
class PostsController extends Base {
public function view($post) {
if (!$post) {
$this->redirect("Posts::index");
}
@notomato
notomato / gist:3376843
Created August 17, 2012 07:57
Fat filters are bad
<?php
// FAT FILTERS == BAD
// Try to make filters do one thing, not like this...
Dispatcher::applyFilter(run, function($self, $params, $chain) {
// Herp
// Derp
// Herp
// Derp