Skip to content

Instantly share code, notes, and snippets.

npm start &
# echo sleep 100 | bash &
pid=$!
gid=$(echo $(ps -o pgid= $pid))
ps -jH -$gid
kill -SIGKILL $pid
ps -jH -$gid
kill -SIGTERM -$gid
reset
@thejohnfreeman
thejohnfreeman / 01-sudo.sh
Last active August 23, 2023 12:07
terminate background sudo
#!/usr/bin/env bash
psudo() {
sudo --validate
dir=$(mktemp -d)
mkfifo ${dir}/pipe
sudo sh -c "echo \$\$ >${dir}/pipe; exec $*" &
pid=$(cat ${dir}/pipe)
rm -rf ${dir}
}
@thejohnfreeman
thejohnfreeman / kill.md
Last active August 23, 2023 12:10
sudo kill

I've got the script below. after running this script, my terminal is broken. my input is not echoed to me, though it is read. I can still run commands. output from commands to stdout is broken: newlines are replaced with long sequences of spaces, so all output is on one very long line. I can use the reset command to fix the terminal.

if I change the SIGKILL to SIGTERM, it is fine. I know that SIGKILL doesn't give the program a chance to shutdown gracefully, but what exactly is going on? what important part of the graceful shutdown is missing that ends up breaking the terminal?

if I remove sudo from the kill command, the same breakage happens. if I remove sudo and change the signal to SIGTERM, then the script hangs on the wait command until the first command exits (presumably the SIGTERM was delivered and ignored).

#!/usr/bin/env bash
sudo sleep 3 >/dev/null 2>&1 </dev/null &
pid=$!
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Debug
compiler=Visual Studio
compiler.runtime=MTd
compiler.version=17
os=Windows
os_build=Windows
import asyncio
async def message(delay):
await asyncio.sleep(delay)
print(delay, flush=True)
async def main():
task = asyncio.create_task(message(2))
await message(1)

My last post covered the importance of supplying a RAII type for every pair of balanced functions in an API. Is it possible to write a reusable generic type that can implement that pattern for developers?

We might imagine a type that calls the start function in its constructor and the stop function in its destructor. The constructor would be parameterized by the start and stop functions; let them be callable objects in the general case. The start callable object would not be needed after the constructor returns, and honestly, maybe it shouldn't be passed to the constructor. Maybe the caller of the constructor should be responsible for calling the start function first, and then just constructing the gener

For this technique, we could write a generic type, call it Stopper, that calls an arbitrary function in its destructor.

Notes on Naxxramas from a caster perspective

Short descriptions of each fight, with actions you must take in bold.

Anub'Rekhan

Two adds and Anub. Keep your distance from everything at all times. Focus down the adds while the tank holds Anub, then switch to Anub.

The tank and Anub will start to move around the perimeter of the room, and a new add will spawn. Switch focus to the add, but keep your distance from it and Anub. The add can root you with a web, and if Anub gets close enough to you, he'll silence you. We'll probably wipe if that happens to the healers. Anub will send out waves of little critters. AOE them down.

GROUP_ORDER = 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'
// Divide by two and round up = shift right 1 bit and add 1.
HALF_GROUP_ORDER = '7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A1'
function isFullyCanonical(signatureDer) {
s = signatureDer.slice(-32)
// A lexicographical compare between big-endian hex strings yields the same ordering
// as a comparision of the unsigned integers they represent.
return s < HALF_GROUP_ORDER
}
split(FwdIt first, FwdIt last, Char delim)
{
Result result;
using string = typename Result::value_type;
FwdIt iter = first;
string word;
bool need_space = false;
while (iter != last)
{
Char c = *iter++;