Skip to content

Instantly share code, notes, and snippets.

View edhaase's full-sized avatar

Edward Haase edhaase

  • Gresham, Oregon
View GitHub Profile
/**
* @module TimeStamp
* @todo Unit tests
*/
'use strict';
var moment = require('moment');
/**
* @class
* @param {TimeStamp|string} [src] - A timestamp to parse
@edhaase
edhaase / SequelizeModels.js
Last active December 10, 2021 05:38
Load sequelize models from a folder
/*
* Not actually a JS file; Normally you'd break these components up.
*/
/* creating the database connection */
var db = new Sequelize('database', 'username', 'password', ...);
/* loading the models */
var fs = require('fs');
var path = require('path');
var koa = require('koa');
var app = koa();
var router = require('koa-router')();
var util = require('util');
var compress = require('koa-compress')
app
.use(compress({
threshold: 5,
flush: require('zlib').Z_SYNC_FLUSH
<?php
class TwigAPCuCache implements \Twig_CacheInterface
{
/**
* {@inheritdoc}
*/
public function generateKey($name, $className)
{
$key = "$name;$className";
<?php
class TwigStashCache implements \Twig_CacheInterface
{
private $pool;
public function __construct(\Stash\Interfaces\PoolInterface $pool)
{
$this->pool = $pool;
}
<?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
{
@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
/**
* TempStreamIterator.php
*
* Caches an iterable into a temporary stream, memory or file backed.
* Result is rewindable.
*
*/
class TempStreamIterator implements \Iterator
<?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;
function progressGen(ProgressBar $bar, $itr)
{
$bar->start();
try {
foreach($itr as $k => $v) {
yield $k => $v;
$bar->advance();
}
} finally {
$bar->finish();