Skip to content

Instantly share code, notes, and snippets.

@sfaut
sfaut / zimbra-soap.txt
Created August 9, 2021 09:20 — forked from be1/zimbra-soap.txt
Zimbra 6.0.4 soap.txt file with json examples
REST URL for requesting content:
http://server/service/home/[˜][{username}]/[{folder}]?[{query-params}]
fmt={ics, csv, etc}
id={item-id}
imap_id={item-imap-id}
part={mime-part}
query={search-query}
types={types} // when searching
auth={auth-types}
@sfaut
sfaut / human_duration.php
Last active February 28, 2022 08:48
Converts seconds to human reading duration like "4 days, 13 hours, 5 minutes, 49 seconds"
<?php
function human_duration(int $seconds): string
{
if ($seconds < 0) {
return 'invalid';
}
if ($seconds === 0) {
return 'now';
@sfaut
sfaut / ZimbraSearchTips.md
Last active March 2, 2022 21:27
Zimbra web Client Search Tips -- Can also be used with sfaut\Zimbra::search()

[2022-03-02] Grabed from https://wiki.zimbra.com/wiki/Zimbra_Web_Client_Search_Tips

Zimbra Web Client Search Tips

Search language description

Some type of query is always applied to produce the view that you see in the Zimbra interface. This topic describes in detail the search grammar used for Zimbra's Search feature & the most overlooked feature: The main search bar!

  • TIP: You can set your General Options to 'Always show search string' to see the current query in the Search toolbar. For example, when this option is set, clicking your Inbox folder shows the query string 'in:inbox'.
@sfaut
sfaut / stream_write_to_file.php.php
Created March 6, 2022 16:35
PHP stream_write_to_file() has been inspired by standard stream_copy_to_stream() which accepts only streams
<?php
if (!function_exists('stream_write_fo_file')) {
/**
* Write a stream to a file, old file contents is lost
*
* Parameters:
* $from: the source stream
* $to: the destination file
* $length: maximum bytes to copy, but default all bytes left are copied
@sfaut
sfaut / human_size.php
Created March 10, 2022 10:04
Converts bytes to a readable value to nearest unit
<?php
/**
* Return the $bytes to the nearest unit (1 kB = 1,000 B)
* eg. human_size(1_000) => "1 kB"
* eg. human_size(876543210, 1) => "876.5 MB"
*/
function human_size(
int $bytes, int $precision = 0, int $base = 1_000,
array $units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
@sfaut
sfaut / levenshtein-distance.sql
Created July 4, 2022 10:56
SQL function calculating the Levenshtein distance between 2 strings
-- Author : sfaut <https://github.com/sfaut>
-- Creation date : 2022-07-04
-- Tested with MySQL 8.0.28 (@@sql_mode='ANSI,TRADITIONAL')
CREATE DEFINER="sfaut"@"%" FUNCTION "levenshtein_distance"(s1 TINYTEXT, s2 TINYTEXT)
RETURNS TINYINT UNSIGNED
DETERMINISTIC
COMMENT 'Calculate the Levenshtein distance'
BEGIN
DECLARE s1_length TINYINT UNSIGNED DEFAULT CHAR_LENGTH(s1);
DECLARE s2_length TINYINT UNSIGNED DEFAULT CHAR_LENGTH(s2);
<?php
function unflat($record, $separator = '.')
{
$result = [];
foreach ($record as $key => $value) {
$parts = explode($separator, $key);
$count = count($parts);
unset($last); // Nettoyage, pour éviter l'empîlement
$new_field =& $last;
function base64url_encode(string $buffer): string
{
$buffer = base64_encode($buffer);
$replacements = ['+' => '-', '/' => '_', '=' => ''];
$buffer = str_replace(array_keys($replacements), array_values($replacements), $buffer);
return $buffer;
}
@sfaut
sfaut / hsl.sql
Last active September 5, 2022 20:00
HSL management with MySQL
-- HSL functions, manage HSL CSS colors
-- Author : sfaut <https://github.com/sfaut>
-- Publication date : 2022-09-05
-- Tested with MySQL 8.0.30 (@@sql_mode='ANSI,TRADITIONAL')
/*
Summary :
hsl() Create a CSS HSL representation of a color