Skip to content

Instantly share code, notes, and snippets.

@tux-00
tux-00 / configparser_to_dataclasses.py
Created August 20, 2018 18:20
Converts python config parser to dataclasses (easier access)
import configparser
from dataclasses import dataclass
@dataclass
class Sections:
raw_sections: dict
def __post_init__(self):
for section_key, section_value in self.raw_sections.items():
@tux-00
tux-00 / iptables.service
Created July 23, 2018 17:23
iptables systemd service file
[Unit]
Description=Add iptables rules
After=systemd-sysctl.service
Before=sysinit.target
[Service]
Type=oneshot
ExecStart=/sbin/iptables-restore /etc/iptables.up.rules
ExecReload=/sbin/iptables-restore /etc/iptables.up.rules
RemainAfterExit=yes
@tux-00
tux-00 / install_neovim.md
Created August 1, 2017 12:44
Install neovim
@tux-00
tux-00 / vim.md
Last active July 19, 2017 08:18
Vim

Replace and ask for confirmation

:%s/foo/bar/gc

@tux-00
tux-00 / timeit_fct.py
Last active March 21, 2017 15:46
Measure execution time of a function
import timeit
timeit.timeit(fct, number=10)
@tux-00
tux-00 / git_change_commit_author.md
Created March 20, 2017 12:41
Change Git commit author
git rebase -i <earliercommit>
git commit --amend --author="Author Name <email@address.com>"
git rebase --continue
@tux-00
tux-00 / test_strings.py
Created March 17, 2017 13:35
Test python3.6 string concatenation performance
def test1():
g = 'gg'
s = 'toto' + g
def test2():
g = 'gg'
s = 'toto%s' % g
def test3():
g = 'gg'
@tux-00
tux-00 / convert_date_to_timestamp.py
Last active March 20, 2017 13:01
Convert date to POSIX timestamp
dt = datetime.datetime.strptime("2015-01-08T01:50:11.719671Z", "%Y-%m-%dT%H:%M:%S.%fZ")
dt.timestamp()
@tux-00
tux-00 / cat_without_comment.md
Last active March 20, 2017 12:53
Cat without comment
cat /etc/squid/squid.conf | egrep -v "(^#.*|^$)"