Skip to content

Instantly share code, notes, and snippets.

View alexweissman's full-sized avatar
💭
For the glory of the swarm

Alex Weissman alexweissman

💭
For the glory of the swarm
View GitHub Profile
@alexweissman
alexweissman / Worker.php
Created November 6, 2016 20:22
Represents a Worker and various helper scope queries
<?php
namespace UserFrosting;
use Illuminate\Database\Capsule\Manager as Capsule;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* Worker Class
*
@alexweissman
alexweissman / ApiController.php
Last active September 20, 2016 16:21
Example for sorting, searching, and paginating directly in the Eloquent query builder
<?php
/**
* Returns a list of workers.
*
* Generates a list of workers, optionally paginated, sorted and/or filtered.
* This page requires authentication.
* Request type: GET
*/
public function listWorkers()
<?php
public function scopeUnionLike($query, $name, $value)
{
$columns = $this->getFillable();
if (!in_array($name, $columns)) {
throw new \PDOException("Column $name does not exist!");
}
$subQuery = $query->toSql();
@alexweissman
alexweissman / config.cfg
Created June 30, 2016 17:48
Rockbox config file
# .cfg file created by rockbox 00a3658-160517 - http://www.rockbox.org
volume: -21
idle poweroff: 1
start directory: /<microSD1>/Music/
autoresume enable: on
eq enabled: on
dircache: off
fmr: /.rockbox/fmpresets/preset01.fmr
start in screen: wps
@alexweissman
alexweissman / collection_to_csv.php
Last active June 10, 2016 00:26
Converting an Eloquent collection to CSV
<?php
use \League\Csv\Writer;
$transform = function($collection) {
$collection->transform(function ($item) {
$item['institution'] = $item['institution']['name'];
$item['status'] = $item['status']['status'];
if ($item['latest_note']){
$item['latest_note_user'] = $item['latest_note']['user']['user_name'];
@alexweissman
alexweissman / index.php
Created May 27, 2016 22:03
Tryina use Schema
<?php
use Illuminate\Database\Schema\Blueprint;
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
global $app;
$app->get('/install', function (Request $request, Response $response, $args) {
@alexweissman
alexweissman / CheckEnvironment.php
Created May 24, 2016 19:59
check yoself before you wreck yoself
public function __invoke($request, $response, $next)
{
$problems_found = $this->problemChecker();
if ($problems_found){
$response = $this->view->render($response, 'pages/config-errors.html.twig', [
"messages" => $this->results
]);
} else {
$response = $next($request, $response);
@alexweissman
alexweissman / sample-data.json
Last active May 20, 2016 16:48
load some kind of data from a JSON API into a dropdown menu
{
"count": 6,
"rows": [
{
"id": 1,
"name": "Indiana University Bloomington"
},
{
"id": 2,
"name": "Ivy Tech Bloomington"
public function fatalHandler() {
$error = error_get_last();
// Handle fatal errors
if( $error !== NULL && $error['type'] == E_ERROR) {
$errno = $error["type"];
$errfile = $error["file"];
$errline = $error["line"];
$errstr = $error["message"];
@alexweissman
alexweissman / composer.json
Last active March 15, 2016 02:18
Using Rockettheme's Locator and Stream classes
{
"require": {
"php": ">=5.4.0",
"rockettheme/toolbox": "1.3.0"
}
}