Skip to content

Instantly share code, notes, and snippets.

View andrewcrook's full-sized avatar

andrewcrook

  • UK
View GitHub Profile
@jaantollander
jaantollander / .bashrc
Created August 10, 2021 04:35
Adding to PATH in idempotent way, that is, without repetition.
# https://unix.stackexchange.com/a/124447
add_to_path() {
case ":${PATH:=$1}:" in *:"$1":*) ;; *) PATH="$1:$PATH" ;; esac;
}
# Example
add_to_path $HOME/bin/julia-1.6.1/bin
@waydabber
waydabber / chbrt.m
Last active October 7, 2022 09:22
This should change the brightness level of a single external display connected to an M1 MBP or MBA relative to the current setting using DDC/CI. Reportedly does not work on M1 Mini.
@import Darwin;
@import Foundation;
@import IOKit;
/*******
This should change the brightness level of a single external display connected to an M1 MBP or MBA relative to the current setting using DDC/CI. Reportedly does not work on M1 Mini.
Credits to @tao-j and @alin23
Compile:
@import Darwin;
@import Foundation;
@import IOKit;
// clang -fmodules -o i2cwrite i2cwrite.m && ./i2cwrite
typedef CFTypeRef IOAVServiceRef;
extern IOAVServiceRef IOAVServiceCreate(CFAllocatorRef allocator);
extern IOReturn IOAVServiceCopyEDID(IOAVServiceRef service, CFDataRef* x2);
// outputBufferSize must be less than (1 << 12) (4096 bytes)
@tao-j
tao-j / brt.m
Last active September 2, 2023 02:17
M1 External Monitor Brightness Control over DDC
@import Darwin;
@import Foundation;
@import IOKit;
// clang -fmodules -o brt brt.m && ./brt
// credit to @zhuowei for discovering the following APIs
typedef CFTypeRef IOAVServiceRef;
extern IOAVServiceRef IOAVServiceCreate(CFAllocatorRef allocator);
extern IOReturn IOAVServiceCopyEDID(IOAVServiceRef service, CFDataRef* x2);
@aputs
aputs / pyenv_install_python
Created December 2, 2020 15:13
pyenv install python versions on big sur
export MACOSX_DEPLOYMENT_TARGET=11.0
brew install pyenv bzip2 zlib xz openssl@1.1
## 3.6.8
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.6.8 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
## 3.6.12
CFLAGS="-I$(brew --prefix openssl)/include -I$(brew --prefix bzip2)/include -I$(brew --prefix readline)/include -I$(xcrun --show-sdk-path)/usr/include" LDFLAGS="-L$(brew --prefix openssl)/lib -L$(brew --prefix readline)/lib -L$(brew --prefix zlib)/lib -L$(brew --prefix bzip2)/lib" pyenv install --patch 3.6.12 < <(curl -sSL https://github.com/python/cpython/commit/8ea6353.patch\?full_index\=1)
## 3.7.9
@sloria
sloria / bobp-python.md
Last active April 20, 2024 13:02
A "Best of the Best Practices" (BOBP) guide to developing in Python.

The Best of the Best Practices (BOBP) Guide for Python

A "Best of the Best Practices" (BOBP) guide to developing in Python.

In General

Values

  • "Build tools for others that you want to be built for you." - Kenneth Reitz
  • "Simplicity is alway better than functionality." - Pieter Hintjens