Skip to content

Instantly share code, notes, and snippets.

View thewinterwind's full-sized avatar

Anthony Vipond thewinterwind

View GitHub Profile
0xC27CF0B05c7468764e9f57e84B881821D145CE0d
@thewinterwind
thewinterwind / repo-proposal.md
Last active June 27, 2017 19:42
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.

Benefits

  • 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
thewinterwind / disable_multiple_tabs.js
Created April 29, 2017 03:49
Detect website being accessed in a new tab
<script>
// 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
thewinterwind / demo.php
Created December 1, 2014 10:01
Get next id in table using Laravel
<?php
// select min(id) as id from `property` where `id` > 1;
DB::table($table)->select(DB::raw('min(id) as id'))->where('id', '>', $id)->id;
@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 / insert_many_rows.php
Last active December 12, 2016 13:59
How to insert millions of rows to the database with PHP (YT Tutorial)
<?php
class Stock {
public function store_stock_history()
{
$date = date('Y-m-d');
$files = File::files(app_path() . '/resources/historical_lists/' . $date);
@thewinterwind
thewinterwind / art.php
Last active August 29, 2015 14:02
Artisan Files for Streak Counting Tutorial (2 files combined here)
// this is /app/start/artisan.php
<?php
/*
|--------------------------------------------------------------------------
| Register The Artisan Commands
|--------------------------------------------------------------------------
|
| Each available Artisan command must be registered with the console so
@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();
<?php
use Leads\Repos\LeadRepoInterface;
use Illuminate\Foundation\Application;
class ExchangeController extends BaseController {
private $lead;
private $app;