Skip to content

Instantly share code, notes, and snippets.

@dmmeteo
dmmeteo / 1.srp.py
Last active June 7, 2024 14:11
SOLID Principles explained in Python with examples.
"""
Single Responsibility Principle
“…You had one job” — Loki to Skurge in Thor: Ragnarok
A class should have only one job.
If a class has more than one responsibility, it becomes coupled.
A change to one responsibility results to modification of the other responsibility.
"""
class Animal:
def __init__(self, name: str):

I write a buggy server to leak socket fd, which listen on 5000, and as expected there were CLOSE-WAIT left when client is closed

$ ss -ntpa | grep 5000
LISTEN     0      50                       :::5000                    :::*      users:(("java",14586,92))
CLOSE-WAIT 79     0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:55804  users:(("java",14586,96))
CLOSE-WAIT 79     0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:59235  users:(("java",14586,93))
CLOSE-WAIT 5      0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:55803  users:(("java",14586,95))
CLOSE-WAIT 150    0          ::ffff:127.0.0.1:5000      ::ffff:127.0.0.1:59236  users:(("java",14586,94))
@soderlind
soderlind / Install.txt
Last active March 5, 2024 20:30
macOS DoH! (DNS over HTTPS) using cloudflared
1) Install cloudflared using homebrew:
brew install cloudflare/cloudflare/cloudflared
2) Create /usr/local/etc/cloudflared/config.yaml, with the following content
proxy-dns: true
proxy-dns-upstream:
- https://1.1.1.1/dns-query
- https://1.0.0.1/dns-query
@awesomebytes
awesomebytes / python_interactive_debugging.md
Last active August 24, 2020 04:28
Drop into interactive console python debugging

To drop into a Python interactive console at some point in your code

import pdb; pdb.set_trace()

And you'll have access to all objects and stuff.

To drop into an iPython interactive console

@Manouchehri
Manouchehri / reply-to-empty-udp.py
Last active May 10, 2024 17:45
Simple Python UDP echo server
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
# Author: David Manouchehri <manouchehri@protonmail.com>
# This script will always echo back data on the UDP port of your choice.
# Useful if you want nmap to report a UDP port as "open" instead of "open|filtered" on a standard scan.
# Works with both Python 2 & 3.
import socket
@darconeous
darconeous / os-x-syslog-server.md
Last active May 2, 2024 13:55
Using OS X as a Syslog Server

Using OS X as a Syslog Server

This document describes how to set up an OS X to be a syslog server that logs messages from the local network. It was largely meant for my own purposes so that I don't forget what I did, but feel free to use it for your own purposes.

A problem with just "turning this on" is that you will not see the correct hostname in the syslog entries. What we will do is use

@nickstanisha
nickstanisha / trie.py
Created November 21, 2015 22:58
An object-oriented implementation of a "Trie" in Python
class Node:
def __init__(self, label=None, data=None):
self.label = label
self.data = data
self.children = dict()
def addChild(self, key, data=None):
if not isinstance(key, Node):
self.children[key] = Node(key, data)
else:
@tjanczuk
tjanczuk / xpub-xsub.js
Created August 24, 2015 23:59
How to connect 5 publishers with 5 subscribers over TCP using ZeroMQ's XPUB/XSUB proxy
// How to connect 5 publishers with 5 subscribers
// over TCP using ZeroMQ's XPUB/XSUB proxy.
// sub (connect)
// <-8701->
// (bind) xpub <---> xsub (bind)
// <-8700->
// (connect) pub
var zmq = require('zmq');
@necmettin
necmettin / find-multiple-extensions.sh
Created August 14, 2015 18:48
Find files by extension, multiple extensions
find FOLDER -type f \( -iname \*.php -o -iname \*.twig \)
@u0d7i
u0d7i / disable_vim_auto_visual_on_mouse.txt
Last active July 26, 2024 06:24
Disable vim automatic visual mode on mouse select
Disable vim automatic visual mode on mouse select
issue: :set mouse-=a
add to ~/.vimrc: set mouse-=a
my ~/.vimrc for preserving global defaults and only changing one option:
source $VIMRUNTIME/defaults.vim
set mouse-=a