Skip to content

Instantly share code, notes, and snippets.

@stephenwf
stephenwf / Example.php
Last active August 29, 2015 14:15
Drupal OOP Hooks using reflection
<?php
/**
* Assumtions:
* IoC Container setup under $container
* EntityManager interface with 2 classes:
* - Traditional Storage
* - MongoDB
* 2 Services in IoC
* - services.user injects the Traditional Storage
@stephenwf
stephenwf / Server.php
Last active August 29, 2015 14:19
Multi-process PHP Webserver
<?php
interface ServerInterface {
/**
* This is called at the end of every request, to determine wether to continue
* with the event loop. Returns true to conitune, false to stop.
*
* @return bool
*/
@stephenwf
stephenwf / Express.php
Last active August 30, 2016 14:55
Express.php
<?php
/** Requires classes from previous gist **/
/**
* Express lightweight wrapper around Server
*/
class Express extends Server implements ServerInterface {
/**
* Routing default registry
@stephenwf
stephenwf / fix.sh
Created October 5, 2015 13:13
iTerm true fullscreen
defaults write /Applications/iTerm.app/Contents/Info LSUIElement true
@stephenwf
stephenwf / autobahn.js
Created June 11, 2016 15:45
Autobahn for react native projects
This file has been truncated, but you can view the full file.
global.process.versions = {};
global.process.versions.node = false;
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}(g.bundle2 || (g.bundle2 = {})).js = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof notrequire=="function2"&&notrequire;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof notrequire=="function"&&notrequire;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(notrequire,module,exports){
///////////////////////////////////////////////////////////////////
<?php
function changeMe($o) {
$o->name = "changed";
}
$object_1 = new StdClass();
$object_1->name = "original";
changeMe($object_1);
@stephenwf
stephenwf / wat1.php
Last active August 5, 2016 13:24
Wat.php
<?php
$fn1 = function() {
yield 'foo';
yield 'bar';
yield 'bar';
};
$fn2 = function() use ($fn1) {
yield 'baz';
yield from $fn1();
@stephenwf
stephenwf / getClassNames.js
Created August 25, 2016 10:52
Class Name list
function *traverse(item) {
for ( var child of item.children ) {
if (child.className) {
yield* child.classList;
}
if (child.childElementCount !== 0) {
yield* traverse(child);
}
}
}
@stephenwf
stephenwf / BEM.js
Last active October 12, 2016 10:44
BEM JavaScript Helper
const BEM = {
block: (b) => {
const modifier = function (m, c) {
if (m.toString() === '[object Object]') return this.ms(m);
if (!c && c !== undefined) {
return this;
}
return `${this} ${this}--${m}`;
};
const modifiers = function (m) {