Skip to content

Instantly share code, notes, and snippets.

@slopjong
Last active October 3, 2019 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save slopjong/4c55cfb3a340ba300718 to your computer and use it in GitHub Desktop.
Save slopjong/4c55cfb3a340ba300718 to your computer and use it in GitHub Desktop.
Become DevOp Talk Series

Become DevOp

Introduction into PHP and JavaScript

AngularJS

  • AngularJS Best Practices: Directory Structure
  • Digest: AngularJs variable not updating
  • Overview of main features and how it's better than backbone (see this).
  • Controller as syntax described here
  • Let's code a calculater using AngularJS.
  • What to explain:
    • arguments are passed to controllers by using dependency injection, always use the long version as minifiers will break the application since minified variable names no longer correspond the right service providers.
    • data should be stored in services unless they should be bound to a scope. Services are singletons, controllers are not. Inject a data service to share the same data across multiple controllers.
    • Prefer
{{user.name}}
{{user.name}}s
``` over ```
{{user}}
{{user}}
``` if you intend to update the user name in both directives. See `8 Scoping $scope's`. * Pay attention when handling large collections with `ng-repeat` with filtering. See [this](http://www.reddit.com/r/angularjs/comments/2i5mvv/a_simple_trick_ive_used_to_improve_responsiveness/) * Use Batarang * use `ng-annotate` (btford/ngmin#93) if `ng-min` doesn't perform well or if it's not doing the job correctly. * definition minification: (show minified and non-minified code side-by-side) it's not about obfuscation, though the minified code is not really readable. On the other hand minified code can easily be unminified and IDEs such as PhpStorm have great support on following references. * Readings * [The Top 10 Mistakes AngularJS Developers Make](http://www.airpair.com/angularjs/posts/top-10-mistakes-angularjs-developers-make) * [Things I Wish I Were Told About Angular.js](http://ruoyusun.com/2013/05/25/things-i-wish-i-were-told-about-angular-js.html) Node.js & Express -----------------

Zend Framework

Apigility

Security

Workshop by Manu, test app

Youtube:

Testing

Docker

* Docker can be controlled in PHP by using Docklet.
* [Docker & Ansible](http://docs.ansible.com/docker_module.html)
* Commands
  * `docker rm -f $(docker ps -a -q)`
  * `docker rmi $(docker images -q)`
  * you can specify container name/id (id can be partial, name also?)
* [Provision with Vagrant](https://docs.vagrantup.com/v2/provisioning/docker.html)
* [Wikipedia: Docker](http://de.wikipedia.org/wiki/Docker_%28Software%29)
* [Renaissance der Container-Virtualisierung mit Docker](http://www.admin-magazin.de/Das-Heft/2014/02/Renaissance-der-Container-Virtualisierung-mit-Docker)
* [Run metrics](https://docs.docker.com/articles/runmetrics/)

Orchestration/Packaging
-----------------------

* Vagrant
* Chef/Puppet
* [Ansible](http://www.ansible.com/application-deployment)
  * [Integration with Vagrant](http://docs.ansible.com/guide_vagrant.html)
* The DevOps Security Handbook: Building Security in With Chef
  * [Part I](http://www.markerbench.com/blog/2013/10/01/chef-starter/)
  * [Part II](http://www.markerbench.com/blog/2013/10/03/chef-2nd-course/)
  * [Part III](http://www.markerbench.com/blog/2013/10/06/chef-3rd-course/)
* [Puppet SSL Explained](http://www.masterzen.fr/2010/11/14/puppet-ssl-explained/)

Continuous Integration
----------------------

* http://phpundercontrol.org/
* [Jenkins]()
  * [Continuous Delivery Using Build Pipelines With Jenkins and Ant](http://www.methodsandtools.com/archive/archive.php?id=121)
  * [How to run multiple jobs in parallel more than 1 level deep?](http://stackoverflow.com/questions/13366167/jenkins-hudson-how-to-run-multiple-jobs-in-parallel-more-than-1-level-deep)
  * [Template for Jenkins Jobs for PHP Projects](http://jenkins-php.org/)
* [CruiseControl](http://cruisecontrol.sourceforge.net/gettingstartedbindist.html)
* [CodeShip](https://codeship.com)
* [ContinuousPHP](http://continuousphp.com/)

Monitoring Tools
----------------

* Uptime
* [Remonit](http://zef.io/remonit/)
* Munin
* Icinga
  * https://github.com/Icinga/
  * https://github.com/Icinga/icinga-vagrant
  * https://www.icinga.org/

Some others listed [here](http://serverfault.com/questions/44/what-tool-do-you-use-to-monitor-your-servers).

Build Tools and Dependency Managers
-----------------------------------

* Composer
  * [In-Depth with Composer](http://slides.seld.be/?file=2012-09-14+In-Depth+with+Composer.html#1)
* Grunt
* Phing
  * [Building and deploying PHP applications with Phing](http://de.slideshare.net/michieltcs/building-and-deploying-php-applications-with-phing)
  * [Idiot-Proof Deployment with Phing](http://www.lornajane.net/posts/2011/idiot-proof-deployment-with-phing)
* Bower
* NPM
  * http://djebbz.github.io/npm-paris-js/#/
* http://qafoo.com/services/tools.html

Quality Assurance
-----------------

* [PHPQAtools](http://phpqatools.org/)

Docker

What if docker exits?

Sometimes running containers exit. You can restart an exited container, but ...

➜  ~  docker restart 1b9aa589c7a8
Error response from daemon: Cannot restart container 1b9aa589c7a8: Bind for 0.0.0.0:8082 failed: port is already allocated
2014/10/10 10:26:28 Error: failed to restart one or more containers

... this doesn't help always.

Common problem as described in this issue.

Links:

        $mapperMock = $this->getMock('Doctor\Mapper\Calendar');
        $mapperMock
            ->expects($this->once())
            ->method('getDoctorTimeSlots')
            ->will($this->returnValue([]))
        ;

        $translator = $this->getMock('Zend\Translator');
        $translator
            ->expects($this->any())
            ->method('translate')
            ->will($this->returnValue(''));

        $serviceManagerMock = new ServiceManager();
        $serviceManagerMock->setService('doctor.mapper.calendar', $mapperMock);
        $serviceManagerMock->setService('translator', $translator);
        $this->instance->setServiceLocator($serviceManagerMock);

        $expected = [];
        $actual = $this->instance->getDoctorTimeSlots(0, '2013-08-07', '2013-08-15');
        $this->assertSame($expected, $actual);

When mockuping fails

$mock = $this->getMock('Composer\Command\DockerBuildCommand');
$mock
    ->method('getBuildFiles')
    ->will($this->returnValue(array(
        'example/image2' => (new DebianImage())->from('example/image1'),
        'example/image1' => (new DebianImage())->from('ubuntu'),
    )));
PHP Fatal error:  Call to a member function setDescription() on null in /srv/http/posedoc-tool/src/Composer/Command/DockerBuildCommand.php on line 47

How it should be mockuped correctly

Test protected/private methods

class CustomTest extends TestCase
{
    public function testSomething()
    {
        $object = new MyClass();

        $returnVal = static::callMethod(
            $object,
            'doSomething'
        );

        $this->assertEmpty($returnVal);
    }

    protected static function callMethod($obj, $name, array $args = array())
    {
        $class = new \ReflectionClass($obj);
        $method = $class->getMethod($name);
        $method->setAccessible(true);

        if ($args) {
            return $method->invokeArgs($obj, $args);
        } else {
            return $method->invoke($obj);
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment