Sennheiser CX 300-II

The bass is decent but it muds up the rest of the audio.
The high end is a bit off compared to the mids.

Ear fit is great. I have large ear canals (especially the right side) and the standard size does a pretty good job.

They have a unique design which is nice at times and at other times weird. The left speakers is on about a 1 foot cable from the split and the right is on a 2 foot cable from the split. Its nice when you keep in the left while keeping out the right so you can hear if some one comes to your desk and that keeps the cable out of your way while typing.

They do a pretty good job of blocking outside noise in an office likes sales people and office printers.

I would give them a 3.5/5 for price to quality.

Amazon Sennheiser II Precision Enhanced Earbuds

Continue reading Sennheiser CX 300-II

API Response Suggestions

So todays coding is all about standards but also about the wild west but also making the code that comes out of the wild west a standard (which a lot of it does).

I’m torn every time I look something up that I’m not sure about or would like to see if there is a new suggestion or standard to follow.

I will work a little harder to take an idea to make it work to a standard but there comes a point that it just to much to keep up with and the next time I touch my “future proofed” code, it will be different.

So I look at what the wild west is doing then what the best practice is and then what posts on stackoverflow say and usually I take the best suggestion on stackoverewflow that is as close to a standard I found and try and clean it up best as I can and then stop worrying about if its 100% right. The only times I change my mind is if a best practice of another technology needs it and it makes my life easier than if I ignore it, it’s seldom but it does happen.

The Best Practice / Wild West Talk:

The Best Practice:

http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

The Suggestion of Best Practice:

http://jsonapi.org/format/

The “What I do” Best Practice:

http://stackoverflow.com/questions/12806386/standard-json-api-response-format

My 2 thoughts on this:

The Json API is pretty simple to implement, it seems to meet todays standards but is the extreme of Hypermedia Restful. Yes that new standards looks so nice but I’m sorry I’m building the API for our own app and know what I need, the overhead just isn’t worth it.

Suggestion #2 Standard JSON API

I do like using the HTTP Status Codes to better handle the type of Errors happening without depending on them solely for determining the state of our application. I do like the idea of just being able to check the HTTP Status first and then moving down to checking the error code of the response. Overall I think it gives the API a well rounded feel without it making it to complicated to know how the application is working plus it seems to better fit our current state with multiple different levels of coding standards and application structures with these legacy applications.

Continue reading API Response Suggestions

Dependency Injection and Containers

I realized I haven’t explained dependency injection or containers on here but I reference them in places (Controllers as Service) with little regard to the reads level of understanding.

Dependency Injection itself isn’t a complex subject. Here is an example:

<?php

class A{
    protected $dependencyOne;
    public function __construct($b) {
         $this->dependencyOne = $b;
    }
}

class B{
    public function __construct(){
        echo 'hey';
    }
}

$b = new B();
$a = new A($b);

So instead of A creating B since it needs it, you pass in B. That is dependency injection. Nothing more. Nothing to be scared about.

So a container is something this was built to help this process and do a little bit more.

Using or example above here is what it looks like using Pimple\Container.

<?php
$container = new Pimple\Container();

$container['b'] = function($c){
    return new B();
}

$container['a'] = function($c){
    return new A($c['b']);
}

So that seems like a lot of work to get a simple object into another but image a more complex tree. A->B->C->D,E,F,G,H->I. That would be a lot to type every time you needed A in your project. So instead you pass the container around or pass in A into the utility, controller or any other other class that might require A and the container takes care of the rest.

Like the Controllers as Service article, you can do some more complex requires without having to do it over and over again.

Continue reading Dependency Injection and Containers

Building an MVC while Refactoring – Part 2 – Controllers as a Service

I found hints of this while working on refactoring a project into using MVC.

Framework Independent Controllers by Matthias Noback

Pimple Container with Yaml by Gonzalo

Symfony post about Controllers as a service

Controllers as a Service.

Using Symfony’s Routing and Resolvers, it seems like a simple move.

Well it was(n’t). I tried this tutorials, Messing Around with Silex Pimple, one issue I found was that the Silex is still using v1 of Pimple which now has changed to Pimple\Container, removed the ->share method and just over all matured. So I needed find a way to do this outside of Silex and using a new version of Pimple’s Container.

