Skip to content

Instantly share code, notes, and snippets.

View tyx's full-sized avatar

Timothée Barray tyx

  • @gogaille
  • Marseille
View GitHub Profile
@bloodyowl
bloodyowl / Component.js
Created January 4, 2017 15:16
Component library in less than 140 bytes
b=0;$=x=>(p,i="_"+b++,u=($[i]=q=>eval(i).innerHTML=x(p,$[q],u),z=>($[++b]=z,`$.${i}(${b})`)))=>`<c id=${i}>${x(p,[]._,u)}</c>`
@pqina
pqina / create-thumbnail.php
Last active January 4, 2025 17:42
Create thumbnails with PHP
<?
// Link image type to correct image loader and saver
// - makes it easier to add additional types later on
// - makes the function easier to read
const IMAGE_HANDLERS = [
IMAGETYPE_JPEG => [
'load' => 'imagecreatefromjpeg',
'save' => 'imagejpeg',
'quality' => 100
<?php
/**
* This is the clock interface. It's really simple, you write it once, use it anywhere.
* Cool extra things you can do:
* - have it return custom value objects
* - separate method for currentDate() without time part
*/
interface Clock
{
@rosstuck
rosstuck / 1-cookiejar.feature
Last active May 24, 2017 12:03
Behat / ES Helper
Feature: Cookie Jar
Scenario: The last cookie put in the jar is the first eaten
Given I put a raisin cookie in the jar
And I put a chocolate cookie in the jar
When I eat a cookie
Then I should have eaten a chocolate cookie
Scenario: I eat multiple cookies
Given I put a raisin cookie in the jar
@Ocramius
Ocramius / find-missing-return-types.php
Last active September 5, 2018 10:27
Script to find classes/interfaces/traits with missing return types: ADD THEM TO YOUR SHIT.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$namespace = 'PutYourProjectNamespaceHere\\';
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src')), '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH) as $file) {
require_once $file[0];
}
@paulirish
paulirish / what-forces-layout.md
Last active April 18, 2025 15:29
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@codeliner
codeliner / DDD_avoid_large_cluster_example.php
Created July 7, 2015 19:07
This example illustrates modelling small aggregates instead of a large cluster: See discussion: https://groups.google.com/forum/#!topic/dddinphp/WBKuPAT0OS8
<?php
/*
* This example illustrates modelling the following use cases:
*
* - A user can write and publish an article, with the title, description.etc.
* - X users can then respond to said article by posting comments,
* - and responding to one another.
* - it is very common for an Article to be 'locked' when it becomes older.
*
* Note: The example is an incomplete draft.
@jeremyb
jeremyb / 1. UsernameType.php
Last active November 28, 2015 20:16
Username value object mapped to a form
<?php
namespace AppBundle\Form;
use AppBundle\Model\Username;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\DataMapperInterface;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormError;
class MoneyType extends AbstractType implements DataMapperInterface
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('amount', 'integer')
->add('currency', 'string')
->setDataMapper($this)
;
}
@addyosmani
addyosmani / README.md
Last active April 6, 2025 09:15 — forked from 140bytes/LICENSE.txt
108 byte CSS Layout Debugger

CSS Layout Debugger

A tweet-sized debugger for visualizing your CSS layouts. Outlines every DOM element on your page a random (valid) CSS hex color.

One-line version to paste in your DevTools

Use $$ if your browser aliases it:

~ 108 byte version