Skip to content

Instantly share code, notes, and snippets.

View dmitrybelyakov's full-sized avatar

Dmitry Belyakov dmitrybelyakov

View GitHub Profile
{
"entry": [{
"id": "170732843767218",
"messaging": [{
"message": {
"mid": "mid.$cAACbR4sU9YJqcg-ACFkQMo3sqezB",
"seq": 29877,
"text": "hey bot!"
},
"recipient": {
@dmitrybelyakov
dmitrybelyakov / nearby-coordinates.sql
Created June 5, 2018 11:45 — forked from statickidz/nearby-coordinates.sql
Ordering with SQL by nearest latitude & longitude coordinates (MySQL & SQLite)
---
METHOD 1
This should roughly sort the items on distance in MySQL, and should work in SQLite.
If you need to sort them preciser, you could try using the Pythagorean theorem (a^2 + b^2 = c^2) to get the exact distance.
---
SELECT *
FROM table
ORDER BY ((lat-$user_lat)*(lat-$user_lat)) + ((lng - $user_lng)*(lng - $user_lng)) ASC
@dmitrybelyakov
dmitrybelyakov / AppKernel.php
Last active October 3, 2016 08:59
Symfony write cache and logs to memory
<?php
public function getCacheDir()
{
if (in_array($this->environment, array('dev', 'test'))) {
return '/dev/shm/appname/cache/' . $this->environment;
}
return parent::getCacheDir();
}
@dmitrybelyakov
dmitrybelyakov / pedantically_commented_playbook.yml
Created October 26, 2015 11:14 — forked from phred/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
#!/bin/bash
# Make sure we have the dev tools
yum groupinstall "Development Tools"
# Just in case you started installing dependencies from yum
yum -y remove libnfnetlink
# lets put the source code here
mkdir -p ~/.src
@dmitrybelyakov
dmitrybelyakov / Controller.php
Created March 6, 2014 07:58
Bind entity to form with fieldsets
<?php
/**
* Example action
* This is an example action that tests binding of forms to entities.
* @return \Zend\View\Model\ViewModel
*/
public function exampleAction()
{
$node = new ArrayObject(array(
/**
* Construct
* Instantiates the form and configures input fields
*
* @return void
*/
public function __construct($name, array $options = array())
{
//init
parent::__construct($name, $options);

Looking for a way to define a view helper via configuration. That helper should be created via callback factory and have a dependency injected in constructor, as per documentation here: Registering Helpers

So there we go with a helper itself:

class Locale extends AbstractHelper
{

    protected $localeService;
//action helpers (controller plugins)
'controller_plugins' => array(
'invokables' => array(
'isAllowed' => 'ShiftUser\Access\ActionHelper\IsAllowed'
),
'factories' => array(
'ShiftUser\Access\ActionHelper\IsAllowed' => function($sm){
$class = new \ShiftUser\Access\ActionHelper\IsAllowed($sm);
$class->createByFactory();
'view_helpers' => array(
'invokables' => array(
'currentlocale' => 'ShiftKernel\Locale\ViewHelper\Locale',
),
'factories' => array(
'currentlocale' => function($sm) {
return new \ShiftKernel\Locale\ViewHelper\Locale(
$sm->get('ShiftKernel\Locale\LocaleService')
);
},