Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am rbayliss on github.
  • I am rbayliss (https://keybase.io/rbayliss) on keybase.
  • I have a public key ASBa65UfXH4FUKGkhTgE2hA4SPrpKB-5nO3yuUA5RYmaXAo

To claim this, I am signing this object:

@rbayliss
rbayliss / guard.test.ts
Created August 10, 2022 17:51
Guard for gracefully handling errors thrown during async iterable iteration
import { collect } from 'streaming-iterables';
import { guard, mapGuard } from './guard';
describe('mapGuard()', () => {
it('Should handle errors thrown while mapping.', async () => {
const err = new Error('An error');
const mapper = (throwError: boolean) => {
if (throwError) {
throw err;
}
<?php
$map = array(
'best_sandwiches' => 'field_sandwiches',
);
// Fatal error in PHP 7
$sandwiches = $node->$map['best_sandwiches']
// OK:
$sandwiches = $node->{$map['best_sandwiches']}
@include foundation-global-styles;
@include foundation-typography;
{#
This is a glue template. It maps Drupal data to a simpler structure.
In this case, it converts the items render array into an array
of rendered images, then passes that into the image-grid component.
It also handles outputting the wrapper with the attributes Drupal
requires.
#}
{% set images = [] %}
{% for item in items %}
{% set images = images|merge([item|render]) %}
const puppeteer = require('puppeteer');
const EventEmitter = require('events');
/**
* Usage:
*
* const crawler = new Crawler('http://example.com');
*
* crawler.on('insecureRequests', (e) => {
* console.log(`Caught insecure request on ${e.url} to ${e.requests}`);
<?php
require_once __DIR__.'/vendor/autoload.php';
$time = microtime(TRUE);
for($i = 0; $i < 1000; $i++) {
\League\Uri\Schemes\Http::createFromString('http://google.com');
}
/**
* Graceful degradation
*/
#sidebar, #main {
float:left;
}
#sidebar {
width:25%;
}
@rbayliss
rbayliss / .htaccess
Created August 15, 2013 17:55
Drupal .htaccess rewrite rules that can be used both with and without a VirtualDocumentRoot. Shamelessly stolen from Symfony2 Standard Edition (https://github.com/symfony/symfony-standard/blob/master/web/.htaccess)
RewriteEngine On
# Determine the RewriteBase automatically and set it as environment variable.
# If you are using Apache aliases to do mass virtual hosting or installed the
# project in a subdirectory, the base path will be prepended to allow proper
# resolution of the app.php file and to redirect to the correct URI. It will
# work in environments without path prefix as well, providing a safe, one-size
# fits all solution. But as you do not need it in this case, you can comment
# the following 2 lines to eliminate the overhead.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
@rbayliss
rbayliss / cache.drush.inc
Created April 30, 2011 04:40
Drush cache-disable and cache-enable commands.
<?php
function cache_drush_command() {
$items = array();
$items['cache-disable'] = array(
'description' => 'Disable caching.',
'arguments' => array(
'type' => 'Name of Caches to Disable'
),