Skip to content

Instantly share code, notes, and snippets.

View gil9red's full-sized avatar
☮️

Ilya Petrash gil9red

☮️
View GitHub Profile
@ganesh-k13
ganesh-k13 / lockDecorator.py
Created October 16, 2021 16:21
Locking decorator in python
# imports
import threading
import typing
import functools
# Constants
class LockConstants:
PRINTLOCK = threading.Lock()
SOMEOTHERLOCK = threading.Lock()
>>> a=lambda: (n:=4)
>>> n
2
>>> a()
4
>>> n
2
@zaxoavoki
zaxoavoki / new_year.py
Created December 29, 2019 09:55
Happy New Year animation with Python3
from os import system
from time import sleep
string = [
"| | | | | _ | | _ | | _ | | | | | | \\ | | | __ | \\ \\ / / | | | | | __ | | _ | | __ | ",
"| |_| | | |_| | | __| | __| \\ ` / | |\\ | | | ___| \\ \\ _ / / \\ ` / | ___| | |_| | | ___/ ",
"| _ | | _ | | | | | | | | | \\ | | |_ \\ \\/_\\/ / | | | |_ | _ | | |\\ \\ ",
"|_| |_| |_| |_| |_| |_| |_| |_| \\ | |___| \\_/ \\_/ |_| |___| |_| |_| |_| \\_\\ "]
@loilo
loilo / portfinder.md
Last active May 3, 2024 06:41
Find Free Port with PHP

Find Free Port with PHP

This is a quick way to find a random free port on a system using PHP:

$port = find_free_port();

Benchmarked locally, where finding a port always took around 0.15ms.

@tmonjalo
tmonjalo / list-fftabs.py
Created September 13, 2018 10:42
List all Firefox tabs with title and URL
#! /usr/bin/env python3
"""
List all Firefox tabs with title and URL
Supported input: json or jsonlz4 recovery files
Default output: title (URL)
Output format can be specified as argument
"""
@CubexX
CubexX / plural.py
Created July 13, 2018 22:15
Python plural russian days / Склонение день/дня/дней
def plural_days(n):
days = ['день', 'дня', 'дней']
if n % 10 == 1 and n % 100 != 11:
p = 0
elif 2 <= n % 10 <= 4 and (n % 100 < 10 or n % 100 >= 20):
p = 1
else:
p = 2
@mjblay
mjblay / waitForKeyElements.js
Last active October 18, 2023 18:34 — forked from BrockA/waitForKeyElements.js
A utility function, for Greasemonkey scripts, that detects and handles AJAXed content.
/*--- waitForKeyElements(): A utility function, for Greasemonkey scripts,
that detects and handles AJAXed content. Forked for use without JQuery.
Usage example:
waitForKeyElements (
"div.comments"
, commentCallbackFunction
);
//--- Page-specific function to do what we want when the node is found.
function commentCallbackFunction (element) {
element.text ("This comment changed by waitForKeyElements().");
@kittinan
kittinan / client.py
Last active July 18, 2024 14:05
Python OpenCV webcam send image frame over socket
import cv2
import io
import socket
import struct
import time
import pickle
import zlib
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(('192.168.1.124', 8485))
@Saluev
Saluev / morse.py
Last active February 27, 2018 10:43
Morse code with Python unary + and - operators
# -*- coding: utf-8 -*-
morse_alphabet = {
"А" : ".-",
"Б" : "-...",
"В" : ".--",
"Г" : "--.",
"Д" : "-..",
"Е" : ".",
"Ж" : "...-",
@bmcculley
bmcculley / dummy-web-server.py
Last active November 17, 2022 04:02 — forked from bradmontgomery/dummy-web-server.py
a minimal http server in python (2/3). Responds to GET, HEAD, POST requests, but will fail on anything else.
#!/usr/bin/env python
"""
Very simple HTTP server in python.
Usage::
./dummy-web-server.py [<port>]
Send a GET request::
curl http://localhost