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 / password-validation.js
Last active May 3, 2017 16:33
Find a matching password string then check if the password is not a duplicate and is still valid.
// Test data.
var userData = {
"password": "$2a$12$cZnjMBhqUI97xlKyizJh9uf43Kz5h0RC5wXVfy9WhTuth.mCbfzl.",
"password_history": [
{
"created": "2017-05-01T23:00:00.000Z",
"password": "password"
},
{
"created": "2017-04-25T23:00:00.000Z",
@linxlad
linxlad / QRLogo.php
Created February 28, 2017 10:31 — forked from NTICompass/QRLogo.php
QR Code + Logo Generator
<?php
/**
* QR Code + Logo Generator
*
* http://labs.nticompassinc.com
*/
$data = isset($_GET['data']) ? $_GET['data'] : 'http://labs.nticompassinc.com';
$size = isset($_GET['size']) ? $_GET['size'] : '200x200';
$logo = isset($_GET['logo']) ? $_GET['logo'] : FALSE;
@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 / 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 / ManualLogin.php
Created April 17, 2015 16:40
Custom Authentication Class with Symfony 2.6
<?php
/**
* @Author: Nathan Daly
* @Date: 17/04/15
*/
namespace AppBundle\Security;
use Doctrine\ORM\EntityManager;
use Symfony\Component\DependencyInjection\Container;
@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 / 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; }