Skip to content

Instantly share code, notes, and snippets.

@Tocacar
Tocacar / gist:2930939
Created June 14, 2012 15:20
refactored validate
public function validate(array $requiredParams)
{
$properties = get_object_vars($this);
foreach ($properties as $property => $propValue) {
if (array_key_exists($property, $requiredParams) && empty($propValue)) {
return false;
}
}
return true;
}
@Tocacar
Tocacar / gist:2960231
Created June 20, 2012 14:45
Query idea
public function getCages($query, cageQueryParams $params)
{
$q = $this->createQuery('c')
->leftJoin('c.Strain s')
->leftJoin('c.MouseCage m')
->where('m.dateout IS NULL');
if($params->strainid) {
$q->addWhere('c.strain_id = ?', $params->strainid);
@Tocacar
Tocacar / gist:2995768
Created June 26, 2012 13:26
Moving mouse
/**
* Completes process of moving of mouse to selected cage
*
* @param sfWebRequest $request
* @return json-encoded template
*/
public function executeDoMove(sfWebRequest $request)
{
$this->checkRequest($request);
$this->form = new MouseCageDateInForm();
@Tocacar
Tocacar / gist:3033105
Created July 2, 2012 12:47
zf2 tutorial vhost
<VirtualHost *:80>
ServerName zf2-tutorial.localhost
DocumentRoot /Users/rowan02/Sites/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory "/Users/rowan02/Sites/zf2-tutorial/public">
Options Indexes FollowSymLinks
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
@Tocacar
Tocacar / gist:3060077
Created July 6, 2012 13:10
looping an object collection
$results = $this->query->execute();
$userIdArray = array(1, 4, 7, 9);
if ($results->count() > 0) {
$users = array();
foreach ($results as $result) {
@Tocacar
Tocacar / gist:3061034
Created July 6, 2012 15:56
Why mentoring?
Why Mentoring?
Why bother? What are the personal reasons to make mentorship something you get involved with? Just what is a role model anyway? Well, generally speaking, a role model is a "person who serves as an example, whose behaviour is emulated by others.“ For reasons to bother and to discover what you could get out of it, keep reading...
Mentees:
It can really help you get where you want to be in your career if you have the opportunity to see someone who is where you want to be (maybe Bill Gates, Rasmus, ADD A WOMAN HERE?). The following are some of the benefits you can expect to gain from a good mentor relationship:
Information: Mentors can help you learn complex tools or processes, review your work, and avoid or resolve problems.
Advice: Mentors can share insights you didn’t even know you needed. Mentors can also help you understand your hidden strengths and weaknesses.
<?php
/**
* Write a function that generates a
* random 5 star rating as a decimal
* number and outputs the following
* strings (in place of star images)
*
* 'Full Star',
* 'Partial Star',
@Tocacar
Tocacar / gist:3182576
Last active October 7, 2015 14:57
FizzBuzz
<?php
for ($i = 1; $i < 100; $i++) {
if ($i % 3 == 0) {
echo 'Fizz';
} elseif ($i % 5 == 0) {
echo 'Buzz';
} else {
echo $i;
@Tocacar
Tocacar / gist:3369752
Created August 16, 2012 12:18
Sample blog schema
SET SESSION storage_engine = "InnoDB";
ALTER DATABASE CHARACTER SET "utf8";
DROP TABLE IF EXISTS post;
CREATE TABLE post (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
author_id INT NOT NULL REFERENCES author(id),
slug VARCHAR(100) NOT NULL UNIQUE,
title VARCHAR(400) NOT NULL,
content MEDIUMTEXT NOT NULL,
SET SESSION storage_engine = "InnoDB";
DROP DATABASE IF EXISTS demo_blog;
CREATE DATABASE demo_blog;
USE demo_blog;
ALTER DATABASE demo_blog CHARACTER SET "utf8";
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES, CREATE TEMPORARY TABLES ON `blog_demo`.* TO 'Tester'@'localhost' IDENTIFIED BY 'queries';