Skip to content

Instantly share code, notes, and snippets.

View lotharthesavior's full-sized avatar

Sávio Resende lotharthesavior

View GitHub Profile
@lotharthesavior
lotharthesavior / inotify.sh
Created July 24, 2021 07:37
Inotify for PHP Swoole Hot Reload
#!/usr/bin/env bash
# Start the supervisor program.
# /usr/bin/supervisord -c /etc/supervisor/conf.d/supervisord.conf &
WORK_DIR=$1
if [ ! -n "${WORK_DIR}" ] ;then
WORK_DIR="."
fi
@lotharthesavior
lotharthesavior / Dockerfile-php7
Last active March 5, 2022 18:49
Run php where you have only docker
FROM php:7.4
RUN apt-get update && apt-get install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
RUN apt-get install -y libzip-dev \
@lotharthesavior
lotharthesavior / run-node.sh
Created July 27, 2021 22:31
Run node where you have only docker
function nodeBase {
docker run --rm -v $(pwd):/app -w /app node:13 $1 $2 $3 $4
}
function node {
nodeBase node $1 $2 $3
}
function npm {
nodeBase npm $1 $2 $3
}
@lotharthesavior
lotharthesavior / copy_to_clipboard.js
Created January 7, 2022 02:22
Copy text to clipboard
const textContent = "Some Text to be copied";
const textBlob = new Blob([textContent], { type: "text/plain" });
const data = [new ClipboardItem({"text/plain": textBlob})];
navigator.clipboard.write(data).then(function() {
console.log("Copied to clipboard successfully!");
}, function() {
console.error("Unable to write to clipboard. :-(");
});
@lotharthesavior
lotharthesavior / composer.json
Last active April 4, 2022 00:54
Swoole Http Server with templating and routing
{
"require": {
"league/plates": "^3.4",
"slim/slim": "4.*",
"ilexn/swoole-convert-psr7": "^0.6.0",
"nyholm/psr7": "^1.5"
}
}
@lotharthesavior
lotharthesavior / index.php
Created February 27, 2022 22:09
PHP OpenSwoole Server with query parameters and global scope example.
<?php
use Swoole\Http\Request;
use Swoole\Http\Response;
use Swoole\Http\Server;
$user = 'World';
$server = new Server("0.0.0.0", 8003);
@lotharthesavior
lotharthesavior / server.php
Last active May 16, 2022 04:22
Identifying WebSocket Message author with OpenSwoole
<?php
use Swoole\Websocket\Server;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
$server = new Server("0.0.0.0", 9501);
$server->table = (require __DIR__ . DIRECTORY_SEPARATOR . 'user-table.php')();
$server->on("start", function (Server $server) {
@lotharthesavior
lotharthesavior / Dockerfile
Last active May 16, 2022 04:37
OpenSwoole Docker Dev Environment
FROM ubuntu:20.04
ARG WWWGROUP
ARG SUPERVISOR_CONF
WORKDIR /var/www/html
ENV DEBIAN_FRONTEND noninteractive
ENV TZ=UTC
@lotharthesavior
lotharthesavior / service.php
Created May 17, 2022 17:41
OpenSwoole Yield/Resume Example
#!/usr/bin/env php
<?php
declare(strict_types=1);
class DataObject
{
public $total = 0;
public $data = [];
public function push($item)
@lotharthesavior
lotharthesavior / client.html
Last active May 21, 2022 01:25
OpenSwoole WebSocket with WaitGroup example
<script>
let ws = new WebSocket('ws://127.0.0.1:9502');
ws.send("test 1");
setTimeout(() => ws.send("test 2"), 2000);
</script>