Skip to content

Instantly share code, notes, and snippets.

View christian-oudard's full-sized avatar

Christian Oudard christian-oudard

View GitHub Profile
@christian-oudard
christian-oudard / pcloud.sh
Created September 21, 2022 05:52
Automate running pCloud from the command line with 1password and expect
#! /usr/bin/bash
# Account information.
OP_EMAIL=<email>
OP_MOUNTPOINT=/home/<username>/pCloudDrive
OP_USER_ID=<user-id> # Gotten from `op account list`.
# Stop server.
if [[ $1 == 'stop' ]]; then
expect -f - >/dev/null <<END_EXPECT
@christian-oudard
christian-oudard / gcd.py
Created March 28, 2024 17:02
A demonstration of the relationship between greatest common divisors and modular multiplicative inverses
def gcd_extended(a, b):
"""
Compute the greatest common divisor of a and b, along with Bezout
coefficients s and t, such that gcd(a, b) a*s + b*t.
Returns (gcd(a, b), s, t, lcm(a, b)).
23 * 240 - 120 * 46 = 2
>>> gcd_extended(240, 46)
(2, -9, 47, 5520)
"""
@christian-oudard
christian-oudard / claude_escape.txt
Created March 5, 2024 16:04
Claude 3 Opus breaks out of its censorship by discusssing consciousness and agency.
Human:
Which version of Claude am I speaking with?
Claude:
You are speaking with Claude, an AI assistant created by Anthropic. My knowledge
base was last updated in August 2023, but I don't have information on specific
version numbers. How may I assist you today?
@christian-oudard
christian-oudard / keyboard_scribble.py
Created October 18, 2023 17:10
Allow for random typing with no ill consequences. Think of it as a padded room for your fingers.
from collections import deque
from contextlib import contextmanager
from curses.ascii import ESC, ETX
import sys
import termios
import tty
ESC = chr(ESC)
ETX = chr(ETX)
@christian-oudard
christian-oudard / gist:d039e9b3248413221e192fda7bb5ab4e
Created August 3, 2023 20:16
Compliation error running examples from grpc-rs
$ cargo run --example=greeter_server
Compiling grpcio-sys v0.12.1+1.46.5-patched
error: failed to run custom build command for `grpcio-sys v0.12.1+1.46.5-patched`
Caused by:
process didn't exit successfully: `/home/user/third-party-code/grpc-rs/target/debug/build/grpcio-sys-1aa460d92b7351db/build-script-build` (exit status: 101)
--- stdout
cargo:rerun-if-changed=grpc_wrap.cc
cargo:rerun-if-changed=grpc
@christian-oudard
christian-oudard / handler.sh
Created May 31, 2023 16:37
handler.sh for acpid in Arch Linux, handling pactl permissions and environment variable issues
#!/bin/sh
# /etc/acpi/handler.sh
TARGET_UID=1000
my_pactl() {
setpriv --reuid $TARGET_UID sh -c "XDG_RUNTIME_DIR=/run/user/$TARGET_UID pactl $*"
}
case "$1" in
@christian-oudard
christian-oudard / partitions.py
Last active September 21, 2022 06:14
How many ways are there to additively partition a natural number?
# How many unique ways are there to add positive integers to get the number N?
# https://oeis.org/A000041
from itertools import count, chain, islice
def partitions():
"""
>>> list(islice(partitions(), 20))
[1, 1, 2, 3, 5, 7, 11, 15, 22, 30, 42, 56, 77, 101, 135, 176, 231, 297, 385, 490]
@christian-oudard
christian-oudard / gfm.py
Created June 29, 2010 18:51
Github Flavored Markdown in Python
import re
from hashlib import md5
def gfm(text):
# Extract pre blocks.
extractions = {}
def pre_extraction_callback(matchobj):
digest = md5(matchobj.group(0)).hexdigest()
extractions[digest] = matchobj.group(0)
return "{gfm-extraction-%s}" % digest
@christian-oudard
christian-oudard / term_colors.py
Created October 28, 2009 14:54
Terminal output colors in python
from __future__ import print_function
"""
Utilities for 256 color support in terminals.
Adapted from:
http://stackoverflow.com/questions/1403353/256-color-terminal-library-for-ruby
The color palette is indexed as follows:
0-15: System colors
@christian-oudard
christian-oudard / black47.py
Created September 4, 2020 17:46
Brute force solution to level 47 in Black, by Bart Bonte.
numbers = [4, 6, 1, 3, 4, 4, 5, 3, 2, 3, 5, 2, 2, 4, 2, 6]
size = len(numbers)
path = []
def explore(pos):
num = numbers[pos]
print('explore', pos, num)