Skip to content

Instantly share code, notes, and snippets.

@MacDada
MacDada / steemit-stylish.css
Created Jul 27, 2016
Stylish for visited links on steemit.com
View steemit-stylish.css
.PostSummary__header > h1 > a:visited, /* articles feed */
article[itemtype="http://schema.org/blogPost"] a:visited, /* article content */
.entry-content a:visited { /* comments */
color: #76B; /* kinda violet, feel free to change it */
}
View DoctrinePostRepository.php
<?php
/**
* Simpler version of
* https://github.com/dddinphp/repository-examples/blob/master/src/Infrastructure/Persistence/Doctrine/DoctrinePostRepository.php#L64
*
* Thanks to using inheritance.
*/
namespace Infrastructure\Persistence\Doctrine;
@MacDada
MacDada / composition.php
Last active May 15, 2016
PHP OOP reuse with composition, inheritance and traits
View composition.php
<?php
class BasicStuff
{
public function foo()
{
/* does basic stuff */
}
}
View guzzle.php
<?php
$client = new GuzzleHttp\Client();
$response = $client->request('POST', 'http://localhost:8000/hello/world', [
'form_params' => [
'name' => 'Norbert',
],
'timeout' => 30,
]);
View test.html
<!DOCTYPE html>
<html>
<body>
<script async src="test.js"></script>
<script>
helloFromTestJs('ok');
</script>
</body>
</html>
@MacDada
MacDada / ShowBlogPostsController.php
Last active Mar 15, 2021
PHP: Use Case architecture example
View ShowBlogPostsController.php
<?php
class ShowBlogPostsController
{
/**
* @param ShowBlogPostUseCase
**/
private $useCase;
/**
View EntitiesToIdsDataTransformer.php
<?php
namespace AppBundle\Form\DataTransformer;
use AppBundle\Entity\Entity;
use AppBundle\Entity\EntityRepository;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\TransformationFailedException;
class EntitiesToIdsDataTransformer implements DataTransformerInterface
View InMemoryStorageLikeLocalStorage.js
/**
* should behave like LocalStorage
*/
var inMemoryStorage = (function () {
var items = {};
return {
length: 0, // todo: read only
getItem: function (key) {
return 'undefined' !== typeof items[key] ? items[key] : null;
@MacDada
MacDada / build.xml
Created Oct 18, 2015
Ant: build.xml: php lint
View build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="NazwaProjektu" default="lint">
<target name="lint" description="Sprawdzamy poprawność składni PHP (syntax check)">
<apply executable="php" failonerror="true">
<arg value="--syntax-check" />
<fileset dir="${basedir}">
<include name="**/*.php" /><!-- sprawdzaj wszystkie pliki php -->
<exclude name="PominTenFolder/**/*" />
View Updateable.php
<?php
class Updatable
{
private $field1;
private $field2;
public function __construct($field1, $field2)
{
$this->field1 = $field1;