Skip to content

Instantly share code, notes, and snippets.

View ShenTengTu's full-sized avatar
🇹🇼
working & study

涂紳騰(Shen-Teng Tu) ShenTengTu

🇹🇼
working & study
View GitHub Profile
@vsajip
vsajip / client.py
Last active October 3, 2024 07:05
Run a logging socket receiver in a production setting with logging from an example webapp
from concurrent.futures import ThreadPoolExecutor, as_completed
import json
import urllib.request
with open('webapp.json', encoding='utf-8') as f:
config = json.loads(f.read())
URLS = [
'http://localhost:%d/?ident=%d' % (config['port'], ident)
for ident in range(1, 1001)
@ShenTengTu
ShenTengTu / main.py
Created June 1, 2021 07:42
Python: simple module to build simple command line tool
"""
Run `python main.py help`:
Output:
```
Use: main.py <command>
Commands:
help Helping imformation.
demo_cmd Demo command docstring.
```
@Jiab77
Jiab77 / upgrade-systemd-on-ubuntu-18.04.md
Last active July 10, 2024 05:03
In this document, I will explain how to upgrade the default systemd version from 237 to 242.

Upgrade systemd on Ubuntu 18.04

In this document, I will explain how to upgrade the default systemd version from 237 to 242.

The main reason why I needed this was related to the DNS-over-TLS that was not supported in the version 237 but available from version 242.

Later, when playing with Lynis, the security auditing tool, I then discovered that the version 242 was also providing the command systemd-analyze that is used by lynis to detect if existing systemd services are configured correctly in the security context, meaning that the existing services can run as expected but needs few or several changes in their configuration to make them safe without any exploitable attack surfaces.

You can try it once you've installed the version 242 of systemd that way:

@tomhicks
tomhicks / plink-plonk.js
Last active November 12, 2024 19:08
Listen to your web pages
@sarfata
sarfata / esp32-crashdecoder.py
Created December 28, 2019 01:02
A Python version of the esp32 exception decoder
#!/usr/bin/env python
import argparse
import re
import os
import subprocess
import sys
class ESP32CrashParser(object):
@ShenTengTu
ShenTengTu / mpy_connect_network.py
Last active September 17, 2023 11:43
MicroPython : callback if connect network successful
import network
import time
SSID = ''
PASSWORD = ''
# disable all network interface first
network.WLAN(network.AP_IF).active(False)
network.WLAN(network.STA_IF).active(False)
@ShenTengTu
ShenTengTu / cli.py
Last active March 20, 2021 14:09
A simple class that extends `argparse.ArgumentParser`. It let you use decorator to build sub commands CLI.
"""
https://gist.github.com/ShenTengTu/5e40217db8f7a218b28f365a13a14c00
"""
__all__ = ["arg_meta", "CLI"]
import argparse
def arg_meta(*arg_flags, **arg_conf):
@jedie
jedie / button_test.py
Last active January 31, 2024 05:32
microPython button irq debouncing
import time
from micropython import const
from machine import Pin, Timer
BUTTON_A_PIN = const(32)
BUTTON_B_PIN = const(33)
class Button:
"""
@dunossauro
dunossauro / singleton_example.py
Created March 15, 2018 02:16
singleton decorator python
# copied from:
# https://stackoverflow.com/questions/31875/is-there-a-simple-elegant-way-to-define-singletons
class Singleton:
"""
A non-thread-safe helper class to ease implementing singletons.
This should be used as a decorator -- not a metaclass -- to the
class that should be a singleton.
The decorated class can define one `__init__` function that
@JLChnToZ
JLChnToZ / ninjectscript.js
Last active December 7, 2017 16:31
Inject external JavaScript like a ninja
var ninjectScript = (function(window, document) {
var head = document.head || document.getElementsByTagName('head')[0],
BlobBuilder,
builderPrefixes = [
'webkit', 'Webkit', 'WebKit',
'moz', 'Moz', 'o', 'O',
'ms', 'Ms', 'MS',
'khtml', 'Khtml', ''
];