Skip to content

Instantly share code, notes, and snippets.

View boutell's full-sized avatar

Tom Boutell boutell

View GitHub Profile
// Why does this print 'Redirecting' but then send 'You are special' anyway?
function secure(req, res, next) {
if (!req.user) {
console.log('Redirecting');
req.session.afterLogin = req.url;
res.redirect('/login');
return;
}
else
{
@boutell
boutell / checkhyperthreads.php
Created October 4, 2012 14:12
Check distribution of fastcgi processes over the hyperthreads and cores of your server
<?php
// Are your fastcgi processes spread out evenly over the available hyperthreads on your server?
// This script will tell you.
//
// If your php-cgi process is not /usr/local/bin/php-cgi, tweak accordingly.
//
// In my experience they do tend to distribute pretty well over time, but see also
// assignhyperthreads.php.
//
@boutell
boutell / assignhyperthreads.php
Created October 4, 2012 14:31
Spread out your fastcgi processes among the hyperthreads and cores of your CPU
<?php
// This script will spread out your php-cgi fastcgi processes
// evenly over the hyperthreads of your server.
// If your php-cgi process is not /usr/local/bin/php-cgi,
// tweak accordingly.
//
// [email protected], @boutell, punkave.com
@boutell
boutell / loadwatch.php
Created October 15, 2012 22:22
CPU load watcher: sends email when the load average changes by at least one full point
<?php
// Install me via cron:
// [email protected]
// * * * * * /usr/local/bin/php /home/someaccount/loadwatch.php
$fields = explode(' ', file_get_contents('/proc/loadavg'));
$avg = $fields[0];
$last = @file_get_contents("/home/gps/cpulast.txt");
@boutell
boutell / gist:3941578
Created October 23, 2012 21:10
Display a Google map with markers linking to pages
// Display a map with markers that link to other pages. Each marker must
// have latitude, longitude and slug properties. There must also be a
// a 'url' option which is used to build the links. The following
// wildcards are replaced in the url: ID (with the id), SLUG (with the
// slug property), PUBLISHED (with /year/month/day taken from published_at),
// and START (with /year/month/day taken from start_date). In other words,
// you can pass most array-hydrated Doctrine objects, including Apostrophe
// blog posts and events, and easily generate links back to them.
// The hover text title of the marker is taken from title if present,
PunkAve\GPS\SchoolBundle\Entity\School:
constraints:
- \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: psp_id
- \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity: name
@boutell
boutell / gist:4125045
Created November 21, 2012 14:16
Scaled up my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Use new password format for compatibility with newer PHP
old_passwords=0
# Disabling symbolic-links is recommended to prevent assorted security risks;
# to do so, uncomment this line:
# symbolic-links=0
@boutell
boutell / gist:4143757
Created November 25, 2012 14:34
Update to Symfony 1.4.20
svn up && ./symfony apostrophe:deploy staging staging && ./symfony apostrophe:deploy production prod
@boutell
boutell / gist:4225851
Created December 6, 2012 16:36
Import series for testing
./symfony scrape-legacy-site --series-only && ./symfony create-entities --import-posts
// Render a view specific to this module
function render(res, template, info) {
return res.render(__dirname + '/views/' + template, info);
}