Skip to content

Instantly share code, notes, and snippets.

@webmozart
webmozart / array-validation-error-mapping.php
Last active November 9, 2024 19:58
A little experiment: Validating (potentially multi-leveled) arrays with the Symfony2 Validator component and returning the errors in the same data structure as the validated array by using the Symfony2 PropertyAccess component.
<?php
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\Validator\Constraints\All;
use Symfony\Component\Validator\Constraints\Choice;
use Symfony\Component\Validator\Constraints\Collection;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Optional;
use Symfony\Component\Validator\Constraints\Required;
@danvbe
danvbe / 1-Explanations.md
Last active November 14, 2024 02:13
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.
@mystix
mystix / setup-php-dev.sh
Last active April 27, 2023 15:46
(OSX 10.7.x/10.8.x + Homebrew + nginx + mysql + php 5.4 + php-fpm + apc + xdebug) development environment
#!/bin/bash
# install homebrew's official php tap
brew tap josegonzalez/homebrew-php
# install homebrew-dupes (required to install zlib, php54's dependency)
brew tap homebrew/dupes
# install nginx + mysql + php 5.4 + php-fpm + apc + xdebug
brew install nginx mysql
@johnagan
johnagan / githook.sh
Created May 22, 2011 22:55
A sample git hook to update webroot on commit
# Bring in Source Control
mkdir ~/repo
cd ~/repo
git init --bare
# Create a git hook
cat > hooks/post-receive
#!/bin/sh
GIT_WORK_TREE=/home/ubuntu/www
@jacklynrose
jacklynrose / post-receieve
Created April 19, 2011 08:17
post-receive git hook to pull changes to your source folder
#!/bin/sh
cd ~user/ProjectRepo
env -i git pull
@kayue
kayue / get_trimmed_excerpt.php
Created January 10, 2011 04:18
Get trimmed excerpt (by word) in WordPress
<?php
function get_trimmed_excerpt($maxChars = 160, $appendingString = '...', $default_excerpt = "Default page description.")
{
if( !is_single() && !is_page() )
return $default_excerpt;
the_post();
$content = substr(get_the_excerpt(), 0, $maxChars);
$content = strip_tags($content);
@kayue
kayue / get_the_relative_time.php
Created January 10, 2011 04:13
Get relative time in WordPress
<?php
// This function will return "now", "3 seconds ago", "1 month ago" etc ...
function get_the_relative_time($time = null)
{
if(is_null($time)) $time = get_the_time("U");
$time_diff = date("U") - $time; // difference in second
$second = 1;
$minute = 60;
// ----------------------------------------------------------
// A short snippet for detecting versions of IE in JavaScript
// without resorting to user-agent sniffing
// ----------------------------------------------------------
// If you're not in IE (or IE version is less than 5) then:
// ie === undefined
// If you're in IE (>=5) then you can determine which version:
// ie === 7; // IE7
// Thus, to detect IE:
// if (ie) {}
(function($) {
$.fn.oembed = function(url, options, callback) {
options = $.extend(true, $.fn.oembed.defaults, options);
return this.each(function() {
var container = $(this),
resourceURL = (url != null) ? url : container.attr("href"),
provider;
@paulirish
paulirish / README.md
Created January 4, 2010 02:38
imagesLoaded() jquery plugin