Skip to content

Instantly share code, notes, and snippets.

View tykling's full-sized avatar
😀

Thomas Steen Rasmussen tykling

😀
View GitHub Profile
@tykling
tykling / carpstop
Created April 21, 2023 06:53
FreeBSD rc.d script to switch CARP MASTER vhids to BACKUP state before shutdown
#!/bin/sh
#
# $FreeBSD$
#
# PROVIDE: carpstop
# REQUIRE: securelevel
# KEYWORDS: nostart shutdown
. /etc/rc.subr
@tykling
tykling / gist:72d3396601c010842695910fbdc74661
Last active May 17, 2018 10:51
Django model method to print information on model instances with an FK relation to the current model instance.
def print_related_objects(self):
"""Print info on the objects that are related with a ForeignKey to this instance"""
for link in [f for f in self._meta.get_fields() if f.one_to_many and f.auto_created and not f.concrete]:
related = getattr(self, link.get_accessor_name()).all()
print("found %s instances of %s pointing at this object - they can be accessed using obj.%s.all()" % (len(related), link.related_model, link.get_accessor_name()))
sessions = AcsSession.objects.filter(inform_eventcodes=[])
while i < 2852690:
sessions_slice = sessions[i:i+1000]
print "processing number %s - %s" % (i, i+1000)
for acss in sessions_slice:
if acss.inform_eventcodes:
continue
xmlroot = fromstring(acss.acs_http_conversationlist[-1].body.encode('utf-8'))
soap_body = xmlroot.find('soap-env:Body', settings.SOAP_NAMESPACES)
inform = soap_body.find('cwmp:Inform', settings.SOAP_NAMESPACES)
sudo chyves windowsguest2 create 32g
sudo chyves windowsguest2 set ram=2G
sudo chyves windowsguest2 set bhyve_net_type=e1000
sudo chyves windowsguest2 set loader=uefi
sudo chyves windowsguest2 set uefi_firmware=BHYVE_UEFI.fd
sudo chyves windowsguest2 set uefi_console_output=vnc
sudo chyves windowsguest2 set uefi_vnc_pause_until_client_connect=yes
sudo chyves windowsguest2 set eject_iso_on_n_reboot=3
sudo chyves windowsguest2 start win2012.iso
sudo chyves windowsguest2 get uefi_vnc_ip
zone "." {
type slave;
file "/usr/local/etc/namedb/slave/root.slave";
masters {
192.5.5.241; // F.ROOT-SERVERS.NET.
};
notify no;
};
zone "arpa" {
type slave;
@tykling
tykling / gist:3ab29c4937422e65b7a29db9cf051585
Created April 13, 2017 15:47
use unicast.uncensoreddns.org over TLS
user@sys-dns:~$ cat /rw/config/unbound/conf.d/tls-upstream.conf
server:
ssl-upstream: yes
forward-zone:
name: "."
forward-addr: 89.233.43.71@853
forward-first: no
@tykling
tykling / hosts_to_zone.sh
Created September 28, 2012 15:08
hosts file to bind zone file
#!/bin/sh
while read line; do
ip=$(echo $line | cut -d " " -f 1);
hosts=$(echo $line | cut -d " " -f 2-);
zone=$(echo $hosts | tr " " "\n" | awk '{print length"\t"$0}'|sort -n|cut -f2- | head -1);
echo "processing zone: $zone (ip $ip - hosts $hosts)";
echo "\$ORIGIN $zone." > $zone.db;
echo "\$TTL 1h" >> $zone.db;
echo "$zone. IN SOA ns.$zone. username.$zone. ( 2007120710; 1d; 2h; 4w; 1h )" >> $zone.db;