Skip to content

Instantly share code, notes, and snippets.

View hskrasek's full-sized avatar

Hunter Skrasek hskrasek

View GitHub Profile
@hskrasek
hskrasek / APIController.php
Created November 9, 2017 17:03
Sunset Laravel
<?php
class APIController
{
uses SunsetsEndpoints;
public function index()
{
return $this->sunsetResponse($apiResponse, 'really cool date here');
}
@hskrasek
hskrasek / guzzle.php
Created August 15, 2017 02:59
How to generate guzzle exceptions when calling Slack API and getting errors
<?php
$stack = new \GuzzleHttp\HandlerStack(\GuzzleHttp\choose_handler());
$stack->push(function (callable $handler) {
return function (
\Psr\Http\Message\RequestInterface $request,
array $options
) use ($handler) {
$promise = $handler($request, $options);
<?php
tap(null, function (&$email) {
preg_match('/\@(.*)\./', $email, $matches);
$email = $matches[1];
})
@hskrasek
hskrasek / AppServiceProvider.php
Created February 2, 2017 17:17
Loading deferred service providers with a non-deferred service provider
<?php namespace App\Modules\Foo\Providers;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider {
protected $defer = true;
public function register() {
$this->app->bind(FooThingInterface::class, FooThing::class);
}
@hskrasek
hskrasek / macro.php
Created November 10, 2016 22:19
Randomly selects a value from from the collection, by weight.
<?php
/**
* Returns a random item from the collection based on a weighted value.
* ['foo' => 70, 'bar' => 30] Foo has a 70 percent chance of being returned
* @return int|string
*/
Collection::macro('weightedRandom', function () {
$sumOfWeights = $this->sum();
$rand = rand(1, $sumOfWeights);
Verifying that +hskrasek is my blockchain ID. https://onename.com/hskrasek
<?php
use Config;
use Illuminate\Support\Contracts\ArrayableInterface;
class Board implements ArrayableInterface
{
/**
* Easy Difficulty
*
@hskrasek
hskrasek / gist:7469f2c5d0650fc58bd1
Created December 10, 2014 20:31
IODocsConverter
import json
from pprint import pprint
from os.path import expanduser
import os
home = expanduser("~")
baseDir = home + '/Documents/Projects/iodocs/public/data'
for subdir, dirs, files in os.walk(baseDir):
for file in files:
# if file == 'apiconfig.json' or file.startswith('.'):
@hskrasek
hskrasek / gist:d2f7e844de6384109114
Created November 12, 2014 16:36
Stash Recovery
#Thanks StackOverflow: http://stackoverflow.com/a/91795
git log --graph --oneline --decorate $( git fsck --no-reflog | awk '/dangling commit/ {print $3}' )
git stash apply $stash_id
@hskrasek
hskrasek / create.blade.php
Created October 14, 2014 23:05
Laravel 5 Validation
@extends('layout')
@section('content')
<h1>Create a new task...</h1>
<ul>
@foreach($errors->all() as $error)
<li>{{$error}}</li>
@endforeach
</ul>