Skip to content

Instantly share code, notes, and snippets.

View henrikbjorn's full-sized avatar

Henrik Hauge Bjørnskov henrikbjorn

View GitHub Profile
<?php
class QuizzesController extends AppController
{
var $helpers = array('Form');
public function index() {
$this->set('description', 'Et xml/flash quiz værktøj');
}
public function save($id = 1) {
$this->Quiz->saveAll($this->data['Quiz'], array('validate' => 'first'));
$quizId = $this->Quiz->id;
foreach($this->data['QuizQuestion'] as $data){
$data['quiz_id'] = $quizId;
$this->Quiz->QuizQuestion->saveAll($data, array('validate' => 'first'));
}
<?php
class DownloaderComponent extends Object
{
public function sendFileHeaders($path)
{
$handle = finfo_open(FILEINFO_MIME_TYPE);
$contentType = finfo_file($handle, $path);
$extension = path_info($path, PATHINFO_EXTENSION); //Better way to get the extension
header("Pragma: public");
<?php
function checkEmail($email) {
// checks proper syntax
if(preg_match("/^([a-z])([a-z0-9._])+([a-z0-9])\@([a-z0-9])*([a-z])+(-[a-z])*([a-z0-9])*(\.([a-z0-9])*([a-z])+(-[a-z])*([a-z0-9])*)+$/i" , $email)) {
// gets domain name
list($username, $domain) = split('@', $email);
// checks for if MX records in the DNS
if(checkdnsrr($domain, 'MX')) {
<?php
namespace Symfony\Bundle\FrameworkBundle\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Output\Output;
use Symfony\Bundle\FrameworkBundle\Util\Filesystem;
@henrikbjorn
henrikbjorn / php.rb
Created January 12, 2011 21:45 — forked from cranberyxl/php.rb
require 'formula'
def mysql_installed?
`which mysql_config`.length > 0
end
class Php <Formula
url 'http://www.php.net/get/php-5.3.5.tar.gz/from/this/mirror'
homepage 'http://php.net/'
md5 'fb727a3ac72bf0ce37e1a20468a7bb81'
security:
acl: ~
access_control:
- { path: /admin/.*, roles: [ROLE_ADMIN] }
- { path: /.*, roles: [IS_AUTHENTICATED_ANONYMOUSLY, ROLE_USER] }
encoders:
admin: { algorithm: sha1, class: Sas\CoreBundle\Entity\Account }
providers:
fos_user:
id: fos_user.user_manager
@henrikbjorn
henrikbjorn / ActiveEntity.php
Created August 16, 2011 08:46 — forked from beberlei/ActiveEntity.php
Doctrine 2.2 Traits Preview
<?php
use Doctrine\ORM\EntityManager,
Doctrine\ORM\Configuration,
Doctrine\ORM\Mapping\ClassMetadata;
/**
* Active Entity trait
*
* Limitations: a class can only ever be assocaited with ONE active entity manager. Multiple entity managers
@henrikbjorn
henrikbjorn / BukkitVote oversættelse
Created October 11, 2011 08:03 — forked from tcarlsen/BukkitVote oversættelse
Vi skal lige have oversat BukkitVote til dansk :)
error.accept.already={{RED}}This vote has not been initialized or you already accepted it
error.accept.unknown={{RED}}There is no such vote command
error.permissions={{RED}}You do not have permissions to use this command
error.force.permissions={{RED}}You do not have the permissions to use this command. Generally it is an admin command
error.notonserver={{RED}}{{PLAYER}} is not on this server
force.success={{GREEN}} Forcing event
muted=You are muted!
mute.broadcast={{PLAYER}} has been muted
mute.notmuted={{PLAYER}} is not muted
unmute.broadcast={{PLAYER}} has been unmuted
@henrikbjorn
henrikbjorn / RelDate.php
Created December 5, 2011 08:01 — forked from arnaud-lb/RelDate.php
4 lines relative date formatter with DateInterval and Symfony2 Translator
<?php
use Symfony\Component\Translation\TranslatorInterface;
function format(\DateTime $date, TranslatorInterface $translator)
{
$diff = date_create()->diff($date);
$seconds = $diff->days * 86400 + $diff->h * 3600 + $diff->i * 60 + $diff->s;
$format = $translator->transChoice('reldate', $seconds);