Let’s Encrypt

Generating a certificate:

# Point to the letsencrypt directory
$ cd /root/letsencrypt;
$ ./letsencrypt-auto certonly --standalone --email developer@example.com -d example.com -d www.example.com

Docker – Modify files in a running container

Here is a solution to use a fully functioning text editor within a docker container when ssh’d into a remote linux host.

# Log on to your container
docker exec -it grave_ride /bin/bash

# Run this command to fix the terminal
export TERM=xterm

# Continue to open and edit your file in your faviourite text editor.
nano my-file.js

Symfony form querybuilder with parameters

->add( 'weeks', 'entity', array(
    'class' => 'MV\CaravanBundle\Entity\CaravanRow',
    'property' => 'line',
    'query_builder' => function(EntityRepository $er ) use ( $caravan ) {
        return $er->createQueryBuilder('w')
                  ->orderBy('w.dateFrom', 'ASC')
                  ->where('w.caravan = ?1')
                  ->andWhere('w.visible = 1')
                  ->andWhere('w.booked = 0')
                  ->setParameter(1, $caravan);
}

Source: http://stackoverflow.com/a/13847387

Fix timezone settings for PHP on Mac OSX El Capitan for Symfony

Symfony requires you to specify a date.timezone in the ini file. The problem is, Mac uses it’s own install of PHP, and you need to create directory structure it searches for the ini file… and a php.ini file. Here’s how you do it.

1. Open terminal
2. nano /Library/Server/Web/Config/php/php.ini
3. add line date.timezone = “Europe/London” (Other timezones)
4. Save & exit.

The original error:

[Symfony\Component\Debug\Exception\ContextErrorException]                                                                                                                                                                                                                                                                                                                                                                         
Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.  

Cron Job over SSL (wget & curl)

WGET

With wget, you must add the argument –no-check-certificate.
Hitting a PHP script every 15 minutes over SSL:

*/15 * * * * /usr/bin/wget -q -O /dev/null --no-check-certificate https://example.com/script.php

CURL

I haven’t tested the curl example, it was referenced from: http://serverfault.com/questions/476141/cron-jobs-no-longer-work-since-installing-ssl-cert-on-rackspace-cloud-server

For curl, you add -k:

*/15 * * * * /usr/bin/curl -k https://example.com/script.php

Symfony2 Entity Timestamps With Doctrine

1. Add line to entity annotation:

@ORM\HasLifecycleCallbacks

2. Add new columns for created and modified:

/**
* @ORM\Column(type="datetime")
*/
protected $created_at;

/**
* @ORM\Column(type="datetime")
*/
protected $modified_at;

3. Now tell doctrine that before persisting or updating, call updatedTimestamps()

/**
* @ORM\PrePersist
* @ORM\PreUpdate
*/
public function updatedTimestamps()
{
    $this->setModifiedAt(new \DateTime(date('Y-m-d H:i:s')));

    if($this->getCreatedAt() == null)
    {
        $this->setCreatedAt(new \DateTime(date('Y-m-d H:i:s')));
    }
}

http://www.jamesmandrews.com/2012/10/31/symfony-2-entity-timestamps-with-doctrine/

Add Media plugin in PhoneGap CLI 5.0.0 (Android)

Firstly, open terminal and globally install the latest cordova (if it isn’t already global):

$ sudo npm install -g cordova

Then open your phonegap project root in terminal and run the following to add the plugin:

$ cordova plugin add org.apache.cordova.media

Once this has successfully been added, open config.xml and add the following entry:

<feature name="Media">
     <param name="android-package" value="org.apache.cordova.media.AudioHandler" />
</feature>

I guess you just have to add config entries for another platforms.

Hundreds of Thousands of Particles at 60 fps

Recently been getting to grips with Cinder, OpenGL and GLSL for a project. I managed to get close to a million particles drawing at around 60fps 

Here’s what I did to achieve this:

Firstly I created a VBO mesh that contained randomly positioned vertices (each vertex represented a root particle position).

Using VBO meshes mean you don’t have to upload the geometry before every draw call- it  gets uploaded to the GPU once, then you can transform and draw the referenced mesh in your render loop.

Once i had the VBO mesh, I created vertex and fragment shaders that accept GL_POINTS as the input and output types. This means the vertex shader is expecting a bunch of vertices and the fragment shader is expecting to draw a single points to the screen.

The clever thing is, you can flick a switch in OpenGL to enable point sprites, this means you can tell the fragment shader to draw a texture at the point instead.

You can also tell the vertex shader what size each point sprite should be rendered at based on its distance from the camera

Using point sprites is fast, because there are no triangles or textures that need mapping to them- the fragment shader just renders the texture at a given screen position and at the size you have specified.

FAST FAST FAST!!!!!