Skip to content

Instantly share code, notes, and snippets.

@jm42
jm42 / Vagrantfile
Created August 10, 2018 12:24
Prometheus Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby sw=2 ts=2 :
Vagrant.configure("2") do |config|
config.vm.box = "debian/jessie64"
config.vm.define "prom-server" do |prom|
prom.vm.hostname = "prom.local"
prom.vm.network "private_network", ip: "192.168.42.63"
prom.vm.synced_folder ".", "/vagrant", disabled: true
@jm42
jm42 / Stack.php
Created September 14, 2016 01:17
Old http middleware impl for guide42/ochenta
<?php declare(strict_types=1);
namespace ochenta\psr15;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use ochenta\psr7\Response;
use ochenta\psr7\ServerRequest;
use ochenta\psr7\Stream;
use function ochenta\stream_of;
- name: read config
when: version is not defined
shell: "cat {{ working_dir }}/app/config/config.yml"
register: config
changed_when: no
- name: set version
when: version is not defined
set_fact: version="{{ (config.stdout|from_yaml).parameters.project.version }}"
@jm42
jm42 / Entity_Forum.php
Created August 28, 2016 00:56
[Unfinished] `ForumBundle` entities
<?php
namespace Argon\MessageBundle\Entity;
use Argon\GameBundle\Entity\Character as Creator;
use Argon\GameBundle\Provider\GameProviderInterface;
use Argon\GameBundle\Provider\GameProviderTrait;
/**
* Forum contains topics
@jm42
jm42 / match.php
Created August 16, 2016 23:30
Bizarre implementation mixing FastRoute and my previous iteration
<?php
define('MATCH_ERR_OK', 0);
define('MATCH_ERR_NOT_FOUND', 1);
define('MATCH_ERR_METHOD_NOT_ALLOWED', 2);
function match(callable $handler): callable {
$static = $dynamic = ['GET' => [], 'POST' => []];
$routes = $handler(function(string $method, string $pattern) use(&$static, &$dynamic) {
$method = strtoupper($method);
@jm42
jm42 / match.md
Last active August 10, 2016 18:59
Playing around with a match function
  • Sería un responder para Ochenta\emit,

    function __invoke(ServerRequest $req, callable $open) {
        try {
            $action = $this->getRouter()->match($req);
        } catch (RouteNotFoundException $ex) {
            return not_found($req, $open);
        } catch (MethodNotAllowedException $ex) {

return method_not_allowed($req, $open);

@jm42
jm42 / lambda_router.php
Created August 7, 2016 02:43
Router idea
<?php
class R {
protected $matchers = [];
function __invoke(...$matchers) {
$uniq = uniqid();
$this->matchers[$uniq] = $matchers;
return $uniq;
}
@jm42
jm42 / mustache-vars.php
Last active August 6, 2016 20:44
Variable template in mustache style
<?php
function mustache(array $context) {
return function($resource) use($context) {
$handler = resource_of($resource);
$state = @out;
$tag = '';
while (!feof($handler)) {
$out = fgets($handler);
{
"type": "project",
"autoload": {
"psr-0": {
"Aix\\": "src/",
"Bossa\\": "src/"
}
},
"require": {
"nikic/fast-route": "dev-master",
@jm42
jm42 / aix.php
Created June 30, 2016 12:56
Applicacion w/Auryn
<?php
namespace Aix;
use Auryn\Injector;
use Telegraph\DispatcherFactory;
use Telegraph\DispatcherInterface;
class Aix
{