Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How to Take Over the World with Lithium

How to Take Over the World with Lithium

This talk was originally about how to take over the world. Then Instagram was acquired by Facebook for a BILLION DOLLARS.

I figure, a billion dollars? That's gotta be enough for a moon base with a laser. Let's just make a billion dollars, and the taking-over-the-world part will handle itself.

7fca546408cc6d46ab158f06baed2535?s=128

Nate Abele

April 13, 2012
Tweet

Transcript

  1. Taking Over the World with Lithium 2012-04-12 @ NYCPHP

  2. ?

  3. $1B

  4. How to Make a BILLION DOLLARS with Lithium 2012-04-12 @

    NYCPHP
  5. $ li3 library extract

  6. $ li3 library extract moneygram

  7. $ li3 library extract moneygram moneygram created in /<path to

    app> from / <path to lithium>/console/command/create/ template/app.phar.gz
  8. None
  9. $ cd moneygram/ && sudo chmod -R 777 resources/

  10. config/bootstrap/connections.php use lithium\data\Connections; Connections::add('default', array( 'type' => 'MongoDb', 'host' =>

    'localhost', 'database' => 'moneygram' ));
  11. None
  12. $ li3 create Photos

  13. $ li3 create Photos Photos created in moneygram\models. PhotosController created

    in moneygram\controllers. PhotosTest created in moneygram\tests\cases\models. PhotosControllerTest created in moneygram\tests\cases\controllers.
  14. config/routes.php Router::connect('/', 'Pages::view'); Router::connect('/', 'Photos::index');

  15. config/routes.php Router::connect('/', 'Pages::view'); Router::connect('/', 'Photos::index');

  16. None
  17. views/photos/index.html.php <?php if (!count($photos)): ?> <p> No photos! <?=$this->html->link('Add one',

    'Photos::add'); ?>. </p> <?php endif ?>
  18. views/photos/add.html.php <?=$this->form->create($photo, array( 'type' => 'file' )); ?> <?=$this->form->field('title'); ?>

    <?=$this->form->field('description'); ?> <?=$this->form->field('file', array( 'type' => 'file' )); ?> <?=$this->form->submit('Save'); ?> <?=$this->form->end(); ?>
  19. None
  20. None
  21. None
  22. views/layouts/default.html.php // … <?=$this->html->style(array( 'bootstrap', 'bootstrap-responsive' )); ?> // …

  23. None
  24. models/Photos.php namespace moneygram\models; class Photos extends \lithium\data\Model { // ..

    protected $_meta = array('source' => 'fs.files'); protected $_schema = array( '_id' => array('type' => '_id'), 'title' => array('type' => 'string'), 'description' => array('type' => 'string'), ); }
  25. None
  26. config/routes.php Router::connect( '/{:controller}/{:action}/{:id:[0-9a-f]{24}}.{:type}', array('id' => null) ); Router::connect( '/{:controller}/{:action}/{:id:[0-9a-f]{24}}' );

  27. views/photos/view.html.php <h2><?=$photo->title; ?></h2> <p><?=$photo->description; ?></p> <?=$this->html->image( "/photos/view/{$photo->_id}.jpg", array('alt' => $photo->title)

    ); ?>
  28. config/bootstrap/media.php Media::type('jpg', 'image/jpeg', array( 'cast' => false, 'encode' => function($data)

    { return $data['photo']->file->getBytes(); } )); config/bootstrap.php require __DIR__ . '/bootstrap/media.php';
  29. None
  30. views/photos/index.html.php <ul class="thumbnails"> <?php foreach ($photos as $photo): ?> <li

    class="span3"> <div class="thumbnail"> <?=$this->html->image("/photos/view/{$photo->_id}.jpg"); ?> <div class="caption"> <h5><?=$this->html->link( $photo->title, array('Photos::view', 'id' => $photo->_id) ); ?></h5> </div> </div> </li> <?php endforeach ?> </ul>
  31. views/photos/view.html.php <p> <?=$this->html->link( 'Age-ify!', array('Photos::edit', 'id' => $photo->_id), array('class' =>

    'btn btn-info') ); ?> </p>
  32. None
  33. $ git submodule add git://github.com/avalanche123/Imagine.git libraries/_source/Imagine Cloning into libraries/_source/Imagine... ....

    .... $ cd libraries/ && ln -s ./_source/Imagine/lib/Imagine Imagine
  34. config/bootstrap/libraries.php Libraries::add('Imagine');

  35. controllers/PhotosController.php use Imagine\Imagick\Imagine; use moneygram\extensions\imagine\SepiaToneFilter; class PhotosController extends \lithium\action\Controller {

    public function edit() { // ... } }
  36. controllers/PhotosController.php public function edit() { set_time_limit(0); $photo = Photos::first($this->request->id); $imagine

    = new Imagine(); $filter = new SepiaToneFilter($imagine); // ... }
  37. controllers/PhotosController.php public function edit() { // ... $new = $filter->apply($imagine->load(

    $photo->file->getBytes() )); $photo->delete(); $photo = Photos::create(array( '_id' => $photo->_id, 'title' => $photo->title, 'file' => $new->get('jpg') )); $photo->save(); return $this->redirect(array( 'Photos::view', 'id' => $photo->_id )); }
  38. extensions/imagine/SepiaToneFilter.php namespace moneygram\extensions\imagine; use Imagine\Image\Box; use Imagine\Image\Point; use Imagine\Image\Color; class

    SepiaToneFilter implements \Imagine\Filter\FilterInterface { // ... }
  39. extensions/imagine/SepiaToneFilter.php public function apply(\Imagine\Image\ImageInterface $image) { $new = $this->_imagine->create($image->getSize(), new

    Color('fff')); for ($x = 0; $x < $image->getSize()->getWidth(); $x++) { for ($y = 0; $y < $image->getSize()->getHeight(); $y++) { $position = new Point($x, $y); $pixel = $image->getColorAt($position); $r = $pixel->getRed(); $g = $pixel->getGreen(); $b = $pixel->getBlue(); $r = min(array((0.272 * $r) + (0.534 * $g) + (0.131 * ($b)), 255)); $g = min(array((0.349 * $r) + (0.686 * $g) + (0.168 * ($b)), 255)); $b = min(array((0.393 * $r) + (0.769 * $g) + (0.189 * ($b)), 255)); $r = ($r > 255) ? 255 : $r; $g = ($g > 255) ? 255 : $g; $b = ($b > 255) ? 255 : $b; $pixel = new Color(array($r, $g, $b)); $new->draw()->dot($position, $pixel); } } return $new; }
  40. None