Skip to content

Instantly share code, notes, and snippets.

View thewinterwind's full-sized avatar

Anthony Vipond thewinterwind

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / convert-span-to-input-and-back.js
Created November 9, 2013 08:40
Convert span to text input for editing, then back to span upon successful save
// Icons with edit class will convert their data partner to an input
$('i.edit').click(function() {
var table = $(this).data('table');
var column = $(this).data('column');
var relation = $(this).data('relation');
var id = $(this).data('id');
var type = $(this).data('type');
var morph = $(this).data('morph');
var original_elem = $(this).siblings('span');
var original_text = original_elem.text();
@thewinterwind
thewinterwind / queries_run.php
Created November 9, 2013 04:27
Helper function for viewing queries ran in Laravel 4
<?php
if (!function_exists('sql')) {
function sql($detailed = false) {
if ($detailed) {
Event::listen("illuminate.query", function($query, $bindings, $time, $name) {
$queries = DB::getQueryLog();
echo '<pre>';
foreach(end($queries) as $item) {
var_dump($item);
@thewinterwind
thewinterwind / update_query_string_value.html
Last active December 27, 2015 07:39
Update query string value with Javascript (author: Anthony Vipond)
<select class="filter">
<option>Results Shown</option>
<option>20</option>
<option>30</option>
<option>50</option>
<option>100</option>
</select>
<script>
// This example is for a 'Results per page' dropdown
@thewinterwind
thewinterwind / .bash_profile
Created November 1, 2013 01:40
My ~/.bash_profile on Mac OS X Mountain Lion ***CODE FAST***
alias l='ls -lah'
alias b='cd ..'
alias bb='cd ../..'
alias bbb='cd ../../..'
alias ra='sudo apachectl restart'
alias sa='sudo apachectl start'
alias ka='sudo apachectl stop'
alias a-dir='cd /etc/apache2'
alias sites='cd ~/sites'
@thewinterwind
thewinterwind / check_if_integer.js
Last active December 26, 2015 12:09
Check if a number is an integer in Javascript using jQuery (author: Anthony Vipond)
/**
* Check if a number is an integer using jQuery
* @param {Number} num
* @return {Boolean}
*/
function is_integer(num) {
return $.isNumeric(num) && !(num % 1);
}