Skip to content

Instantly share code, notes, and snippets.

import itertools
def solve(n, xs):
for t in make_trees(xs):
if eval_tree(t) == n:
return print_tree(t)
def make_trees(xs):
if len(xs) == 1:
yield ('unit', xs[0])
@jthemphill
jthemphill / oneplayer.py3
Last active June 16, 2017 04:00
Attempt to solve JT's tea game for a single player
import collections
import copy
import heapq
from typing import (Any, Dict, Iterator, List, NewType, Set, Tuple, TypeVar)
SMALL_T: int = 2
BIG_T: int = 3
JEFF_SOLUTION = 32
GOAL = 50
; ModuleID = 'slow_iters.cgu-0.rs'
source_filename = "slow_iters.cgu-0.rs"
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-darwin"
%"unwind::libunwind::_Unwind_Exception" = type { i64, [0 x i8], void (i32, %"unwind::libunwind::_Unwind_Exception"*)*, [0 x i8], [6 x i64], [0 x i8] }
%"unwind::libunwind::_Unwind_Context" = type {}
@ref.5 = internal unnamed_addr constant [1 x i32] [i32 1], align 4
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn tests::iter_any::{{closure}}(_1: &mut [closure@src/lib.rs:4:24: 4:35], _2: &i32) -> bool {
let mut _0: bool; // return pointer
scope 1 {
let _3: i32; // "x" in scope 1 at src/lib.rs:4:26: 4:27
}
let mut _4: i32;
bb0: {
.section __TEXT,__text,regular,pure_instructions
.globl __ZN10slow_iters5tests8iter_any17h9958878595c8e553E
.p2align 4, 0x90
__ZN10slow_iters5tests8iter_any17h9958878595c8e553E:
.cfi_startproc
pushq %rbp
Lcfi0:
.cfi_def_cfa_offset 16
Lcfi1:
.cfi_offset %rbp, -16
// % g++ --std=c++14 accidentalcopy.cc -o accidentalcopy
// % ./accidentalcopy
// This prints the output:
//
// 42 = 42
// 42 = 42
// accidentalcopy(13656,0x117fc45c0) malloc: *** error for object 0x7fd967402b20: pointer being freed was not allocated
// accidentalcopy(13656,0x117fc45c0) malloc: *** set a breakpoint in malloc_error_break to debug
#include <iostream>
@jthemphill
jthemphill / facts.tla
Created March 22, 2021 21:33
TLA+ spec for HHVM's live type-to-file reverse index
------------------------------- MODULE facts -------------------------------
EXTENDS Integers
CONSTANTS
NumFiles,
NumTypes,
NumRequests,
FinalClock
@jthemphill
jthemphill / gist:487b41c21c35fa026f71fe82939d0413
Created November 4, 2021 20:07
HHVM watchman deadlock quickstack
2021-11-02 13:41:47 837839: Setting mount namespace failed. Errno: 22
2021-11-02 13:41:47 837906: Target pid: 425995 (inside container: 425995)
2021-11-02 13:41:47 841508: Reading process symbols..
2021-11-02 13:41:48 189050: Gathering stack traces..
2021-11-02 13:41:48 233281: Printing stack traces..
2021-11-02 13:41:48 233298: Total Traced Time: 35.196 milliseconds
2021-11-02 13:41:48 233306: Average Traced Time Per LWP: 0.109 milliseconds
2021-11-02 13:41:48 233310: Longest Traced LWP: LWP 4047257, 0.528 milliseconds
Thread 323 (LWP 4122695):
@jthemphill
jthemphill / debugging.md
Created November 4, 2021 20:07
HHVM watchman deadlock GDB debugging session

Summary

  • The thread that holds s_sharedDataMutex is calling WatchmanConnection::close()
  • WatchmanConnection::close() needs to run something in the EventBaseThread
  • The EventBaseThread is in a callback that's trying to get s_sharedDataMutex
  • This is a deadlock.

Event Base Thread

use rayon::prelude::*;
use std::io::BufRead;
fn edit_distance(s1: &str, s2: &str) -> usize {
if s1.len() > s2.len() {
return edit_distance(s2, s1);
}
let mut distances: Vec<usize> = (0..=s1.len()).collect();
for (i2, c2) in s2.chars().enumerate() {