Skip to content

Instantly share code, notes, and snippets.

View shtrom's full-sized avatar
💭
When you're coding, noone needs to see your mouth.

Olivier Mehani shtrom

💭
When you're coding, noone needs to see your mouth.
View GitHub Profile
@shtrom
shtrom / echo.php
Created February 15, 2021 07:02
A simple echo page in PHP
<?php
/** A simple echo page in PHP
*
* It just outputs the request it received back, including HTTP headers.
*/
if (!function_exists('getallheaders')) {
// Polyfill for PHP<7.3
function getallheaders()
{
@shtrom
shtrom / bootstrap.sh
Last active February 1, 2024 22:00
Semi-automated tag deduplicator for Wallabag
#!/bin/sh
python3 -m venv .venv/wallabag_merge_tags
. .venv/wallabag_merge_tags/bin/activate
pip install -r requirements.txt
cat << EOF >&2
*** Now run
. .venv/wallabag_merge_tags/bin/activate
@shtrom
shtrom / dial.php
Created November 3, 2020 11:44
dial.php - A simplistic one-page protocol handler for tel: schemes, for FRITZ!Box and Mitel phones
<?php
/**
* dial.php - A simplistic one-page protocol handler for tel: schemes.
*
* Copyright (C) 2020 Olivier Mehani <[email protected]>
*
* This renders a simple HTML form allowing to call a number,
* and to register itself as a protocol handler.
*
* Multiple devices are supported (see the `$devices` array),
@shtrom
shtrom / php_array_funcs_vs_foreach.php
Created October 25, 2019 03:32
Comparing PHP array_* functions vs. foreach.
$referenceMap = [ "sessRef1" => "ibkRef1", "sessRef2" => "ibkRef2", "sessRef3" => null, "sessRef1_2" => "ibkRef1" ];
function test_funcs(array $map) { $values = array_values($map); $newMap = array_merge($map, array_combine($values, $values)); return $newMap; }
function test_foreach(array $map) { $newMap=[]; foreach($map as $k => $v) { $newMap[$k] = $v; $newMap[$v] = $v; } return $newMap; }
function fmicrotime_funcs($map, $count=10000) { $time=microtime(true); for($i=0;$i<$count;$i++) { test_funcs($map); }; $delta=microtime(true)-$time; echo $delta; };
function fmicrotime_foreach($map, $count=10000) { $time=microtime(true); for($i=0;$i<$count;$i++) { test_foreach($map); }; $delta=microtime(true)-$time; echo $delta; }
@shtrom
shtrom / read-kinesis-stream.sh
Last active December 9, 2020 04:30
Simple script to read new records from an AWS Kinesis stream
#!/bin/bash -eu
#
# Test script to read from a Kinesis Data Stream
#
# Olivier Mehani <[email protected]>
#
# Example usage:
#
# REGION=ap-southeast-2 AWS_PROFILE=playground ./read-stream.sh kinesis-cross-account-playground
#
@shtrom
shtrom / staticVsSelf.php
Last active September 5, 2022 07:30
`static` vs `self`
<?php
class VarHolder {
const VAR = 2;
public function showVar() {
echo self::VAR;
echo static::VAR;
}
}
int doSomething(int n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j < n; j += i)
{
// Some O(1) task
}
}
}
@shtrom
shtrom / fritz_cert_upload.py
Last active March 12, 2023 17:01
Upload a TLS key and cert to a FRITZ!Box, in pretty Python
#!/usr/bin/env python3
# vim: fileencoding=utf-8
"""
Upload a TLS key and cert to a FRITZ!Box, in pretty Python
Copyright (C) 2018--2021 Olivier Mehani <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
@shtrom
shtrom / fritzbox-cert-update.sh
Created January 28, 2018 09:55 — forked from wikrie/fritzbox-cert-update.sh
Fritzbox Fritz!Box AVM SSL Letsencrypt automatically update
#!/bin/bash
# parameters
USERNAME="maybe empty"
PASSWORD="fritzbox-password"
CERTPATH="path to cert eg /etc/letsencrypt/live/domain.tld/"
CERTPASSWORD="cert password if needed"
HOST=http://fritz.box
# make and secure a temporary file
@shtrom
shtrom / wallabag19-export.php
Created November 27, 2016 07:39
Export Wallabag 1.9 (and maybe other 1.x) library.
<?php
/* Export Wallabag 1.9 (and maybe other 1.x) library.
*
* Olivier Mehani <[email protected]>, 2016
* MIT license (same as Wallabag itself)
*
* Particularly useful in * case the normal export process dies with a message
* such as
*
* PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 74558957 bytes) in /srv/www/wallabag/inc/poche/Tools.class.php on line 231