Skip to content

Instantly share code, notes, and snippets.

View jmikola's full-sized avatar
💭
🌭

Jeremy Mikola jmikola

💭
🌭
View GitHub Profile
@jmikola
jmikola / symfony2_forms_validation_groups.php
Created June 11, 2010 20:23
Using grouped constraints with Symfony 2 Forms
<?php
/* Since the group name is specified, "Default" will be assigned automatically and
* the implicity group name "Registration" (based on containing class' name) will
* also not be assigned.
*/
class Registration
{
public $field;
@jmikola
jmikola / DoctrineOdmUnique.php
Created June 14, 2010 22:28
DoctrineOdmUnique Constraint for Symfony 2 Forms
<?php
namespace Application\Validator\Constraints;
use Symfony\Components\Validator\Constraint;
class DoctrineOdmUnique extends Constraint
{
public $message = 'OpenSky.Validator.DoctrineOdmUnique.message';
public $documentManager;
@jmikola
jmikola / ProjectConfiguration.class.php
Created June 23, 2010 04:49
Symfony 1.4 ProjectConfiguration for ServerGrove with local vendor/symfony fallback
<?php
/**
* ServerGrove's shared Symfony libraries are not accessible within chrooted
* sessions on shared hosting, which means the symfony console command is
* unusable. The following conditional will allow you to fall back to a
* local copy of Symfony in your project's vendor directory and still make
* use of ServerGrove's up-to-date libraries elsewhere.
*
* Note: you likely won't have access to Doctrine or Propel commands, since
@jmikola
jmikola / fitzify.php
Created July 28, 2010 22:36
Add a random number of tabs to random lines in a string
<?php
function fitzify ($input) {
return implode(\PHP_EOL, array_map(function($line) {
return $line . (rand(1, 4) == 1 ? str_repeat("\t", rand(1, 4)) : '');
}, explode(\PHP_EOL, $input)));
}
$a = file_get_contents(__FILE__);
echo fitzify($a);
@jmikola
jmikola / mongo_normalize_address_countries.js
Created August 27, 2010 19:22
Normalize address countries to uppercase
var cols = ['customers', 'sellers', 'suppliers'];
for (j in cols) {
db[cols[j]].find({'addresses.country':/[a-z]/}).forEach(function(d){
for (i in d.addresses) {
d.addresses[i].country = d.addresses[i].country.toUpperCase();
}
db[cols[j]].save(d);
});
}
@jmikola
jmikola / symfony_configs.md
Created September 2, 2010 21:26
Suggestions for organizing Symfony2 app configs

Some rules

Configs exist in three levels:

  1. local
  2. dev | stg | prod
  3. default (no environment)

There are three types of configs:

@jmikola
jmikola / SecurityListener.php
Created September 13, 2010 16:24
Symfony2 security request listener using HTTP authentication and LDAP groups
<?php
namespace OpenSky\AdminBundle\Listener;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpKernel\Log\LoggerInterface;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
/**
@jmikola
jmikola / Nginx Conf
Created September 19, 2010 20:45 — forked from jself/Nginx Conf
jself's nginx config
# You may add here your
# server {
# ...
# }
# statements for each of your virtual hosts
server {
listen 80 default;
server_name domain.com;
@jmikola
jmikola / Document.PasswordContainer.dcm.yml
Created November 3, 2010 14:42
Password hashing in a Doctrine2 ODM model class
Document\PasswordContainer:
type: document
collection: password_container
fields:
password:
type: string
salt:
type: string
algorithm:
type: string
@jmikola
jmikola / symfony_dev.log
Created November 11, 2010 17:10
Log of #symfony-dev meeting 20101111 (all times GMT-5)
Nov 11 11:00:10 <lsmith> ok lets start ..
Nov 11 11:00:33 <lsmith> so i am quite thrilled to see so many people here .. and also that fabpot managed to come after all
Nov 11 11:01:13 <lsmith> i think we do not need to ask for permission to speak, but try to make sure that stuff that is said is well thought out .. and rather take it slower than faster
Nov 11 11:01:34 <lsmith> also i think when we start on a topic, it would be good for the person who proposed the topic to briefly introduce the topic
Nov 11 11:01:52 * nicobn ([email protected]) has joined #symfony-dev
Nov 11 11:02:07 <lsmith> also when saying something for the first time with a nickname that isnt obvious as to what the name that is used on the mailinglist, one should mention the name the first time speaking
Nov 11 11:02:24 <lsmith> ok .. so the first topic today is this IRC meeting process
Nov 11 11:02:34 <lsmith> i proposed that one .. my name is Lukas Smith btw :)
Nov 11 11:02:53 <lsmith> i came up with this IRC meeting idea, since t