Skip to content

Instantly share code, notes, and snippets.

@soyuka
soyuka / switch_dark_mode.sh
Created September 5, 2022 09:02
Switch theme alacritty
#!/bin/bash
from=$(cat ~/.config/sway/current_scheme)
if [ "$from" = "black" ]; then
from=black
to=white
else
from=white
to=black
@soyuka
soyuka / index.php
Created December 14, 2020 08:30
API Platform bootstrap
<?php
require './vendor/autoload.php';
use ApiPlatform\Core\Action\EntrypointAction;
use ApiPlatform\Core\Action\ExceptionAction;
use ApiPlatform\Core\Action\PlaceholderAction;
use ApiPlatform\Core\Api\IdentifiersExtractor;
use ApiPlatform\Core\Api\IdentifiersExtractorInterface;
use ApiPlatform\Core\Api\OperationType;
@soyuka
soyuka / stub.php
Created April 4, 2022 17:33
Stubs api platform
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@soyuka
soyuka / wow.ts
Created January 5, 2022 15:59
component dynamic angular
@ViewChild('vc', {read: ViewContainerRef}) vc: ViewContainerRef;
constructor(private _compiler: Compiler,
private _injector: Injector,
private _m: NgModuleRef<any>) {
}
ngAfterViewInit() {
const template = '<span>generated on the fly: {{name}}</span>';
@soyuka
soyuka / example-1.js
Last active August 24, 2021 16:38
Promise reflect API by bluebird to handle multiple errors in Promise.all
const Promise = require('bluebird')
const lambdas = require('./lambdas.js')
// Ref: https://stackoverflow.com/questions/25817366/bluebird-promise-all-multiple-promises-completed-aggregating-success-and-rejec
Promise.all(lambdas.map(function(promise) {
// On utilise l'API reflect pour inspecter a la main nos promesses voir http://bluebirdjs.com/docs/api/reflect.html
// grace a ca, la promesse réussira toujours
return promise.reflect();
})).each(function(inspection) {
// Ici la lambda (ou promesse) a réussi
@soyuka
soyuka / DebugResourceCommand.php
Created May 8, 2021 10:50
Debug command api platform resource collection
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
@soyuka
soyuka / Caddyfile
Created April 6, 2021 09:39
Postgrest JSON-LD support
{
debug
}
localhost
file_server
@resource path_regexp resource ^/api/([a-z_]+)/([a-z0-9-]+)$
@resources path_regexp resources ^/api/([a-z_]+)$
@soyuka
soyuka / Makefile
Created March 3, 2021 11:24 — forked from Pierstoval/confirm.Makefile
"confirm" action for your Makefile
# To use the "confirm" target inside another target,
# use the " if $(MAKE) -s confirm ; " syntax.
mycommand:
@if $(MAKE) -s confirm ; then \
execute_your_command_here ; \
fi
.PHONY: mycommand
# The CI environment variable can be set to a non-empty string,
@soyuka
soyuka / PropertyMetadataFactory.php
Created February 18, 2021 13:36
API Platform use the Model namespace for the API and the Entity namespace for doctrine
<?php
declare(strict_types=1);
namespace App\Metadata;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
final class PropertyMetadataFactory implements PropertyMetadataFactoryInterface
@soyuka
soyuka / stresstest.js
Last active September 11, 2020 16:25
Stresstest event source
const { Transform } = require('stream');
const http = require('http')
function toDataString(data) {
if (typeof data === 'object') return toDataString(JSON.stringify(data));
return data
.split(/\r\n|\r|\n/)
.map(line => `data: ${line}\n`)
.join('');
}