Skip to content

Instantly share code, notes, and snippets.

@JanKoppe
JanKoppe / README.md
Last active December 4, 2020 03:58
nginx basic auth with different users for read/write

This nginx configuration allows to restrict access via different methods to separate users.

This is very useful for private docker registries, where you want every member of your team to be able to fetch Docker images, but only some users (admins and CI users) to push new images to the registry.

Example:

  • User write can use GET, POST, PUT, DELETE and everything else.
  • User read can only use GET and HEAD.
  • Anonymous users are denied access entirely.
@gregneagle
gregneagle / fancy_defaults_read.py
Last active February 6, 2024 15:14
fancy_defaults_read.py: Reads a preference, prints its value, type, and where it is defined.
#!/usr/bin/python
import os
import sys
from CoreFoundation import (CFPreferencesAppValueIsForced,
CFPreferencesCopyAppValue,
CFPreferencesCopyValue,
kCFPreferencesAnyUser,
kCFPreferencesAnyHost,
@fand
fand / uniforms.md
Last active December 21, 2022 03:15
GLSL uniform values conversion table
@pudquick
pudquick / pyobjc_keychain.py
Last active February 28, 2020 17:09
Manipulating the Keychain in macOS via python and pyobjc
from Foundation import NSBundle
import objc, array
# from CoreFoundation import CFGetTypeID
Security = NSBundle.bundleWithPath_('/System/Library/Frameworks/Security.framework')
# First we need the CF TypeIDs to build some signatures
functions = [
('SecKeychainGetTypeID', 'I'),
]
@pudquick
pudquick / sip_config.py
Created December 22, 2016 22:31
Querying active SIP status directly from the kernel, bypassing nvram and csrutil, via python on macOS
# An overly complicated SIP config checker
# This is a technically interesting implementation because it does not rely on csrutil
# Instead it queries the kernel directly for the current configuration status
# This means, for example, in environments where SIP has been disabled and csrutil has
# been removed or modified (say, with DYLD_LIBRARY_PATH), as long as python can run you
# can still check status
# Additionally, checking the nvram csr-active-config setting isn't accurate now with
# 10.12.2+, since running "sudo csrutil clear" deletes the variable until reboot,
@pudquick
pudquick / receipts.py
Created August 18, 2016 17:14
Programmatically access package receipt information using the OS X PrivateFramework PackageKit (same one pkgutil uses) with python and pyobjc
import objc
packagekit_bundle = objc.loadBundle('PackageKit', module_globals=globals(), bundle_path='/System/Library/PrivateFrameworks/PackageKit.framework', scan_classes=False)
PKReceipt = objc.lookUpClass('PKReceipt')
receipts = PKReceipt.receiptsOnVolumeAtPath_('/')
first_receipt = receipts[0]
# Things you can look up:
# installPrefixPath
#include <stdio.h>
#include <string.h>
#include <windows.h>
static CALLBACK DWORD discard_thread(void *arg)
{
HANDLE pipe = arg;
OVERLAPPED ol = { 0 };
ol.hEvent = CreateEventW(NULL, TRUE, TRUE, NULL);
@xem
xem / readme.md
Last active April 5, 2024 23:16
Maths & trigonometry cheat sheet for 2D & 3D games

Conventions

  • A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
  • lengths are in any unit (ex: pixels)
  • code snippets are in JavaScript

Degrees to radians

angleRad = angleDeg * Math.PI / 180;

#include <stdio.h>
#include <windows.h>
static CALLBACK DWORD read_thread(void *arg)
{
HANDLE pipe = arg;
OVERLAPPED ol = { .hEvent = CreateEventW(NULL, TRUE, TRUE, NULL) };
HANDLE out = GetStdHandle(STD_OUTPUT_HANDLE);
char outbuf[128];
@loderunner
loderunner / osx-ld.md
Last active April 26, 2024 13:53
potential blog posts

ld – Wading through Mac OS X linker hell

Intro

Friend: I tried looking at static linking in Mac OS X and it seems nearly impossible. Take a look at this http://stackoverflow.com/a/3801032

Me: I have no idea what that -static flag does, but I'm pretty sure that's not how you link to a library. Let me RTFM a bit.

Minutes later...