Skip to content

Instantly share code, notes, and snippets.

@kms70847
kms70847 / makegrid.py
Created September 19, 2019 12:35
makegrid.py - copy rectangular grids to the clipboard
from PIL import Image, ImageDraw
import sys
from io import BytesIO
from ctypes import memmove, windll, c_size_t as SIZE_T
from ctypes.wintypes import UINT, LPVOID, BOOL, HWND, HANDLE
HGLOBAL = HANDLE
GHND = 0x0042
GMEM_SHARE = 0x2000
@kms70847
kms70847 / GifHider.bookmarklet
Last active July 26, 2019 18:59
Gif Hider - replaces gifs with a black rectangle until you hover over them
javascript:(function(){style = document.createElement("style"); style.stype = "text/css"; style.innerHTML = 'img[src$=".gif"]{filter: brightness(0%);} img[src$=".gif"]:hover{filter: brightness(100%);}'; document.getElementsByTagName("HEAD")[0].appendChild(style);})();
@kms70847
kms70847 / geometry.py
Created July 12, 2019 14:23
random generation of points in an equilateral triangle without conditionals or discarding out-of-bounds points
import math
class Point(object):
def __init__(self, *args, **kargs):
self.num_dimensions = kargs.get("num_dimensions", len(args))
self.coords = [0 for i in range(self.num_dimensions)]
for i in range(len(args)):
self.coords[i] = args[i]
"""Gives the distance from this point to the origin."""
import struct
import math
import decimal
from fractions import Fraction
def float_to_bits(f):
bits = [(b>>i)%2 for b in struct.pack(">d", f) for i in range(7, -1, -1)]
return "".join(str(b) for b in bits)
def bits_to_float(bits):
@kms70847
kms70847 / float_visualizer.py
Last active May 16, 2019 12:32
Interacitve visualization of the binary form of any floating point number
from tkinter import Tk, Entry, Frame, Label, StringVar
import struct
import traceback
def float_to_int(x):
s = struct.pack("d", x)
x = 0
for value in s[::-1]:
x = (x << 8) | value
return x
@kms70847
kms70847 / fractal_visualizer.py
Last active June 19, 2018 18:13
Fractal Visualizer Tool
try:
from tkinter import *
except ImportError:
from Tkinter import *
try:
from queue import Queue
except ImportError:
from Queue import Queue
@kms70847
kms70847 / network_bar_filter.user.js
Last active April 30, 2018 17:55
Filters links out of Stack Overflow's "Hot Network Questions" sidebar
// ==UserScript==
// @name Network Bar Filter
// @namespace about:blank
// @include http://stackoverflow.com/*
// @include https://stackoverflow.com/*
// @include *.stackexchange.com/*
// @version 3
// @grant none
// ==/UserScript==
@kms70847
kms70847 / get_SO_chat_stars.py
Created April 26, 2018 18:59
Scrapes the star list from Stack Overflow's Python chat room and displays a ranking of most starred users
import requests
from bs4 import BeautifulSoup as Soup
import json
import re
import time
import datetime
import dateparser
from collections import defaultdict
import os
// ==UserScript==
// @name Common Comments Box (Stack Overflow)
// @namespace about:blank
// @include http*://stackoverflow.com/questions/*
// @version 1
// @grant none
// ==/UserScript==
var question_comments = [
"Are you getting an error? If so, what is the error and stack trace? Is your code running, but producing unexpected output? If so, what output are you getting, and what output did you expect to get?",
// ==UserScript==
// @name Hacker News Post Sorter
// @namespace .
// @include https://news.ycombinator.com/
// @version 1
// @grant none
// ==/UserScript==
HTMLCollection.prototype.forEach = Array.prototype.forEach;