The second part was fairly easy since ->share is now just = function($c) since its now the default.

The first part was the issue. How do I get Symfony’s Controller Resolver to work with Pimple outside of the Symfony Framework and not in Silex.

The hunt began.

I found this file that depended on the file below it:

  • https://github.com/silexphp/Silex/blob/1.2/src/Silex/CallbackResolver.php
  • https://github.com/silexphp/Silex/blob/1.2/src/Silex/ServiceControllerResolver.php

It also depended on the symfony ControllerResolver but that was easy to add.


<?php use Symfony\Component\ClassLoader\MapClassLoader as MapClassLoader; use Symfony\Component\ClassLoader\UniversalClassLoader; use Pimple\Container; //temporary till mvc is setup use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Config\FileLocator; use Symfony\Component\Routing\Loader\YamlFileLoader; use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing; use Symfony\Component\HttpKernel; use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface; $container['callback_resolver'] = function ($c) { return new \App\Component\CallbackResolver($c); }; $container['request'] = function($c) { return Request::createFromGlobals(); }; $container['resolver'] = function($c) { return new \App\Component\HttpKernel\Controller\ServiceControllerResolver(new HttpKernel\Controller\ControllerResolver(), $c['callback_resolver']); }; $container['routes'] = function($c) { return new RouteCollection(); }; $container['routes'] = $container->extend('routes', function(RouteCollection $routes) { $loader = new YamlFileLoader(new FileLocator(APP_DIR . '/Resource/config')); $collection = $loader->load('routes.yml'); $routes->addCollection($collection); return $routes; }); $container['context'] = function($c) { return new Routing\RequestContext(); }; $container['matcher'] = function($c) { return new Routing\Matcher\UrlMatcher($c['routes'], $c['context']); }; //Controller Service $container['index_controller'] = function($c) { return new \App\Controller\IndexController($c['database']); }; $container['config'] = function($c) { return; }; $container['kernel'] = function($c) { return new \App\Kernel($c['matcher'], $c['resolver']); }; $container['context']->fromRequest($container['request']); $response = $container['kernel']->handle($container['request']); $response->send();

Modified ServiceControllerResolver File from Silex Framework

Modified CallbackResolver File From Silex Framework

There are still somethings to work out with these files so that error handling / logging is taken care of. The services will soon be loaded by a yaml file but in all it was a great fix to make the controller have dependencies and not require being built to meet the Silex/Symfony only needs.

Continue reading Building an MVC while Refactoring – Part 2 – Controllers as a Service

Moving to Twitter Bootstrap

So you’ve decided to make your site responsive.

There are a ton of frameworks out there that can help you with this, I recommend Twitter Bootstrap, because well, its from Twitter and easy to get working. No other convincing to happen here. Good luck with your choice

So you picked Twitter Bootstrap, great! Now you have things that used jquery-ui and now are broken. Thats fine. Something things just werent built to be responsive or work together or get the point that it shouldn’t use JS to style to much. The web works well with its html and css for layout and design and javascript for functionality, lets keep it that way as best as possible.

jQuery-UI AutoComplete isn’t really compatible with Bootstrap. You can make it but there is a better way.

The answer to that is Twitter Typeahead which is really 2 different libraries that work together to make a very robust and well formatted system. How to implement Typeahead

Continue reading Moving to Twitter Bootstrap

Building an MVC while Refactoring – Part 1

First, follow 99% of this: Create Your Own Framework by Fabian

Second, watch this, it will make you say “How can he be talking about me with such detail?”: It Was Like That When I Got Here: Steps Toward Modernizing a Legacy Codebase

Third, pay and read this by the guy who did the video: Modernizing Legacy Applications In PHP

This book gets you off on how to do things the right way. I did diverge in a few areas since I’ve worked with other frameworks and not completely in agreement with his folder structure but thats nothing compared to the help it provides. I read it and loved it.

Now thats out of the way, here are some things that are covered may not work with you as with me.

One thing is, I’m building the MVC with the idea this is coming from legacy code that still needs to exist, the urls still need to be there and there is a lot of strictly coupled code & settings that prevent just moving over a page at a time.

Too be continued

Continue reading Building an MVC while Refactoring – Part 1