Skip to content

Instantly share code, notes, and snippets.

View peterfox's full-sized avatar

Peter Fox peterfox

View GitHub Profile
@peterfox
peterfox / mailto_url_encode.php
Last active December 18, 2015 09:49
url encoding a mail to link in PHP
<?php
$URL = "mailto:?subject=Is this a test message!";
$url_var = $URL;
//explode it and if it has a '?' it means it must have URL Parameters
if(count($mail_split = explode('?', $URL))>1)
{
//if for some reason there's more than one '?' then we'll just add the exploded parts to the second part
$mail_params = $mail_split[1];
for($i=2; $i<count($mail_split); $i++)
@peterfox
peterfox / helper.php
Last active December 18, 2015 11:19
A template of a function being applied to a CodeIgniter Helper file, the If statement checks if the function is already loaded, this is a good convention, it also means if you want to simulate a function not included in a current PHP version but is in a later one it'll be swapped in.
if ( ! function_exists('element'))
{
function element($item, $array, $default = FALSE)
{
if ( ! isset($array[$item]) OR $array[$item] == "")
{
return $default;
}
return $array[$item];
@peterfox
peterfox / CI_something.php
Last active December 18, 2015 12:29
A template for wrapping third party libraries that need to be used inside the framework but aren't compatible with the typical parameters required
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//Load this class with $this->load->library('CI_Something', $data, 'something');
require_once dir(__FILE__).'/Something/Something.php';
class CI_Something extends Something
{
public function __construct($config)
@peterfox
peterfox / CI_something.php
Last active December 18, 2015 14:09
A template for wrapping third party libraries that require multiple instances to be generated an therefore require a factory pattern
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
//Load this class with $this->load->library('CI_Something', $data, 'something');
require_once dir(__FILE__).'/Something/Something.php';
class CI_Something
{
@peterfox
peterfox / CI_attribute.php
Last active December 18, 2015 14:09
Example of the code that can be used to bring the same functionality from the Model/CI_Model of CodeIgniter to other classes that want to access CodeIgniter fields as if they were attached to the class itself
/**
* __get
*
* Allows models to access CI's loaded classes using the same
* syntax as controllers.
*
* @param string
* @access private
*/
function __get($key)
@peterfox
peterfox / CI_something.php
Last active December 18, 2015 15:39
An example of a library that uses config groups inside a CodeIgniter config file
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
*defining a config with groups should look like
*
* $config['default']['hostname'] = '127.0.0.1'
* $config['default']['port'] = '1234'
*
*the constructor should then be able to load it by either taking a group name 'default' always being the option without
@peterfox
peterfox / global.php
Created March 12, 2014 20:30
This is a simple piece of code that can be added to Laravel's global.php file to start logging to Logentries.
/*
|--------------------------------------------------------------------------
| LogEntries Error Logger
|--------------------------------------------------------------------------
|
| This adds a handler to Monolog which will send logging data to the cloud service
| log entries. Make sure there is a logentries.php in your config folder with
| an array key defined as 'token'. The format of the messages will be the same
| minus the time and date as the service itself will record that.
|
@peterfox
peterfox / gulpfile.js
Last active August 29, 2015 13:58
Syncs all files beneth a projects /public/assets folder to an S3 bucket that can then be used to back a CloudFront instance
var gulp = require('gulp'),
awspublish = require('gulp-awspublish'),
rename = require('gulp-rename');
var publisher = awspublish.create({ key: '...', secret: '...', bucket: '...' });
gulp.task('publish', function() {
gulp.src('public/assets/**')
.pipe(rename(function (path) {
path.dirname = 'assets/' + path.dirname;

Keybase proof

I hereby claim:

  • I am peterfox on github.
  • I am peterfox (https://keybase.io/peterfox) on keybase.
  • I have a public key whose fingerprint is A902 1061 A14C C4C8 54DA FAA2 A63D 4815 39E1 1F00

To claim this, I am signing this object:

### Keybase proof
I hereby claim:
* I am peterfox on github.
* I am peterfox (https://keybase.io/peterfox) on keybase.
* I have a public key whose fingerprint is B0F7 1B02 236A B65E C5F2 B732 750F 23D9 60D3 8FA6
To claim this, I am signing this object: