Skip to content

Instantly share code, notes, and snippets.

View chrisosaurus's full-sized avatar

Chris Hall chrisosaurus

View GitHub Profile
@snoyes
snoyes / update field.py
Last active September 10, 2023 14:20
Anki: move part of field to different field, or remove unwanted content from a field
# Open the debug console with Ctrl+: (which is Ctrl+Shift+; on US keyboards)
# (Don't have the browser window open when you do.)
# Run it with Ctrl+Enter
# Remove the # from the last line to actually save the changes
s = r'regular expression to search for goes here'
srcField = 'Source Field Name goes here'
tgtField = 'Target Field Name goes here'
noteType = 'Name of the Note Type goes here'
@DomNomNom
DomNomNom / Murphy42_OO.cpp
Last active August 8, 2018 04:15
Accidentally breaks C++ Access Rights while computing The Answer to the Ultimate Question of Life, the Universe, and Everything. This one is coded in a more Object Oriented fashion
#include <iostream>
// This class was named X to be consistent with http://www.gotw.ca/gotw/076.htm
//
// Its primary purpose is to hold a private value which no one should be able
// to accidentally modify.
class X {
public:
X() : private_(1) { /*...*/ }
int getValue() { return private_; }
@DomNomNom
DomNomNom / Murphy42.cpp
Last active August 7, 2018 01:24
Accidentally breaks C++ Access Rights while computing The Answer to the Ultimate Question of Life, the Universe, and Everything.
#include <iostream>
// File x.h
// This class was named X to be consistent with http://www.gotw.ca/gotw/076.htm
//
// Its primary purpose is to hold a private value which no one should be able
// to accidentally modify.
class X
{
public:
@lattner
lattner / TaskConcurrencyManifesto.md
Last active October 18, 2025 15:19
Swift Concurrency Manifesto
@chrisdone
chrisdone / Printf.idr
Last active May 27, 2024 13:01
Type-safe dependently-typed printf in Idris
module Printf
%default total
-- Formatting AST.
data Format
= FInt Format
| FString Format
| FOther Char Format
| FEnd
@avafloww
avafloww / PhpJava.java
Last active August 12, 2025 13:33
This snippet of code is syntactically valid in both PHP and Java, and produces the same output in both.
/*<?php
//*/public class PhpJava { public static void main(String[] args) { System.out.printf("/*%s",
//\u000A\u002F\u002A
class PhpJava {
static function main() {
echo(//\u000A\u002A\u002F
"Hello World!");
}}
//\u000A\u002F\u002A
PhpJava::main();
@DomNomNom
DomNomNom / X.py
Last active April 28, 2016 01:37
"""
The main use case of this is to replace either
>>> [ x * (x + 1) for x in [1,2,3] ]
or
>>> map(lambda x: x * (x + 1), [1,2,3])
with
>>> map(X * (X + 1), [1,2,3]) #SWAG
You can naively think of it as 'lambda X:' without writing 'lambda X:'.
@DomNomNom
DomNomNom / powerset.py
Last active April 5, 2016 21:48
Two ways of writing powerset which produce the same ordering. Have a go at proving it.
def powerset(list):
if not list:
yield set()
return
*rest, last = list
yield from powerset(rest)
for subset in powerset(rest):
yield subset | {last}
@mikeyhc
mikeyhc / diamond-op.scm
Created October 29, 2015 02:02
adding the perl diamond operator to scheme
(define-syntax <>
(syntax-rules ()
((_ v e ...)
(if (null? (command-line-arguments))
(let loop ((v (read-line)))
(unless (eof-object? v)
e ...
(loop (read-line))))
(let file-loop ((port (open-input-file (car (command-line-arguments))))
(rest (cdr (command-line-arguments))))
/* An HTML template in 180 bytes (minified)
Features: Escapes HTML, accepts either strings or functions as values, and that's all (it doesn't handle looping).
Usage:
OneEightyT(
"<h1>{name}</h1><div>{content} @ {currentTime}</div>",
{
name: "Stella",