Skip to content

Instantly share code, notes, and snippets.

View adamtester's full-sized avatar
💻
Coding

Adam Tester adamtester

💻
Coding
View GitHub Profile
@adamtester
adamtester / laravel_compress.php
Created January 15, 2015 11:16
laravel_compress
App::after(function($request, $response)
{
// Compress output
ini_set("pcre.recursion_limit", "16777");
$buffer = $response->getContent();
$re = '%# Collapse whitespace everywhere but in blacklisted elements.
(?> # Match all whitespans other than single space.
[^\S ]\s* # Either one [\t\r\n\f\v] and zero or more ws,
| \s{2,} # or two or more consecutive-any-whitespace.
) # Note: The remaining regex consumes no text at all...
@adamtester
adamtester / ci_compress.php
Last active August 29, 2015 14:13
Compress script for CodeIgniter
function compress()
{
ini_set("pcre.recursion_limit", "16777");
$CI =& get_instance();
$CI->benchmark->mark('compression_start');
// Set output type
$CI->output->set_header('Content-type: text/html; charset=utf-8');
$buffer = $CI->output->get_output();
if (!function_exists('make_slug'))
{
function make_slug($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
@adamtester
adamtester / OutsideCI.php
Created April 8, 2014 16:00
Using CodeIgniter files outside the CI installation
<?php
ob_start();
include('index.php');
ob_end_clean();
$CI =& get_instance();
$CI->load->library('session');
echo $CI->session->userdata('name');
/*
Credit to Ben Swinburne
@adamtester
adamtester / page.html
Created May 10, 2013 08:58
Allows printing of another page without reloading or using ajax, should work in all browsers and as the frame is loaded after the W3 validator won't moan.
<div class="print_retroplan_div" id="print_retroplan_div" style="display:none;"></div>
@adamtester
adamtester / MY_Parser.php
Created May 9, 2013 08:35
Extends the CI Parser class to allow for language files to be parsed. With this instead of using <?php echo $this->lang->line('lineoftext'); ?> You can now use an underscore in your view files like so: {_lineoftext}. Enjoy cleaner view files!
<?php
/*
******************************************************************************
// Extends the CI Parser class to allow for language files to be parsed.
// With this instead of using <?php echo $this->lang->line('lineoftext'); ?>
// You can now use an underscore in your view files like so: {_lineoftext}
// Enjoy cleaner view files!
// Place this file in application/libraries/MY_Parser.php
******************************************************************************