Skip to content

Instantly share code, notes, and snippets.

View edhaase's full-sized avatar

Edward Haase edhaase

  • Gresham, Oregon
View GitHub Profile
/**
* MiniMap.js - MiniMap for the game Adventure.Land
*
* Features:
* Event emitter
* Drag to reposition
* Numpad plus/minus to zoom
* Toggle visibility to show or hide
* Left click to interact with markers, right click to smart move
* Easily extensible
@edhaase
edhaase / CacheStampedeAvoider.js
Created August 7, 2019 18:28
Prevent cache stampedes by tracking pending requests
/**
* Example cache class that uses promises to resolve.
*/
class Cache {
constructor() {
this.store = {};
}
async get(key) {
return this.store[key];
}
<?php
/**
* Streaming json writer. Call generator to set up,
* file isn't opened until you call send().
*
* Pass objects with send until you're done. You can call send(null) to close
* or let the finally finish up and close out the file at end of execution.
*
* @param string $file - File path to write to
function progressGen(ProgressBar $bar, $itr)
{
$bar->start();
try {
foreach($itr as $k => $v) {
yield $k => $v;
$bar->advance();
}
} finally {
$bar->finish();
<?php
/**
* ProgressBar.php
*
* Extension of Symfony's ProgressBar to limit redraw's to a minimum time
*/
namespace App\Lib;
use Symfony\Component\Console\Helper\ProgressBar as SymfonyProgressBar;
<?php
/**
* TempStreamIterator.php
*
* Caches an iterable into a temporary stream, memory or file backed.
* Result is rewindable.
*
*/
class TempStreamIterator implements \Iterator
@edhaase
edhaase / C9 Dev
Last active February 22, 2018 11:57
# Copy this to Dockerfile
# Build with `sudo docker build -t c9 .`
# Resulting container is c9
FROM ubuntu:14.04
RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8
<?php
/**
* This one leverages include with a data uri. Can't leverage opcache with it, but
* for those of you with a religious fear of eval, this is an alternative.
*
* Requires allow_url_include to be enabled in php.ini
*/
class TwigDataUriStashCache implements \Twig_CacheInterface
{
<?php
class TwigStashCache implements \Twig_CacheInterface
{
private $pool;
public function __construct(\Stash\Interfaces\PoolInterface $pool)
{
$this->pool = $pool;
}
<?php
class TwigAPCuCache implements \Twig_CacheInterface
{
/**
* {@inheritdoc}
*/
public function generateKey($name, $className)
{
$key = "$name;$className";