Skip to content

Instantly share code, notes, and snippets.

View Strangemother's full-sized avatar

Jay Strangemother

View GitHub Profile
@Yoplitein
Yoplitein / httpserv.py
Last active November 10, 2024 02:11
Python HTTPServer with custom MIME types/headers
from http.server import HTTPServer, SimpleHTTPRequestHandler
from sys import argv
# teach the request handler about common MIME types
# fixes e.g. JS/WASM/etc. failing to load in some browsers
mimeTypes = {}
mimeTypes.update({
".html": "text/html",
".css": "text/css",
".json": "text/json",
@scionoftech
scionoftech / run_on_gpu.py
Created October 3, 2019 10:02
How to run python script on GPU
# pip install --user numba
from numba import jit, cuda
import numpy as np
# to measure exec time
from timeit import default_timer as timer
# normal function to run on cpu
def func(a):
for i in range(10000000):
int[][] result;
float t, c;
float ease(float p) {
return 3*p*p - 2*p*p*p;
}
float ease(float p, float g) {
if (p < 0.5f)
return 0.5f * pow(2*p, g);
@mgrady3
mgrady3 / testframeless.py
Created September 24, 2017 18:17
Test Qt/PyQt Frameless Window resizing with QSizeGrip
"""
Test Qt Frameless Window resizing with QSizeGrip
Maxwell Grady, September 2017.
"""
import sys
from PyQt5 import QtCore, QtWidgets
from qtmodern.styles import dark
from qtmodern.windows import ModernWindow
@Wilfred
Wilfred / dyn_prop.py
Last active November 22, 2023 16:01
dynamically defined properties in python
def attach_dyn_prop(instance, prop_name, prop_fn):
"""Attach prop_fn to instance with name prop_name.
Assumes that prop_fn takes self as an argument.
Reference: https://stackoverflow.com/a/1355444/509706
"""
class_name = instance.__class__.__name__ + 'Child'
child_class = type(class_name, (instance.__class__,), {prop_name: property(prop_fn)})
@xiongxin
xiongxin / client.nim
Created February 25, 2016 13:10
nim sockets
import net
import rawsockets
import strutils
const SERVER_PORT = Port(1987)
const SERVER_ADDR = "localhost"
var canQuit = false
proc main() =
@paulirish
paulirish / what-forces-layout.md
Last active October 26, 2025 14:01
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@EricsonWillians
EricsonWillians / PyWinPath.py
Created August 27, 2015 15:53
This script recursively searches for python.exe in the C partition of the system and adds its path to the system's PATH environment variable to help new users.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# PyWinPath.py
#
# Copyright 2015 Ericson Willians (Rederick Deathwill) <EricsonWRP@ERICSONWRP-PC>
#
# This script recursively searches for python.exe in the C partition of the system,
# And adds its path to the system's PATH environment variable to help new users.
# It also considers some basic common softwares that uses Python, such as GIMP, and ignores them.
@karpathy
karpathy / min-char-rnn.py
Last active October 23, 2025 16:55
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@hailangx
hailangx / Server.py
Created May 18, 2014 14:00
A simper python http server can handle mime type properly
# -*- coding: utf-8 -*-
#test on python 3.4 ,python of lower version has different module organization.
import http.server
from http.server import HTTPServer, BaseHTTPRequestHandler
import socketserver
PORT = 8080
Handler = http.server.SimpleHTTPRequestHandler