Skip to content

Instantly share code, notes, and snippets.

@un-def
un-def / openwrt-update-tz.sh
Created April 23, 2015 07:21
Update OpenWrt timezones from github.com/openwrt/luci
#!/bin/sh
cd /usr/lib/lua/luci/sys/zoneinfo
for f in tzdata.lua tzoffset.lua
do
mv $f $f.bak
wget -nv --no-check-certificate https://raw.githubusercontent.com/openwrt/luci/master/modules/luci-base/luasrc/sys/zoneinfo/$f
done
@un-def
un-def / nmcli-toggle.py
Created June 24, 2015 08:43
Toggle network connection up/down using nmcli
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import subprocess
if len(sys.argv) < 2:
print("Usage: nmcli-toggle.py connection_id")
sys.exit()
conn_id = sys.argv[1]
active = subprocess.check_output(['nmcli', 'connection', 'show', '--active'])
up_down = ('up', 'down')[conn_id in active]
@un-def
un-def / domru-antidpi
Last active January 23, 2023 14:35
Stop DNS spoofing and fake redirects by Дом.ru ISP
iptables -A INPUT -p udp --sport 53 --match string --algo bm --hex-string '|5cfff164|' -j DROP
iptables -A INPUT -p tcp --sport 80 --match string --algo bm --string 'Location: http://lawfilter.ertelecom.ru' -j DROP
@un-def
un-def / uniq_mixin.py
Created September 12, 2015 10:51
`uniq` method mixin
class UniqMixin:
def uniq(self):
uniq_list = []
for el in self:
if el not in uniq_list:
uniq_list.append(el)
return self.__class__(uniq_list)
@un-def
un-def / instancelinkwidget.py
Last active November 23, 2015 08:38
Django InstanceLinkWidget
from django import forms
from django.utils.safestring import mark_safe
from django.core.urlresolvers import reverse
class InstanceLinkWidget(forms.Widget):
def __init__(self, obj, attrs=None):
self.obj = obj
super(InstanceLinkWidget, self).__init__(attrs)
@un-def
un-def / zip_trim.py
Created January 9, 2016 06:29
zip with trim/fill
def zip_trim(i1, i2, trim='shortest', default=None):
''' trim = 'shortest' | 'longest' | 'first' | 'second'
'''
i1_iter = iter(i1)
i2_iter = iter(i2)
while True:
stop = False
try:
e1 = next(i1_iter)
except StopIteration:
@un-def
un-def / base_site.html
Created January 29, 2016 15:42
Django admin site lang switcher
<!-- {templates_dir}/admin/base_site.html -->
{% extends "admin/base.html" %}
{% load i18n %}
{% block title %}{{ title }} | {{ site_title|default:_('Django site admin') }}{% endblock %}
{% block branding %}
<h1 id="site-name"><a href="{% url 'admin:index' %}">{{ site_header|default:_('Django administration') }}</a></h1>
{% endblock %}
@un-def
un-def / i3-window-icons-deb.sh
Created June 10, 2017 13:11
Tool to create (and optionally install) Debian packages of i3 with window icons patch
#!/bin/bash -e
# Tool to create (and optionally install) Debian packages of i3 with
# window icons patch.
# Based on i3-gaps-deb by Gerhard A. Dittes
# Copyright (C) 2017 Gerhard A. Dittes
#
# This program is free software: you can redistribute it and/or modify
@un-def
un-def / hm.py
Created December 2, 2017 20:14
Ugly Python-based XML/HTML DSL
#!/usr/bin/env python3
from abc import ABC, ABCMeta, abstractmethod
from types import FunctionType
from collections import OrderedDict
# flake8: noqa
class UnresolvedFreeVarsError(Exception):
@un-def
un-def / proxyMagic.js
Created February 15, 2018 21:04
proxyMagic
function doMagic(obj) {
return new Proxy(obj, {
construct: (target, args) => {
return doMagic(new target(...args))
},
get: (target, name) => {
let prop = Reflect.get(target, name)
if (typeof prop === 'function') {
return prop.bind(target)
}