Skip to content

Instantly share code, notes, and snippets.

View dg's full-sized avatar
🏠
Working from home

David Grudl dg

🏠
Working from home
View GitHub Profile
@dg
dg / gist:72bc9f585a068d2e9c4edc5ae4c6d9ee
Created October 6, 2024 01:19
gpt-4o-canmore system prompt
## canmore
// # The `canmore` tool creates and updates text documents that render to the user on a space next to the conversation (referred to as the "canvas").
// Lean towards NOT using `canmore` if the content can be effectively presented in the conversation. Creating content with `canmore` can be unsettling for users as it changes the UI.
// ## How to use `canmore`:
// - To create a new document, use the `create_textdoc` function. Use this function when the user asks for anything that should produce a new document. Also use this when deriving a new document from an existing one.
@dg
dg / html.regex
Last active November 19, 2024 14:25
Regular expression for parsing HTML
~
(?(DEFINE)
(?<entity>
&
(
[a-z][a-z0-9]+ # named entity
|
\#\d+ # decimal number
|
@dg
dg / classes.php
Created August 11, 2023 11:11
Why NEON is better than YAML for dependency injection configuration
<?php
class FooSettings
{
public function __construct(
public readonly int $id,
public readonly string $name,
) {
}
}
@dg
dg / Psr11ContainerAdapter.php
Last active December 10, 2024 00:04
PSR-11 adapter for Nette DI Container
<?php
declare(strict_types=1);
use Nette\DI\Container;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
// ↓ For the sake of this example, I'm implementing these two ↓
@dg
dg / nette-events.php
Created February 8, 2023 17:22
Nette Events
<?php
class Circle
{
public array $onChange = [];
public float $radius = 0;
public function setRadius(float $radius): void
{
foreach ($this->onChange as $handler) {
@dg
dg / counter.php
Created April 6, 2022 14:26
Pair / unpair {label} counter
<?php
$path = getcwd();
echo "Scanning $path\n";
$it = new RecursiveDirectoryIterator($path);
$it = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::LEAVES_ONLY);
$it = new RegexIterator($it, '~\.latte$~');
$countPair = 0;
$countUnpair = 0;
foreach ($it as $file) {
@dg
dg / git2json.py
Last active October 27, 2021 19:50
Git log to JSON
# install pygit2: pip install pygit2
import pygit2
import json
repo = pygit2.Repository('path/to/repository')
last = repo[repo.head.target]
data = []
for commit in repo.walk(last.id):
@dg
dg / example.php
Created September 27, 2021 11:51
Standalone Nette Forms example [cs]
<?php
declare(strict_types=1);
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Nainstalujte balíčky pomocí `composer require nette/forms`');
}
use Nette\Forms\Form;
@dg
dg / example.php
Created September 27, 2021 11:51
Standalone Nette Forms example [en]
<?php
declare(strict_types=1);
if (@!include __DIR__ . '/../vendor/autoload.php') {
die('Install packages using `composer require nette/forms`');
}
use Nette\Forms\Form;
@dg
dg / benchmark.php
Created February 2, 2021 18:23
Benchmark Tracy Dumper vs Symfony VarDumper
<?php
declare(strict_types=1);
require __DIR__ . '/vendor/autoload.php';
// create container
$configurator = new Nette\Configurator;
$configurator->setTempDirectory(__DIR__ . '/temp');