Skip to content

Instantly share code, notes, and snippets.

View mattkirwan's full-sized avatar

Matt Kirwan mattkirwan

View GitHub Profile
@mattkirwan
mattkirwan / AvailableTask_MattKirwan
Created December 5, 2012 21:45
AvailableTask value attribute - possible type inconsistencies
<?xml version="1.0" encoding="UTF-8"?>
<project name="test" default="test">
<property name="dir" value="../test_directory" />
<target name="test">
<echo message="Test 1:" />
<echo message="--------------------" />
@mattkirwan
mattkirwan / ServiceProviderDB.php
Created December 12, 2012 14:51
ServiceProvider DB
<?php
// Service Provider
$app->register(new Via\Content\ContentServiceProvider());
// Route
$app->get('/{id}', function(Doctrine\DBAL\Connection $db) use ($app) {
return $app['content.id_checker']($db);
});
// and in .... ContentServiceProvider
@mattkirwan
mattkirwan / CSV_Ripper.php
Created January 11, 2013 20:29
This gist uses PHP's built in SplFileObject class to loop through .csv file and pretty much do what you want with each row of data. Probably one of my most used snippets of code.
<?php
$file = 'data.csv';
try {
$csv = new SplFileObject($file, 'r');
} catch (RuntimeException $e) {
printf("Error opening .csv: %s\n", $e->getMessage());
}
@mattkirwan
mattkirwan / flattenArray.php
Created January 29, 2013 19:20
Uses PHP's built in SPL Array Iterators to quickly spin through a multidimensional array and return a 'flattened' output.
<?php
function flattenArray( array $array )
{
$returned_array = array();
foreach( new \RecursiveIteratorIterator( new \RecursiveArrayIterator($array) ) as $key => $value )
{
$returned_array[] = $value;
}
@mattkirwan
mattkirwan / create-a-slug.php
Last active December 16, 2015 09:38
A quick function to create a url 'slug' from a given string.
<?php
function convertToSlug($input)
{
$text = preg_replace('~[^\\pL\d]+~u', '-', $input);
$text = trim($text, '-');
$text = strtolower($text);
$text = preg_replace('~[^-\w]+~', '', $text);
return $text;
}
@mattkirwan
mattkirwan / bootstrap.sh
Created June 6, 2013 18:43
Vagrant bootstrap
#!/bin/bash
# Update packages
yum update
# Add some repos
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
# Install MySQL
Starting php-fpm:
[06-Jun-2013 18:38:32] NOTICE: PHP message: PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/memcached.so' - /usr/lib64/php/modules/memcached.so: cannot open shared object file: No such file or directory in Unknown on line 0
[ OK ]
@mattkirwan
mattkirwan / Quick Project
Created November 16, 2013 00:13
A nice simple shell script for create a quick framework based project. Currently only supports Laravel, but will adapt with Silex another time
#!/bin/bash
function install_laravel() {
echo "Installing Laravel into '$project_name'..."
wget https://github.com/laravel/laravel/archive/master.zip ./
unzip ./master.zip
@mattkirwan
mattkirwan / generateChoice.php
Last active December 29, 2015 03:09
Nice little snippet to generate a customisable 'choice' array (up to 5 elements can be displayed) from an array of items - perfect for drop downs/checkboxes and such.
<?php
/***********************************************
Raw Data:
@$raw_data
Array
(
[0] => Array
@mattkirwan
mattkirwan / gist:2588935da356fe81cad1
Last active August 29, 2015 14:13
Problems you know you've solved but can't remember the solution....
Q: Having problems with [usemin, grunt, useminprepare] not correctly renaming hook blocks in a [html, twig] template?
A: Check the motherfucking line endings of that file and ensure they are 'Unix'.
Q: Running a cron job and the script isn't firing?
A: Don't forget to check the PATH variable is imported at the top of the .sh file
Q: Having problems updating ModX directories (eg: core) and the /setup/ upgrade not working?
A: Make sure you replace the files/directories with the cp -R command and not Finder. Because Finder merge is weird and shit.