Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Not liking the clutterful GitHub

Olivier Mehani shtrom

💭
Not liking the clutterful GitHub
View GitHub Profile
@shtrom
shtrom / CACert.sh
Last active Dec 28, 2021
Backport of CACert update scripts (https://www.qnapclub.eu/fr/qpkg/238) for manual use on Qnap QTS 4.3
View CACert.sh
#!/bin/sh
CONF=/etc/config/qpkg.conf
QPKG_NAME="CACert"
#QPKG_ROOT=`/sbin/getcfg $QPKG_NAME Install_Path -f ${CONF}`
QPKG_ROOT=$(cd $(dirname ${0}); pwd)
QPKG_NAME1="QPerl"
QPKG_ROOT1=`/sbin/getcfg $QPKG_NAME1 Install_Path -f ${CONF}`
export QNAP_QPKG=$QPKG_NAME
@shtrom
shtrom / Zendesk Conversation Fixer.js
Created Apr 21, 2021
GreaseMonkey script to fix ZenDesk conversation threads so they are not top-posted
View Zendesk Conversation Fixer.js
// ==UserScript==
// @name Zendesk Conversation Fixer
// @version 2
// @grant none
// @match https://*.zendesk.com/agent/tickets/*
// ==/UserScript==
function fix(eventContainers) {
console.log("GreaseMonkey ZCF: fixing ...");
const nContainers = eventContainers.length;
@shtrom
shtrom / ndjson2csv.py
Last active Mar 17, 2021
Convert an NDJSON file of similarly-formatted object to a CSV file
View ndjson2csv.py
#!/usr/bin/env python3
import csv, ndjson, itertools, sys
r = ndjson.reader(sys.stdin)
r, rh = itertools.tee(r)
w = csv.DictWriter(sys.stdout, next(rh).keys())
w.writeheader()
for d in r:
w.writerow(d)
@shtrom
shtrom / echo.php
Created Feb 15, 2021
A simple echo page in PHP
View echo.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 / wallabag_merge_tags.py
Last active Jan 21, 2021
Semi-automated tag deduplicator for Wallabag
View wallabag_merge_tags.py
#!/usr/bin/env python3
import csv
import logging
import sys
from fuzzywuzzy import process
from spellchecker import SpellChecker
def main(infilename: str):
@shtrom
shtrom / dial.php
Created Nov 3, 2020
dial.php - A simplistic one-page protocol handler for tel: schemes, for FRITZ!Box and Mitel phones
View dial.php
<?php
/**
* dial.php - A simplistic one-page protocol handler for tel: schemes.
*
* Copyright (C) 2020 Olivier Mehani <shtrom@ssji.net>
*
* 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 Oct 25, 2019
Comparing PHP array_* functions vs. foreach.
View php_array_funcs_vs_foreach.php
$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 Dec 9, 2020
Simple script to read new records from an AWS Kinesis stream
View read-kinesis-stream.sh
#!/bin/bash -eu
#
# Test script to read from a Kinesis Data Stream
#
# Olivier Mehani <olivier.mehani@learnosity.com>
#
# Example usage:
#
# REGION=ap-southeast-2 AWS_PROFILE=playground ./read-stream.sh kinesis-cross-account-playground
#
@shtrom
shtrom / staticVsSelf.php
Last active Mar 25, 2019
`static` vs `self`
View staticVsSelf.php
<?php
class VarHolder {
const VAR = 2;
public function showVar() {
echo self::VAR;
echo static::VAR;
}
}
View complexity.c
int doSomething(int n)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j < n; j += i)
{
// Some O(1) task
}
}
}