Skip to content

Instantly share code, notes, and snippets.

View thewinterwind's full-sized avatar

Anthony Vipond thewinterwind

View GitHub Profile
@thewinterwind
thewinterwind / get_url_path_segment.js
Last active December 27, 2015 23:58
Get URL path segments easily with JS
/**
* Return a url segment
* @param {Integer} url segment wanted
* @return {String} URL segment
*/
function get_path_segment(num) {
return location.pathname.split("/")[num].toLowerCase();
}
@thewinterwind
thewinterwind / index.php
Last active January 3, 2016 11:08
Interview test answer - January 15, 2014
<?php
// Email a URL to colleague so he can visit the Admin sessions page
// Current page: /admin/sessions (GET route)
$type = 'type';
$start_date = '2012-01-01';
$end_date = '2012-03-01';
$session_id = '123456';
$url = 'http://domain.com/admin/sessions?type=' . urlencode($type);
$url .= '&start_date=' . urlencode($start_date);
@thewinterwind
thewinterwind / explanation.text
Created January 19, 2014 21:44
How to ignore app/config/database.php in Laravel 4
Add /app/config/database.php into the project folder .gitignore
Then remove it from the staging area cache with:
git rm --cached app/config/database.php
@thewinterwind
thewinterwind / phpunit.xml
Created January 28, 2014 05:14
Add colors to output for PHPUnit
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"
processIsolation="true"
verbose="true"
debug="true">
</phpunit>
@thewinterwind
thewinterwind / checktablesize.sql
Created February 3, 2014 18:42
How to check a table size in MySQL
SELECT table_name AS "Table",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "$DB_NAME"
AND table_name = "$TABLE_NAME";
@thewinterwind
thewinterwind / database_details.sql
Created February 3, 2014 20:19
View details on MySQL tables
SELECT count(*) tables,
concat(round(sum(table_rows)/1000000,2),'M') rows,
concat(round(sum(data_length)/(1024*1024*1024),2),'G') data,
concat(round(sum(index_length)/(1024*1024*1024),2),'G') idx,
concat(round(sum(data_length+index_length)/(1024*1024*1024),2),'G') total_size,
round(sum(index_length)/sum(data_length),2) idxfrac
FROM information_schema.TABLES;
+--------+----------+---------+--------+------------+---------+
| tables | rows | data | idx | total_size | idxfrac |
+--------+----------+---------+--------+------------+---------+
@thewinterwind
thewinterwind / read_from_x_to_end.php
Created February 9, 2014 04:11
Read from a specific line to end of file using PHP
<?php
$log_file = 'lines.log';
$read_start_position = 50;
$file = new SplFileObject($log_file);
$file->seek($read_start_position);
while(!$file->eof()) {
@thewinterwind
thewinterwind / gzip-ajax-response.php
Last active July 26, 2019 09:50
How to gzip AJAX response with PHP (Laravel 4 flavor)
<?php
public function all()
{
if (Request::ajax()) {
$encoded_html = gzencode(Model::all(), 9);
header('Content-Length: ' . strlen($encoded_html));
header('Content-Encoding: gzip');
return $encoded_html;
}
@thewinterwind
thewinterwind / datatables.php
Created March 25, 2014 14:29
Datatables class for Laravel 4
<?php
namespace Leads\Libraries;
class Datatables {
public static function ajax($table, Array $columns)
{
/*
* Script: DataTables server-side script for PHP and MySQL
@thewinterwind
thewinterwind / view_globals.php
Last active August 29, 2015 13:57
View PHP server-related global variables from command line or browser
<?php
/**
* Author: Anthony Vipond
* Tested on: PHP 5.5
*/
$global_indexes = ['SERVER', 'ENV', 'SESSION', 'REQUEST', 'COOKIE', 'GET', 'POST', 'FILES'];
if (php_sapi_name() !== 'cli') {