Skip to content

Instantly share code, notes, and snippets.

View michaelneu's full-sized avatar
Build failed

Michael Neu michaelneu

Build failed
View GitHub Profile
@michaelneu
michaelneu / docker-tags.py
Created April 3, 2019 19:54
Fetch all tags from a Docker image
#!/usr/bin/env python3
import requests
import sys
if __name__ == "__main__":
if len(sys.argv) != 2:
print("usage: python3 docker-tags.py IMAGE")
exit(1)
@michaelneu
michaelneu / proxy.py
Created March 19, 2019 01:13
Basic relay proxy in Python
#!/usr/bin/env python3
import threading
import socket
class Relay(threading.Thread):
def __init__(self, stop_listening, socket_a, socket_b, direction_indicator):
super().__init__()
self._stop_listening = stop_listening
self._socket_a = socket_a
self._socket_b = socket_b
@michaelneu
michaelneu / diff.py
Created March 8, 2019 18:24
Graphically diff similar images
#!/usr/bin/env python3
from PIL import Image
def diff(image_a, image_b):
pixels_a = image_a.load()
pixels_b = image_b.load()
width_a, height_a = image_a.size
width_b, height_b = image_b.size
@michaelneu
michaelneu / drag-n-drop-hook.ts
Created January 5, 2019 14:41
TypeScript React hook for drag'n'drop on elements
import { useState } from "react";
export const useDragAndDrop = <T extends HTMLElement>() => {
const [isDragging, setIsDragging] = useState(false);
const [innerOffsetX, setInnerOffsetX] = useState(0);
const [innerOffsetY, setInnerOffsetY] = useState(0);
const start = (event: React.MouseEvent<T, MouseEvent>) => {
const element = event.target as T;
const { left, top } = element.getBoundingClientRect();
@michaelneu
michaelneu / button.js
Last active January 9, 2019 11:01
Color context sensitive styled-components HoC
import styled from "styled-components";
export const withButtonStyle = (component) => styled(component)`
position: relative;
display: block;
width: 100%;
padding: 0.5rem 2rem;
color: currentColor;
#!/usr/bin/python2
def set_speed(pwm, speed):
speed = max(0, min(100, speed))
speed = 2.55 * speed
speed = int(speed)
with open("/sys/class/hwmon/hwmon1/pwm" + str(pwm), "w") as f:
f.write(str(speed))
@michaelneu
michaelneu / harold-scraper.py
Last active January 3, 2019 16:15
Scrape all images from hide the pain harold
#!/usr/bin/env python3
import urllib.request
import os
import re
import sys
from concurrent.futures import ProcessPoolExecutor as PoolExecutor, as_completed
from PIL import Image
image_page_link_pattern = re.compile(r"src=\"https:\/\/thumbs\.dreamstime\.com\/t\/([^\"]+)")
@michaelneu
michaelneu / arch-asus-fancontrol.py
Created December 28, 2018 20:16
Control the fan in ASUS laptops via ACPI
#!/usr/bin/env python2
import sys
import os
def call_acpi(command):
with open('/proc/acpi/call', 'w') as acpi_call:
acpi_call.write(command)
# Response
@michaelneu
michaelneu / README.md
Last active June 10, 2022 18:53
Create a map for IP addresses

geocode.py

Use this file to geocode IPs from logfiles and draw them on a map.

How to use it

This script requires geocoder to be installed, so setup a virtualenv:

$ virtualenv --python=python3 venv
@michaelneu
michaelneu / blank.html
Last active April 5, 2021 17:27
A blank page with quotes for Safari's new dark mode
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled</title>
<style type="text/css">
@keyframes fade-white {
0% {
background-color: #1e1e1e;
}