Skip to content

Instantly share code, notes, and snippets.

import random
from collections import deque
from dataclasses import dataclass
# Key is hour number
# 0 == midnight
# 1 == 1am, etc.
NUM_PATIENTS_PER_HOUR = {
4: 2,
5: 11,
@kennyyu
kennyyu / gist:f49c3f5d09930d30f98c5f53fec520c6
Last active October 13, 2023 01:20
folly coro changes proof of concept
diff --git a/folly/folly/experimental/coro/Task.h b/folly/folly/experimental/coro/Task.h
--- a/folly/folly/experimental/coro/Task.h
+++ b/folly/folly/experimental/coro/Task.h
@@ -43,13 +43,37 @@
#include <folly/futures/Future.h>
#include <folly/io/async/Request.h>
#include <folly/lang/Assume.h>
+#include <folly/synchronization/SanitizeThread.h>
#include <folly/tracing/AsyncStack.h>
#!/bin/bash -ex
CONTENTS=$(cat <<EOF
foo
bar
baz
EOF
)
sudo echo "$CONTENTS" > /tmp/my_file.txt
namespace {
// Helper struct for manually walking the stack using stack frame pointers
struct StackFrame {
StackFrame* parentFrame;
void* returnAddress;
};
size_t walkNormalStack(
uintptr_t* addresses,
size_t maxAddresses,
#include <folly/executors/CPUThreadPoolExecutor.h>
#include <folly/experimental/coro/BlockingWait.h>
#include <folly/experimental/coro/Task.h>
#include <folly/init/Init.h>
#include <folly/synchronization/Baton.h>
#include <glog/logging.h>
namespace {
// Disallow inlining of the functions below so that we can see the functions
ssize_t getAsyncStackTraceSafe(uintptr_t* addresses, size_t maxAddresses) {
size_t numFrames = 0;
const auto* asyncStackRoot = tryGetCurrentAsyncStackRoot();
if (asyncStackRoot == nullptr) {
// No async operation in progress
return numFrames;
}
// Start by walking the normal stack until we get to the frame right before
// the frame that holds the async root.
#!/usr/bin/env python3
import argparse
import base64
import json
import random
import sys
from typing import Dict, List, NamedTuple, Optional, Tuple
def exp(n: int, e: int, mod: Optional[int] = None) -> int:
#!/usr/bin/env python3
import base64
import random
def exp(n, e, mod=None):
"""
Returns n^e (mod base if specified)
"""
result = 1
// Taken from: http://theclearingband.com/tumblr/tagcloud2.js
var postcount = 0;
var postmax = 400;
var posttotal = 0;
var tmap = new Object();
var tvals = new Object();
var vstr = "";
var tdiv = document.getElementById("tagcloud");
tdiv.innerHTML = "Loading cloud...";
@kennyyu
kennyyu / count.py
Created June 12, 2014 20:10
script to count the number of lines written by an author in a git repository
import argparse
import json
import os
import subprocess
class Chdir:
"""
Initializer/destructor pattern for cd taken from here:
http://stackoverflow.com/questions/431684/how-do-i-cd-in-python
"""