Skip to content

Instantly share code, notes, and snippets.

View bpartridge's full-sized avatar

Brenton Partridge bpartridge

View GitHub Profile
@bpartridge
bpartridge / patch_geos.py
Created December 19, 2021 04:08
Django GEOS patch for macOS arm64
def patch_geos_signatures():
"""
Patch GEOS to function on macOS arm64 and presumably
other odd architectures by ensuring that call signatures
are explicit, and that Django 4 bugfixes are backported.
Should work on Django 2.2+, minimally tested, caveat emptor.
"""
import logging
@bpartridge
bpartridge / hooks.md
Last active June 10, 2022 09:29
React Hooks as Python decorators

So Hooks finally started to "click" for me when I realized they're very similar to Python decorators. In fact, they're essentially Python-like decorators, curried against the renderer, in an alternate syntax that reduces duplicate typing.

To be clear: I'm NOT advocating for Hooks moving towards decorator syntax, and I agree with the reasons why this suggestion isn't the right direction to move. But I think that the comparison with decorators is useful nonetheless, and perhaps could guide some of the ways in which we introduce Hooks to skeptical stakeholders.

Consider, for a moment, that Python almost adopted this syntax: https://www.python.org/dev/peps/pep-0318/#community-consensus ...

using:
    classmethod
 synchronized(lock)
# This file extends and overrides parts of the ActiveAdmin DSL and internals
# in order to provide support for automatically displaying and editing images,
# which in our infrastructure are stored as URLs whose column names end in "img".
# Since this file will be reloaded frequently in the development environment,
# all operations done at load time (class_eval's, etc.) MUST be idempotent.
ActiveAdmin::Views::TableFor.class_eval do
def img_column(col_sym=:img, title="Image")
column title, sortable: false do |obj|
@bpartridge
bpartridge / requests_proxy_headers_3.py
Last active November 10, 2019 21:25
requests patch/adapter to capture CONNECT response headers (Python 3)
# https://stackoverflow.com/questions/39068998/reading-connect-headers
# updated for Python 3
# WARNING: barely tested
import socket
import requests
from urllib3.connection import HTTPSConnection
from urllib3.connectionpool import HTTPSConnectionPool
from urllib3.poolmanager import ProxyManager
@bpartridge
bpartridge / clubhouse-userscript-contents.js
Last active May 15, 2019 19:13
Clubhouse.io Userscript
$(function() {
$('<style>').text(`
/* HIDE STORY IDS */
.story-badges .story-id .badge-text {
font-size: 0 !important;
width: 0;
line-height: 0;
margin-left: -1px;
margin-right: -3px;
}
@bpartridge
bpartridge / Makefile
Created January 31, 2014 00:21
Python and Numpy for Xeon Phi
PY_VER = 2.7.3
SRC = $(shell readlink -f python)
MIC_PY_HOME = $(SRC)/_install
MIC_PY_PATH = $(MIC_PY_HOME)/lib/python2.7
CTYPES = $(SRC)/Modules/_ctypes
all: $(MIC_PY_PATH)/_ctypes
install:
@echo "To install, copy $(MIC_PY_HOME) where it can be accessed from the MIC card."
<svg width='813px'
height='386.9994px'
viewBox='0 0 813 386.9994'
xmlns='http://www.w3.org/2000/svg'
xmlns:xlink="http://www.w3.org/1999/xlink">
<style type='text/css'>
.keycap .border { stroke: black; stroke-width: 2; }
.keycap .inner.border { stroke: rgba(0,0,0,.1); }
{
"metadata": {
"name": ""
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
{
@bpartridge
bpartridge / LICENSE.txt
Created July 8, 2012 06:30 — forked from p01/LICENSE.txt
Music SoftSynth
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 Mathieu 'p01' Henri http://www.p01.org/releases/
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@bpartridge
bpartridge / example-user.js
Created May 4, 2012 11:21 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);