Skip to content

Instantly share code, notes, and snippets.

View linxlad's full-sized avatar

Nathan Daly linxlad

  • Bury St Edmunds, England
View GitHub Profile
@linxlad
linxlad / TypeListMetaUtil.php
Last active August 18, 2016 10:40
Document Typelist Meta Matcher
<?php
namespace OpenObjects\Bundle\CoreBundle\Util;
/**
* Class TypeListMetaUtil
* @package OpenObjects\Bundle\CoreBundle\Util
*/
class TypeListMetaUtil
{
@linxlad
linxlad / FormErrorsSerializer.php
Last active August 18, 2023 11:20 — forked from Graceas/FormErrorsSerializer.php
Symfony 2 Form Error Serializer. May be used for AJAX form validation. Allows tree and flat array styles for errors.
<?php
namespace OpenObjects\Bundle\CoreBundle\Service;
use Symfony\Component\Form\Extension\Validator\ViolationMapper\ViolationMapper;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\FormError;
use Symfony\Component\Validator\ConstraintViolation;
/**
@linxlad
linxlad / script.sql
Created July 1, 2016 10:13 — forked from vielhuber/README.MD
PostgreSQL: Concat two strings intelligently
SELECT CONCAT(
first_name,
(CASE WHEN (first_name IS NULL OR first_name = '') THEN '' ELSE ', ' END),
last_name
) FROM members
@linxlad
linxlad / voting.component.ts
Created June 26, 2016 10:30
Angular 2 voting component.
import {Component, Input, Output, EventEmitter} from 'angular2/core'
/**
* <voting [voteCount]="post.voteCount" [myVote]="post.myVote" (vote)="onVote($event)"></voting>
*/
@Component({
selector: 'voting',
template: `
<div class="voter">
<li
@linxlad
linxlad / like.component.ts
Created June 26, 2016 00:55
Angular 2 Twitter heart like icon component.
import {Component, Input, Output, EventEmitter} from 'angular2/core'
/**
* <like [totalLikes]="post.totalLikes" [iLike]="post.iLike" (change)="oniLikeChange($event)"></like>
*/
@Component({
selector: 'like',
template: `
<li
class="glyphicon glyphicon-heart"
@linxlad
linxlad / auto-grow.directive.ts
Created June 25, 2016 22:23
Auto grow directive for Angular 2.
import {Directive, ElementRef, Attribute} from 'angular2/core'
import {AnimationBuilder} from 'angular2/src/animate/animation_builder';
import {CssAnimationBuilder} from 'angular2/src/animate/css_animation_builder';
/**
* <input type="text" grow-duration="500" grow-width="400" autoGrow />
*/
@Directive({
selector: '[autoGrow]',
host: {
@linxlad
linxlad / 1-Explanations.md
Created June 12, 2016 22:43 — forked from danvbe/1-Explanations.md
A way to integrate FosUserBundle and HWIOAuthBundle

I have managed to install this… and make it work. I implemented it for Facebook and Google, but you can extend it. My solution it is mostly as described in #116, with a bit of more code presented. The key aspects that lack in the #116 presentation (IMO) are:

  • the registration as service of your custom FOSUBUserProvider (with the necessary parameters)
  • set the service for oauth_user_provider in the security.yml with your custom created service

Here are the steps:

  1. Routing. In routing.yml I have added all the routes for both bundles.
  2. Configuration. I have set the config.yml mostly as it is presented in the HWIOAuthBundle.
  3. Security. I have set the security.yml mostly as it is presented in the HWIOAuthBundle (though my routes are using /login pattern, not /connect). Also, the oauth_user_provider is set for my custom service.
@linxlad
linxlad / c-sharp-pattern-matching.cs
Last active June 6, 2016 15:27
Game logic with C# 7.0 and pattern matching.
/**
* In functional programming, data types do not include operations. Instead, each function implements a single operation
* for all the data types. This makes it much easier to add a new operation (just define and implement a new function),
* but much more difficult to add a new data type (modify all existing functions accordingly). While this is already
* possible in C#, it is much more verbose than it could be.
*/
interface IEnemy
{
int Health { get; set; }
@linxlad
linxlad / camelCaseToUnderscore.php
Last active May 19, 2016 12:50
CamelCase to underscore with number support.
<?php
/**
* @param $input
* @param bool $lowercase
* @param int $numbers 0 = No numbers, 1 = Numbers and 2 = Number with underscores
*
* @return mixed
*/
function camelCaseToUnderscore(
@linxlad
linxlad / recursiveArraySearch.php
Created May 17, 2016 15:48
Recursively search an array and return the values for a given key.
<?php
/**
* @param $needle
* @param $haystack
*
* @return array
*/
public function recursiveArraySearch($needle, $haystack)
{