Skip to content

Instantly share code, notes, and snippets.

@jirassimok
jirassimok / prepare_slices.py
Last active May 5, 2020 23:57
Multiple slice assignment
"""
Simulate assignment to different-shaped, non-contiguous slices of a NumPy array.
Note that this is unnecessarily complex and inefficient for most use cases.
Created for this Stack Overflow answer:
https://stackoverflow.com/a/60803701
"""
from itertools import chain
import numpy as np
@jirassimok
jirassimok / a_test.py
Last active November 11, 2019 00:46
Testing halftone speeds
# Comparing answers to this Stack Overflow question:
# https://stackoverflow.com/q/58791296/
from original import process_tones, halftone
from tstanisl import process_tones2, halftone_fast
from jirassimok import tones_as_array, np_halftone
def full_halftone(img):
return halftone(img, process_tones())
@jirassimok
jirassimok / autotest.py
Last active October 23, 2019 22:25
Stack Overflow Sockets question
"""
Code in other all other files adapted from here:
https://stackoverflow.com/q/58424446
This is just a simple script that runs processes for the server and client.
My comments in server.py and client.py all start with '##'.
shared.py sets the global variables shared by the client and the server,
and it modifies a handful of functions they use to improve logging.
@jirassimok
jirassimok / random-speed-test.py
Last active October 12, 2019 02:02
Test Python's random number generation time in edge cases for StackOverflow
#!/user/bin/env python3
# Code written while writing this StackOverflow answer:
# https://stackoverflow.com/a/58126026
from timeit import timeit
def test(bit_lengths, trials=10000, unit=1000, rounding=16):
"""Test how long it takes to find a random n-bit number less than the largest
and smallest number with exactly that many bits.
@jirassimok
jirassimok / module.js
Created September 14, 2019 23:28
Sample JavaScript module for Stack Overflow
// https://stackoverflow.com/a/57939957
export default {
MESSAGE: "default message";
}
export const MESSAGE = "specific message";