Skip to content

Instantly share code, notes, and snippets.

View lotharthesavior's full-sized avatar

Sávio Resende lotharthesavior

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / Autoloader.php
Created May 21, 2021 05:58 — forked from Nilpo/Autoloader.php
A simple recursive PHP autoloader using the RecursiveDirectoryIterator.
<?php
/*
* The MIT License (MIT)
*
* Copyright (c) 2014 Rob Dunham
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
@lotharthesavior
lotharthesavior / wp-show-registered-filters.php
Last active March 25, 2021 17:28
WordPress - show registered filters for hooks
<?php
function show_registered_filters( $hook = '' ) {
global $wp_filter;
if( empty( $hook ) || !isset( $wp_filter[$hook] ) )
return;
echo '<pre>';
@lotharthesavior
lotharthesavior / block.js
Last active September 14, 2020 02:23
Gutenberg Base Block
var wpddb = {}
wpddb.contentTag = 'p';
wpddb.contentClass = 'wpddb-content';
(function (blocks, editor, element) {
var el = wp.element.createElement;
var RichText = editor.RichText;
blocks.registerBlockType('wpddb/promotion', {
title: 'WPDDB Promotion',
@lotharthesavior
lotharthesavior / diffstring.sh
Created April 30, 2020 18:20
Diff 2 strings with Git Diff
#!/bin/bash
git diff $(echo $1 | git hash-object -w --stdin) $(echo $2 | git hash-object -w --stdin) --color-words=.