Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Baker MarkBaker

View GitHub Profile
@MarkBaker
MarkBaker / UK Postcode Parse
Last active Aug 29, 2015
UK Postcode Parsing
View UK Postcode Parse
function parsePostcode2($postcode) {
$postcode = preg_replace('/\s*/','',strtoupper($postcode));
$sector = substr($postcode,0,-2);
$outcode = $district = substr($sector,0,-1);
list($area) = sscanf($district,'%[A-Z]');
$incode = substr($postcode,-3);
return array(
@MarkBaker
MarkBaker / gpxTracker.md
Last active Aug 29, 2015
Cat-Tracker - A PHP Generator-based Reader for reading GPX trackpoint files
View gpxTracker.md

This is a simple reader class for gpx files retrieved from the G-Paws Cat Tracker that allows you to loop over the trackpoints read from that file, returning lat/lon as attributes of a simple stdClass object as the returned "key" from the Reader, and ele/time as attributes of a simple stdClass object as the returned "value"

The Reader class

class gpxReader
{

    public function __construct($fileName)
    {
@MarkBaker
MarkBaker / Duplicate Keys in Array
Created Jul 20, 2013
Using PHP 5.5 Generators to simulate an array with duplicate keys
View Duplicate Keys in Array
function duplicateKeys($string) {
$string = strtolower($string);
$length = strlen($string);
for ($i = 0; $i < $length; ++$i) {
yield ord(strpos($string, $string[$i])) => $string[$i];
}
}
foreach (duplicateKeys('badass') as $i => $value) {
echo $i , ' -> ' , $value, PHP_EOL;
@MarkBaker
MarkBaker / PHPExcel PHPNW13 Hackathon Objectives.md
Last active Dec 22, 2015
Objectives for the PHPNW13 Hackathon
View PHPExcel PHPNW13 Hackathon Objectives.md

For the Open Source PHPExcel library (https://github.com/PHPOffice/PHPExcel):

  • Autodetect separator, enclosure and line endings for CSV Reader

    An autodetect option that will identify the separator (e.g. comma, semicolon, pipe, tab, etc), the enclosure (e.g. quote, double quote), enclosure escape character (e.g. "" or ") and line endings for csv files, and set them up for the CSV reader.

  • Helper Wizards for number format masks

View Blockchain ID
Verifying that +markbaker is my blockchain ID. https://onename.com/markbaker
@MarkBaker
MarkBaker / anonymousFactory.php
Created Jan 29, 2016
Dynamic Instantiation of a class with optional Traits
View anonymousFactory.php
<?php
class baseClass {
protected $a;
protected $b;
public function __construct($a, $b = null) {
$this->a = $a;
$this->b = $b;
}
@MarkBaker
MarkBaker / SPLHeap_Issue.md
Last active Mar 31, 2016
Iterating over an SPLHeap appears to remove entries from the heap
View SPLHeap_Issue.md

Trying a little experiment with PHP's SPLHeap, but puzzled by the fact that iterating over the heap seems to be removing each entry as I access it.

The code

class ExtendedSPLHeap extends \SPLHeap {

    protected function compare($a, $b) {
        if ($a->latitude == $b->latitude) {
            return 0;
View Laravel Controller
<?php
class evidenceController {
public function getDetails($id){
$course = Course::with(['courseType'])
->checkEstablishmentOnView()
->excludeArchived()
->findOrFail($id);
$view = View::make('courses/parts/details')
->with('course', $course);
@MarkBaker
MarkBaker / PHPExcel_Formula_Debugging.md
Last active Apr 17, 2018
PHPExcel formula debugging (prior to 1.7.9)
View PHPExcel_Formula_Debugging.md

PHPExcel formula debugging

Prior to version 1.7.9

/** Error reporting */
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
@MarkBaker
MarkBaker / PHPSpreadsheetCalculationTest.md
Last active Aug 22, 2018
The following code can be used to submit an issue with the PHPSpreadsheet calculation engine
View PHPSpreadsheetCalculationTest.md
<?php

use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;

error_reporting(E_ALL);
set_time_limit(0);

date_default_timezone_set('UTC');
You can’t perform that action at this time.