Skip to content

Instantly share code, notes, and snippets.

View jbosboom's full-sized avatar

Jeffrey Bosboom jbosboom

  • 15:30 (UTC -07:00)
View GitHub Profile
package com.jeffreybosboom.stringbuilderbench;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.State;
@State(Scope.Thread)
public class StringBuilderBench {
//promote to non-final fields to inhibit constant folding (see JMHSample_10_ConstantFold.java)
private String really = "really ", long_string = "long string.", re = "re", al = "al", ly = "ly ";
@jbosboom
jbosboom / RemoveUnusedPrivateCtors.java
Created May 10, 2015 02:05
Removes unused private constructors from .class files
/*
* Copyright (c) 2015 Jeffrey Bosboom
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@jbosboom
jbosboom / ConstantPoolSortingClassWriter.java
Last active June 14, 2019 04:49
ASM constant pool sorter
/***
* Copyright (c) 2015 Jeffrey Bosboom
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
@jbosboom
jbosboom / gtest-to-doctest.py
Created August 30, 2020 21:44
Convert gtest macros to doctest macros
#!/usr/bin/env python2
import sys, os, re
conversions = [
('<gtest/gtest.h>', '<doctest.h>'),
(r'TEST\(([a-zA-Z0-9]+), ([a-zA-Z0-9]+)\)', r'TEST_CASE("\1_\2")')
]
severity_map = {'ASSERT': 'REQUIRE', 'EXPECT': 'CHECK'}
@jbosboom
jbosboom / papergen.py
Created August 30, 2020 21:45
Generates landscape ruled paper
#!/usr/bin/env python2
margin = 0.375
lineheight = (8.5 - 2*margin)/25
linewidth = 11 - 2*margin
midgutter = 11.0/2
ypts = [(margin, midgutter-(margin/2)), (midgutter+(margin/2), 11.0 - margin)]
color = '#A4DDED'
thickness = 1.0/64
@jbosboom
jbosboom / approx-rename.py
Created August 30, 2020 21:46
Approximate file renaming script
#!/usr/bin/env python2
import sys, os, shutil, argparse, string, readline
from fuzzywuzzy import process
parser = argparse.ArgumentParser()
parser.add_argument('directory', type=str)
parser.add_argument('namelist', type=argparse.FileType(mode='r'))
# TODO: option to include extension in renaming?
args = parser.parse_args()
@jbosboom
jbosboom / lmdb-bench.cpp
Created August 30, 2020 21:48
LMDB benchmark testing sorted vs unsorted insert order for a hashtable
#include "precompiled.hpp"
#include "stopwatch.hpp"
#include "lmdb++.h"
int main() { //genbuild {'entrypoint': True, 'ldflags': '-llmdb'}
lmdb::env env = lmdb::env::create();
env.set_mapsize(1UL * 1024 * 1024 * 1024 * 1024);
env.set_max_dbs(64);
env.open(std::string("/home/jbosboom/scratch/benchmark.mdb").c_str(), MDB_NORDAHEAD); //TODO: flags?
#!/usr/bin/env python3
import sys, os
samples = 100
sample_size = 25 * 1024 * 1024
with open(sys.argv[1], 'rb') as input, open(sys.argv[2], 'w+b') as output:
total_size = os.fstat(input.fileno()).st_size
sampled_size = samples * sample_size
#!/usr/bin/env python3
import pickle, io, collections, sys
x = collections.deque()
x.append(10)
x.append(3.14)
x.append(10000000000000)
x.append((1, 2, 3))
x.append([1, 2, 3])
@jbosboom
jbosboom / partial-clone-sparse-checkout-bare-repository.md
Last active May 29, 2021 08:17
Simulating sparse checkout in a partial clone bare repository

Simulating sparse checkout in a partial clone bare repository

Background

Partial clone is a git feature allowing a local repository to contain only a subset of a remote repository's trees and blobs, fetching missing objects lazily. Sparse checkout is a separate git feature allowing a working tree to contain only a subset of the files tracked by the repository. Used together, partial clone and sparse checkout allow working with large multi-project repositories ("monorepos") and repositories containing large binary files without having to download and store a full copy of the data in the repository. (Shallow clone is a distinct git feature that limits the commits stored in the local repository.)

For example, consider jbosboom/test-partial-clone-sparse-checkout, which tracks a few text files and some large images. If we want to work on the text files, but don't need the images, we can avoid downloading and storing them in our local rep