Skip to content

Instantly share code, notes, and snippets.

View backslash7's full-sized avatar

Lukáš Staňa backslash7

View GitHub Profile
@backslash7
backslash7 / nagios_json.php
Last active December 11, 2019 23:23
Script for parsing Nagios object.cache file and returning it as JSON.
<?php
header( 'Content-type: application/json;' );
// Change it according to your nagios.cfg
$data = file_get_contents( '/var/ramdrive/objects.cache' );
$matches = array();
$object_matches = array();
$output = array();
preg_match_all( '/(?|define (?<section>\w+) \{\n([^\}]+)+)/i', $data, $matches );
@backslash7
backslash7 / functions.php
Created April 8, 2015 12:13
Fix Wordpress gallery showing only to logged in users
function quickhack_fix_gallery( $query ) {
if ( $query->get( 'post_type', '' ) == 'attachment' ) {
$query->set( 'post_status', 'inherit' );
}
}
add_action( 'pre_get_posts', 'quickhack_fix_gallery', 99 );

Keybase proof

I hereby claim:

  • I am backslash7 on github.
  • I am backslash (https://keybase.io/backslash) on keybase.
  • I have a public key whose fingerprint is C8F5 79F8 E19D FDFF E145 D260 C1D3 8EAC 3AC2 9B3A

To claim this, I am signing this object:

@backslash7
backslash7 / tdt.py
Last active August 5, 2016 14:01
Generate MPEG-TS stream with TDT info
from binascii import hexlify
from struct import pack
from time import sleep
from datetime import datetime
import socket
ts_header = 0x47401410
table_id = 0x70
pointer_field = 0x00
flags_plus_length= 0x7005
@backslash7
backslash7 / extensions_custom.conf
Last active December 18, 2020 21:00
How to strip destination number from SIP To: header and use it as DID
; Assign this context to your incoming SIP trunk settings
[custom-get-did-from-sip]
exten => _X.,1,Noop(Fixing DID using information from SIP TO header)
exten => _X.,n,NOOP(Header is: ${SIP_HEADER(TO)})
exten => _X.,n,Set(pseudodid=${SIP_HEADER(TO)})
exten => _X.,n,Set(pseudodid=${CUT(pseudodid,@,1)})
exten => _X.,n,Set(pseudodid=${CUT(pseudodid,:,2)})
exten => _X.,n,Noop(Pseudo DID is: ${pseudodid})
exten => _X.,n,Goto(from-trunk,${pseudodid},1)
@backslash7
backslash7 / example.nft
Created February 26, 2022 13:02
Russian IPv4/IPv6 prefixes for Linux nftables
#!/usr/bin/env nft -f
flush ruleset
table inet raw {
include "set_country_RU_v4.nft"
include "set_country_RU_v6.nft"
chain prerouting {
type filter hook prerouting priority raw; policy accept;