Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am python273 on github.
  • I am python273 (https://keybase.io/python273) on keybase.
  • I have a public key ASDZ5cazye3A_KCFjW091hI3vW_F_l9aIFX5aAD901KS1Ao

To claim this, I am signing this object:

@python273
python273 / hack.py
Last active February 10, 2017 16:33
Hacking multi time pad (Coursera: Cryptography I; Week 1)
import sys
import random
from itertools import combinations
import string
MSGS = (
# X -> Y means that the strings start with the same prefix
# 1 -> 8
import asyncio
@asyncio.coroutine
def proxify(reader, writer):
addr_writer = writer.get_extra_info('peername')[0]
while True:
data = yield from reader.read(8192)
@python273
python273 / line.py
Last active June 8, 2018 10:48
Python line (e.g. timeline) with non-intersecting intervals implementation
# -*- coding: utf-8 -*-
"""
:authors: python273
:license: Apache License, Version 2.0
:copyright: (c) 2018 python273
"""
from functools import reduce
from itertools import chain
from numbers import Number
# Install dependencies
NGINX_VERSION=1.10.1 && \
OPENSSL_VERSION=1.0.1t && \
NPS_VERSION=1.11.33.3 && \
sudo apt-get install unzip build-essential checkinstall git libpcre3 libpcre3-dev zlib1g zlib1g-dbg zlib1g-dev && \
mkdir -p ~/sources/ && \
import time
from mido import MidiFile
from mido import bpm2tempo, tempo2bpm
mid = MidiFile('some.midi')
new_tempo = 75
# track numbers are hardcoded, might be different
old_tempo = tempo2bpm(mid.tracks[0][2].tempo)
@python273
python273 / date_ranges_overlapping.py
Last active April 20, 2021 20:03
Python Date Range & number of unique overlapping days with date range
# -*- coding: utf-8 -*-
"""
:authors: python273
:license: Apache License, Version 2.0
:copyright: (c) 2018 python273
"""
from datetime import datetime, timedelta
from functools import reduce
import operator
@python273
python273 / README.md
Created May 5, 2021 18:11
Rust piping fix (e.g. when piping into less or head)
thread 'main' panicked at 'failed printing to stdout: Broken pipe (os error 32)', library/std/src/io/stdio.rs:940:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
use std::error;
use std::io::Write;
@python273
python273 / README.md
Created May 12, 2021 18:03
JavaScript: how to find screen coordinates of a substring in an element OR how to hightlight words

JavaScript: how to find screen coordinates of a substring in an element OR how to hightlight words

Firefox's Reader mode highlights words when using text-to-speech. Here is related code:

const h = new Highlighter(window, document.getElementById('your-el'));
// highlight(startOffset, length)
h.highlight(8, 12);
from pathlib import Path
import os
import ctypes, re, sys
from pprint import pprint
import traceback
c_ptrace = ctypes.CDLL("libc.so.6").ptrace
c_pid_t = ctypes.c_int32
c_ptrace.argtypes = [ctypes.c_int, c_pid_t, ctypes.c_void_p, ctypes.c_void_p]