Skip to content

Instantly share code, notes, and snippets.

Taking new clients now

Anthony Vipond thewinterwind

Taking new clients now
View GitHub Profile
thewinterwind / gzip-ajax-response.php
Last active Jul 26, 2019
How to gzip AJAX response with PHP (Laravel 4 flavor)
View gzip-ajax-response.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 / disable_multiple_tabs.js
Created Apr 29, 2017
Detect website being accessed in a new tab
View disable_multiple_tabs.js
// helper function to set cookies
function setCookie(cname, cvalue, seconds) {
var d = new Date();
d.setTime(d.getTime() + (seconds * 1000));
var expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
// helper function to get a cookie
thewinterwind /
Last active Jun 27, 2017
Proposal for service platform and repository pattern

Service Platform w/ Repository Pattern Proposal

This document will outline a proposal for a service platform (API) and a repository pattern as a business layer for IC.


  • Have a data layer that is independent of models and controllers.
  • Have repo methods that can be consumed from other parts of the web application and from the command line.
  • Reduce logic in controllers and models, allowing controllers to focus on HTTP level work (request data, cookies, responses) and models to focus on creating relationships, casting columns, mutators, etc. The controllers should instead delegate work to the repos.
  • Repository methods can be reused by different parts of the web application and to perform work for an API request coming from outside (i.e. if we use a mobile platform like React Native it can call the API endpoints which in turn consume the repositories)
  • Have repo methods be easily unit tested as they will not be accessing session data, request data or external constants. They only
thewinterwind / insert_many_rows.php
Last active Dec 12, 2016
How to insert millions of rows to the database with PHP (YT Tutorial)
View insert_many_rows.php
class Stock {
public function store_stock_history()
$date = date('Y-m-d');
$files = File::files(app_path() . '/resources/historical_lists/' . $date);
thewinterwind / validate_url.js
Created Oct 17, 2013
Validating a URL with Javascript
View validate_url.js
// 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
thewinterwind / StoringController.php
Last active Jun 13, 2016
Code to count streaks in PHP (used with Yahoo API tutorial)
View StoringController.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 / php-yahoo-finance.php
Created Jun 21, 2014
Lesson 8 - PHP & Yahoo Finance API
View php-yahoo-finance.php
<?php namespace SS\Stock;
use DB, File, Cache;
class Stock {
public function __construct()
ini_set("memory_limit", "-1");
thewinterwind / Stock.php
Created Jun 23, 2014
Entire Stock class for tutorial on using PHP with the Yahoo Finance API
View Stock.php
<?php namespace SS\Stock;
use DB, File, Cache, Input, Response;
class Stock {
public function __construct()
ini_set("memory_limit", "-1");
thewinterwind / phpunit.xml
Created Jan 28, 2014
Add colors to output for PHPUnit
View phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true"