Skip to content

Instantly share code, notes, and snippets.

@gkralik
gkralik / DummyTranslator.php
Created February 25, 2014 11:32
ZF2 without ext/intl prior to 2.3.0
<?php
/* module/Application/src/Application/I18n/DummyTranslator.php */
namespace Application\I18n;
use Zend\I18n\Exception;
use Zend\I18n\Translator\Translator;
class DummyTranslator extends Translator
@gkralik
gkralik / XhrTerminalViewModelListener.php
Last active August 29, 2015 14:05
ZF2 listener to set ViewModel's terminal property if request is XHR
<?php
/**
* Attach XhrTerminalViewModelListener in module's onBootstrap() method.
*
* <code>
* public function onBootstrap(MvcEvent $e)
* {
* $app = $e->getApplication();
* $eventManager = $app->getEventManager();
* $eventManager->attach(new XhrTerminalViewModelListener());
<?php
/**
* Attach in Module::onBootstrap()
* <code>
* $navigationRbacListener = $target->getServiceManager()->get('NavigationRbacListener');
* $target->getEventManager()->getSharedManager()->attach(
* 'Zend\View\Helper\Navigation\AbstractHelper',
* 'isAllowed',
* [$navigationRbacListener, 'hasPermission']
* );
@gkralik
gkralik / chromium_inline_dbg.html
Last active August 29, 2015 14:05
Chromium: debug inline javascript
<script type="text/javascript">
//# sourceURL=dynamic_script.js
// use above annotation to display content of script tag
// as file dynamic_script.js in Chromium's Sources tab.
</script>
@gkralik
gkralik / README
Last active August 29, 2015 14:26
Detect ClickOnce support of browser
Detect if ClickOnce is (or rather: might be) supported by the browser.
This is partly based on https://gist.github.com/adunkman/2371101.
If the userAgent string does not contain a .NET feature hint,
we settle for everything that looks like an IE, because .NET
is installed nearly everywhere nowadays.
It might also be a good idea to check for the X-ClickOnceSupport
header on the server side.
# from http://stackoverflow.com/a/246128
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
BASE_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
BASE_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
@gkralik
gkralik / check_ssl_expiry.py
Last active June 8, 2018 02:21
Nagios script to check SSL certificate expiry for a domain
#!/usr/bin/env python3
import sys
import socket
import ssl
import datetime
# based on https://serverlesscode.com/post/ssl-expiration-alerts-with-lambda/
#
# Usage: check_ssl_expiry.py <hostname> [port] [gracetime_days]
# port Port to check (defaults to 443)
@gkralik
gkralik / blacklisted.zones
Last active March 8, 2018 11:52
Bind DNS Sinkhole
zone "blacklisted.domain" {type master; file "/etc/bind/blockeddomains.db";};
@gkralik
gkralik / cdata.php
Created April 12, 2017 09:02
PHP: embed string in CDATA section
function embedInCData($str)
{
$dom = new \DOMDocument();
$cdata = $dom->createCDATASection($str);
return $dom->saveXML($cdata);
}
// usage:
echo embedInCData('<strong>foobar</strong>');
// <![CDATA[<strong>foobar</strong>]]>
@gkralik
gkralik / readme.txt
Created April 20, 2017 19:24
Raspberry Pi 3: simultaneous audio output via HDMI and analogue jack
Secenario: running Kodi and MPD. Kodi should output sound via HDMI,
MPD should use the 3.5mm jack.
aplay -l lists available devices:
**** List of PLAYBACK Hardware Devices ****
card 0: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA]
Subdevices: 7/8
Subdevice #0: subdevice #0
Subdevice #1: subdevice #1