Skip to content

Instantly share code, notes, and snippets.

@cbarraco
cbarraco / BenchmarkDotnetDiscovery.cs
Last active November 7, 2024 18:52
Discovers all classes in the assembly that have [Benchmark] attributes and runs them with BenchmarkRunner (BenchmarkDotNet)
static Type[] GetAllTypesThatHaveBenchmarkMethods()
{
return Assembly.GetExecutingAssembly().GetTypes().Where(
type => type.GetMethods().Any(
method => method.GetCustomAttributes(typeof(BenchmarkAttribute)).Any()
)
).ToArray();
}
var benchmarkTypes = GetAllTypesThatHaveBenchmarkMethods();
@cbarraco
cbarraco / fast-robocopy-mirror.ps1
Last active May 31, 2024 22:27
Robocopy mirror optimized for speed
# use /MT:1 when the files are big, otherwise if you cancel you'll have 128 big unfinished files instead of a few finished ones
Robocopy.exe /MIR /MT:128 /R:1 /W:1 /LOG:nul /NFL /NDL /NJH /NJS /nc /ns /np <SRC> <DEST>
@cbarraco
cbarraco / download-docker
Created March 2, 2019 21:02
Direct download link for Docker for Windows without signing in
https://download.docker.com/win/stable/Docker%20for%20Windows%20Installer.exe
@cbarraco
cbarraco / gradle.properties
Created February 25, 2019 03:19
Gradle build optimization for compiling Android apps
// Add this in your global gradle.properties file
// at ~/.gradle/gradle.properties
// Enable Gradle Daemon
org.gradle.daemon=true
// Enable Configure on demand
org.gradle.configureondemand=true
//Enable parallel builds
org.gradle.parallel=true
// Enable Build Cache
android.enableBuildCache=true
@cbarraco
cbarraco / install-latest-cmake.sh
Last active January 29, 2019 15:28
Downloads, compiles, and installs the latest version of CMake. Replace 4 with however many CPU cores the machine has. If using the Raspberry Pi, use 2 instead of 4 because you may run out of memory.
git clone https://github.com/Kitware/CMake.git
cd CMake
./bootstrap --parallel=4
make -j 4
sudo make install
<Target Name="NSwag Debug" AfterTargets="Build" Condition="'$(Configuration)'=='DEBUG'">
<Exec Command="$(NSwagExe) run Debug.nswag" />
</Target>
<Target Name="NSwag Release" AfterTargets="Build" Condition="'$(Configuration)'=='RELEASE'">
<Exec Command="$(NSwagExe) run Release.nswag" />
</Target>
@cbarraco
cbarraco / Open bash shell here.reg
Created October 14, 2017 20:04
Add an explorer context menu item for opening a bash for windows shell in the current directory
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash]
@="Open bash shell here"
"Icon"="%USERPROFILE%\\AppData\\Local\\lxss\\bash.ico"
[HKEY_CLASSES_ROOT\Directory\Background\shell\bash\command]
@="C:\\Windows\\System32\\bash.exe"
@cbarraco
cbarraco / exception_signal_handler.c
Created October 7, 2016 15:11
Registers a signal handler that handles exceptions by outputting the program backtrace. Use with the debug flag to include line numbers.
#include <execinfo.h>
#include <stdio.h>
#include <signal.h>
/**
* Outputs the backtrace if the application crashes
* @param signal The signal that was sent when the application crashed
*/
void exception_signal_handler(int signal) {
const int num_backtraces = 20;
@cbarraco
cbarraco / stackoverflow-line-numbers.js
Last active September 9, 2016 21:20
Adds line numbers to code on stackoverflow.com
var code_blocks = $("pre > code");
code_blocks.prepend("1\t");
for (var b = 0; b < code_blocks.length;b++) {
var newlines = $(code_blocks[b]).find("span.pln");
var c = 1;
for (var i=0;i < newlines.length;i++) {
newlines[i].innerHTML = newlines[i].innerHTML.replace(/(?:\r\n|\r|\n)/g, function(x) {
return "\n" + ++c + "\t";
});
}
adb shell "run-as package.name chmod 666 /data/data/package.name/databases/file"
adb pull /data/data/package.name/databases/file .
adb shell "run-as package.name chmod 600 /data/data/package.name/databases/file"