Skip to content

Instantly share code, notes, and snippets.

View zeropaper's full-sized avatar
💅
I may be slow to respond.

Valentin Vago zeropaper

💅
I may be slow to respond.
View GitHub Profile
@zeropaper
zeropaper / dump_to_file.php
Created August 13, 2022 09:03
instead of using dd()
<?php
function dump_to_file(...$any) {
ob_start();
var_dump(...$any);
file_put_contents('log.txt', ob_get_clean(), FILE_APPEND);
}
describe('Some interaction', () => {
// … do something
await writeDocs({
info: {
title: 'Title of the "step"',
},
screenshots: [
// takes a screenshot of the first (0) browser page
{
const renderScreenshot = ({
title = '',
slug = '',
pageIndex = 0,
screenshotPath = '',
description = '',
}) => `<figure id="${slug}-${pageIndex}">
<img src="${screenshotPath}" title="${title}" />
<figcaption>${description}</figcaption>
</figure>`;
@zeropaper
zeropaper / jest-environment.js
Last active October 29, 2019 10:54
Example of Jest environment to generate documentation
// NOTE: this code is not intended to work as-is,
// it needs to be adapted to your setup/environment
const NodeEnvironment = require('jest-environment-node');
const puppeteer = require('puppeteer');
const path = require('path');
const rimraf = require('rimraf');
const mkdirp = require('mkdirp');
const httpServer = require('http-server');
// very useful tool to turn a callback function into a async function ;)
const renderScreenshot = ({
title = '',
slug = '',
pageIndex = 0,
screenshotPath = '',
description = '',
}) => `<figure id="${slug}-${pageIndex}">
<img src="${screenshotPath}" title="${title}" />
<figcaption>${description}</figcaption>
</figure>`;
@zeropaper
zeropaper / e2e.documentation-template.js
Last active September 24, 2019 08:29
puppeteer tips and tricks
const renderScreenshot = ({
title = '',
slug = '',
pageIndex = 0,
screenshotPath = '',
description = '',
}) => `<figure id="${slug}-${pageIndex}">
<img src="${screenshotPath}" title="${title}" />
<figcaption>${description}</figcaption>
</figure>`;
@zeropaper
zeropaper / snippet.php
Created March 19, 2018 08:21
Drupal 8 generate style derivative image
// can be runned from the Devel execute PHP page
use Drupal\image\Entity\ImageStyle;
$path = 'public://2018-03/26756519_10155441271337695_6783993404862700965_o.jpg';
$thumbnail = ImageStyle::load('article');
dpm($thumbnail->buildUrl($path));
$dest = $thumbnail->buildUri($path);
dpm($dest);
$created = $thumbnail->createDerivative($path, $dest);
signals:
colorA:
type: hsla
defaultValue: '180,50%,50%,1'
input: null
hue: 180
saturation: 50
lightness: 50
alpha: 100
beatA:
signals:
colorA:
type: hsla
defaultValue: '180,50%,50%,1'
input: null
hue: 180
saturation: 50
lightness: 50
alpha: 100
beatA:
signals:
colorA:
type: hsla
defaultValue: 1
input: null
hue: 180
saturation: 50
lightness: 50
alpha: 100
beatA: