Skip to content

Instantly share code, notes, and snippets.

@yalue
yalue / view_blocksbysm.py
Created November 5, 2019 21:32
A modified version of view_blocksbysm.py that takes a --min-sm and --max-sm command-line argument.
# This script reads all JSON result files and uses matplotlib to display a
# timeline indicating when blocks and threads from multiple jobs were run on
# GPU, including which SM they ran on. For this to work, all result filenames
# must end in .json.
#
# Usage: python view_blocksbysm.py [results directory (default: ./results)]
import argparse
import glob
import json
import math
@yalue
yalue / thread_create_hook.c
Last active June 4, 2021 17:02
Example of hooking pthread_create
// TO COMPILE:
// gcc -shared -fPIC -o thread_create_hook.so thread_create_hook.c -ldl
// TO USE (needs an absolute path):
// LD_PRELOAD=`pwd`/thread_create_hook.so ./application_to_hook
#define _GNU_SOURCE
#include <dlfcn.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@yalue
yalue / write_to_stdin.c
Last active April 23, 2018 14:11
Note to self: writing to a child process' stdin
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
// A minimal-ish example of writing data to a child process' stdin.
int main(int argc, char **argv) {
char print_buffer[256];
int stdin_pipe[2];
int result;
@yalue
yalue / tester.go
Last active March 26, 2017 12:49
Go question
package main
import (
"fmt"
)
type type1 struct {
number int
}
@yalue
yalue / printf.cpp
Created October 6, 2016 15:50
How to make using C++ suck less
void StreamPrintf(std::ostream stream, const char *format, ...) {
char buffer[1024];
va_list args;
memset(buffer, 0, sizeof buffer);
va_start(args, format);
vsnprintf(buffer, (sizeof buffer) - 1, format, args);
va_end(args);
stream << buffer;
}
#define l putchar
int main(void) {
return ((((l(1 + (1 + (1 + (1 + ((((((((((((((((((((((1 + ((((((((l(1 + (1 + (1 + (1 + (1 +
(1 + (((((((1 + (1 + ((((((((((((((((((((1 + (((l(1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 +
(1 + (1 + (1 + (1 + (1 + (1 + (1 + ((((((((((((((((1 + (((((((1 + ((((((((l(1 + (1 + (1 +
(1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 +
(1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (((1 + (((1 + ((((((
(1 + ((((((((((1 + (((((1 + ((l(1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 +
(1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 +
(1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (1 + (((((((((((1 + ((((1 + (
package main
import (
"fmt"
"math/rand"
"regexp"
"time"
)
func getRandomBytes(n uint32) []byte {
@yalue
yalue / deadwood.rb
Last active September 27, 2025 19:42
Gin rummy optimal meld finder and deadwood calculator in ruby
#!/usr/bin/ruby
#
# If you want to understand how this script works, I'd recommend starting to read it
# at the "entry point" where it starts validating and parsing the arguments---just
# look for the lines interacting with ARGV to get the initial list of cards. From
# there you can follow how it generates the full set of candidate melds (which may
# overlap) and then how it builds a "tree" where each path to a leaf node defines a
# non-overlapping set of melds.
usage = "deadwood.rb: