Skip to content

Instantly share code, notes, and snippets.

View AdventureLand MiniMap.js
/**
* 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 Aug 7, 2019
Prevent cache stampedes by tracking pending requests
View CacheStampedeAvoider.js
/**
* Example cache class that uses promises to resolve.
*/
class Cache {
constructor() {
this.store = {};
}
async get(key) {
return this.store[key];
}
View StreamingJsonWriter.php
<?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
View SymfonyProgressBarGenerator.php
function progressGen(ProgressBar $bar, $itr)
{
$bar->start();
try {
foreach($itr as $k => $v) {
yield $k => $v;
$bar->advance();
}
} finally {
$bar->finish();
View SymfonyProgressBarDelay.php
<?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;
View TempStreamIterator.php
<?php
/**
* TempStreamIterator.php
*
* Caches an iterable into a temporary stream, memory or file backed.
* Result is rewindable.
*
*/
class TempStreamIterator implements \Iterator
View C9 Dev
# 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
View TwigDataUriStashCache.php
<?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
{
View TwigStashCache.php
<?php
class TwigStashCache implements \Twig_CacheInterface
{
private $pool;
public function __construct(\Stash\Interfaces\PoolInterface $pool)
{
$this->pool = $pool;
}
View TwigAPCuCache.php
<?php
class TwigAPCuCache implements \Twig_CacheInterface
{
/**
* {@inheritdoc}
*/
public function generateKey($name, $className)
{
$key = "$name;$className";