Skip to content

Instantly share code, notes, and snippets.

View thewinterwind's full-sized avatar

Anthony Vipond thewinterwind

View GitHub Profile
@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 / 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 / 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 / Stock.php
Created June 23, 2014 11:02
Entire Stock class for tutorial on using PHP with the Yahoo Finance API
<?php namespace SS\Stock;
use DB, File, Cache, Input, Response;
class Stock {
public function __construct()
{
ini_set("memory_limit", "-1");
set_time_limit(0);
@thewinterwind
thewinterwind / php-yahoo-finance.php
Created June 21, 2014 14:38
Lesson 8 - PHP & Yahoo Finance API
<?php namespace SS\Stock;
use DB, File, Cache;
class Stock {
public function __construct()
{
ini_set("memory_limit", "-1");
set_time_limit(0);
@thewinterwind
thewinterwind / StoringController.php
Last active June 13, 2016 13:56
Code to count streaks in PHP (used with Yahoo API tutorial)
<?php
class StoringController extends BaseController {
public function store_streaks()
{
$date = date('Y-m-d');
$stocks = DB::table('stocks')->select('symbol')->orderBy('symbol', 'asc')->get();
@thewinterwind
thewinterwind / validate_url.js
Created October 17, 2013 07:12
Validating a URL with Javascript
// I didn't write this function, only modified it slightly. It works well though!
function valid_url(str) {
var pattern = new RegExp('^(https?:\\/\\/)?'+ // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|'+ // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))'+ // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*'+ // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?'+ // query string
'(\\#[-a-z\\d_]*)?$','i'); // fragment locator