Skip to content

Instantly share code, notes, and snippets.

View makomweb's full-sized avatar
🌀

Martin Komischke makomweb

🌀
View GitHub Profile
@makomweb
makomweb / Dockerfile
Created March 25, 2024 12:29
Docker multi stage file for npm + webserver
# Docker multistage
# 1. stage to run npm install
# 2. stage to create a webserver image with the build artifact from stage 1
FROM node:latest as build-stage
WORKDIR /app
COPY ./ /app/
@makomweb
makomweb / symfony-rx.php
Last active January 24, 2024 12:54
Reactive Extensions are fun 😃
<?php
declare(strict_types=1);
namespace App\Command;
use Rx\Observable;
use Rx\Scheduler;
use Rx\Scheduler\ImmediateScheduler;
use Symfony\Component\Console\Attribute\AsCommand;
@makomweb
makomweb / reflection-test.php
Last active November 30, 2023 12:04
Reflecting a PHP class and it's attributes (traverse properties and attributes)
<?php
declare(strict_types=1);
namespace App\Tests\Unit\Playground;
use Attribute;
use PHPUnit\Framework\TestCase;
use ReflectionAttribute;
use ReflectionClass;
@makomweb
makomweb / docker.sh
Last active October 10, 2023 15:31
Remove docker images / containers
# Remove Image
docker rmi <imageId/Name>
# Force remove image
docker rmi -f <imageId/Name>
# Remove dangling images
docker image prune
# Remove all images
@makomweb
makomweb / pub_sub_cpp.cpp
Last active August 24, 2023 08:13
Fun with C++: implementing a pub/sub scenario using std::bind and other standard facilities. The approach is pretty similar to the well known .NET event mechanism.
#include <iostream>
#include <map>
#include <algorithm>
#include <functional>
#include <memory>
using namespace std;
class EventArgs {
public:
@makomweb
makomweb / jest-react-testing-libary.md
Last active May 12, 2023 14:33
Test a React component via React-Testing-Library
// HiddenMessage.tsx
import * as React from "react";

function HiddenMessage({children}) {
    const [showMessage, setShowMessage] = React.useState(false)
    return (
        <div>
            <label htmlFor="toggle">Show Message</label>
 
@makomweb
makomweb / useGet.tsx
Created March 20, 2023 12:43
HTTP GET hook
import { useEffect, useState } from 'react';
import axios from 'axios';
type State<T> = {
pending: boolean;
error?: Error;
data?: T;
};
export function useGet<T>(url: string) {
<?php
use React\EventLoop\Factory;
use Rx\Observable;
use Rx\Scheduler;
use Rx\Scheduler\EventLoopScheduler;
require_once __DIR__ . '/vendor/autoload.php';
$loop = Factory::create();
@makomweb
makomweb / serialize_test.php
Created June 14, 2022 10:32
Serialize properties
<?php
declare(strict_types=1);
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\SerializerInterface;
class PropertiesTest extends KernelTestCase
{
private SerializerInterface $serializer;
@makomweb
makomweb / json_with_cpp.cpp
Last active June 2, 2022 16:35
Some fun with JSON serialization/deserialization using C++ REST SDK (Codename "Casablanca").
#include <cpprest/json.h>
#include <sstream>
using namespace std;
typedef web::json::value JsonValue;
typedef web::json::value::value_type JsonValueType;
typedef std::wstring String;
typedef std::wstringstream StringStream;
String JsonValueTypeToString(const JsonValueType& type)