Skip to content

Instantly share code, notes, and snippets.

View welblaud's full-sized avatar
🤔
solving something again

Honza Hejzl welblaud

🤔
solving something again
  • Husinec-Řež (Czech Republic)
View GitHub Profile
@welblaud
welblaud / SignalCatching.php
Last active February 17, 2023 16:02
Signal catching in PHP
<?php
// turn on signal catching
pcntl_async_signals(true);
// handler
$sigHandler = static function(): void {
// do some cleanup
// report to user, whatever
// ...
exit(0);
};
@welblaud
welblaud / RemoveRecursively.php
Last active February 17, 2023 16:01
Function for removing dirs and files recursivelly in PHP
<?php
function rrmdir(string $dirPath): bool {
array_map(static fn (string $filePath) => is_dir($filePath) ? rrmdir($filePath) : unlink($filePath), glob($dirPath . '/' . '*'));
return rmdir($dirPath);
}
@welblaud
welblaud / CommandOutputsSymfony.php
Last active February 17, 2023 16:03 — forked from MattKetmo/FooCommand.php
Writing to stdout and stderr in Symfony app
<?php
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\ConsoleOutputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Testcase: app/console foo > std 2> err
*/
<style>
form {
position: relative;
width: 240px;
margin: 16px;
}
input {
width: 100%;
padding: 2px 24px 2px 2px;
@welblaud
welblaud / seoul256.vim
Created July 18, 2019 10:15 — forked from jbkopecky/seoul256.vim
Seoul256 own custom vim Airline theme (vim/autoload/airline/themes/seoul256.vim)
let g:airline#themes#seoul256#palette = {}
function! airline#themes#seoul256#refresh()
let M0 = airline#themes#get_highlight('Special')
let accents_group = airline#themes#get_highlight('Special')
let modified_group = [M0[0], '', M0[2], '', '']
let warning_group = airline#themes#get_highlight2(['airline_warning', 'bg'], ['airline_warning', 'fg'])
let s:N1 = airline#themes#get_highlight2(['Normal', 'bg'], ['StatusLine', 'fg'])
@welblaud
welblaud / imageValidator.js
Last active July 30, 2020 14:03
Quick Image Validator for checking the quality of images
// imageValidator.js
'use-strict';
function handleFileSelect(evt) {
let files = evt.target.files; // FileList object
// Loop through the FileList and render image files as thumbnails.
for (let i = 0; i < files.length; i++) {
@welblaud
welblaud / newBot.js
Last active February 6, 2019 08:59
App for trading on gate.io forex market
// newBot.js
/* ##################### MODULES ####################### */
let fetch = require( 'node-fetch' );
let fs = require( 'fs' );
let crypto = require( 'crypto' );
let querystring = require( 'querystring' );
/* ##################### CONSTANTS ####################### */
const KEY = '';
@welblaud
welblaud / simple-docx-replace.xsl
Last active May 6, 2020 14:21
Simple replacement for DOCX nodes
<?xmlversion='1.0'?>
<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:w='http://schemas.openxmlformats.org/wordprocessingml/2006/main'
version='1.0'>
<xsl:template match="w:document/w:body/w:p/w:r/w:t[node()='Hello World']">
<w:t>Goodbye World</w:t>
</xsl:template>
<!-- The following transform is the identity transform -->
<xsl:templatematch="/|@*|node()">
@welblaud
welblaud / xslt-factorial.xsl
Created December 12, 2018 08:58
XSLT recursive template call – calculating factorial
<!-- Factorial calculated with XSLT recursion. -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="text"/>
<xsl:param name="number" select="9"/>
<xsl:template match="/">
<xsl:call-template name="factorial">
@welblaud
welblaud / cust-utils.xqm
Created May 20, 2016 12:48
A module for searching and replacing text nodes in in-memory documents (for eXist-db)
xquery version "3.0";
module namespace cust-utils = 'http://46.28.111.241:8081/exist/db/apps/karolinum-x/modules/cust-utils';
(: Replace Spaces Soft – This function replaces all spaces after Czech single-letter prepositions
: with no-breaking spaces. Done in-memory, without storaging the result in the DB.
: The limitation is it does not solve double occurence, e.g. “V hlavě a v těle.“. :)
declare function cust-utils:replace-spaces-soft($nodes as node()*) as item()* {
let $match := '(^|\s|&#160;)([szkvaiouSZKVAIOU])[\s]'
for $node in $nodes