Skip to content

Instantly share code, notes, and snippets.

View joelhinz's full-sized avatar

Joel Hinz joelhinz

  • Falkenberg, Sweden
View GitHub Profile
### Keybase proof
I hereby claim:
* I am joelhinz on github.
* I am joelhinz (https://keybase.io/joelhinz) on keybase.
* I have a public key whose fingerprint is 63AF 6064 1A80 DB28 7F95 2EFD 9393 3C45 018E 4679
To claim this, I am signing this object:
@joelhinz
joelhinz / RedirectIndexPhpCalls.php
Last active March 6, 2019 08:08
Laravel 5 redirect index.php calls middleware
<?php
namespace App\Http\Middleware;
use Closure;
class RedirectIndexPhpCalls
{
/**
* Handle an incoming request.
@joelhinz
joelhinz / prisoners.js
Created November 5, 2016 11:07
The twelve prisoners, OOP
var _ = require('lodash');
class Card {
constructor(value) {
this.value = value;
}
}
class Deck {
@joelhinz
joelhinz / prisoners2.js
Created November 5, 2016 11:07
The twelve prisoners, shorter version
var _ = require('lodash');
function run() {
var piles = _.chunk(_.shuffle(_.range(52).map(i => Math.floor(i/4))), 4);
return iterate(piles[0].shift(), piles);
}
function iterate(hold, piles) {
if (_.range(1, 13).every(i => piles[i].length === 0)) return true;
if (piles[0].length == 0 && hold === 0) return false;
@joelhinz
joelhinz / mer-ioc.php
Last active November 25, 2016 13:46
mer ioc!
<?php
// en global helper
function stats($object = null)
{
$cache = App::make('statistics-cache');
return $object ? $cache->resolve($object) : $cache;
}
<?php
// vanliga arrayer
$capitals = [];
foreach ($countries as $country) {
$capitals[] = $country->capital;
}
// collections
$capitals = $countries->map(function ($country) {
<?php
$countries->map(function ($country) {
return $country->capital;
})->reject(function ($capital) {
return $capital->isTiny();
})->partition(function ($capital) {
return $capital->hasMayor();
});
<?php
// variables
$foo = 'bar';
$megafoo = 2345;
$superfoo = new AmaziClass();
// class properties
class Lingon
{
function (event) {
event.preventDefault();
const activate = document.getElementById(this.dataset.activate);
const deactivate = document.getElementById(this.dataset.deactivate);
deactivate.classList.add('inactive');
deactivate.classList.remove('active');
setTimeout(() => {
<?php
foreach ($this->lines as $line) {
if (!str_contains($line, ':')) {
$this->addError($line, 'No code found');
} else {
$this->convertLine($line);
}
}