Skip to content

Instantly share code, notes, and snippets.

View dmikushin's full-sized avatar
🤓

Dmitry Mikushin dmikushin

🤓
View GitHub Profile
@dmikushin
dmikushin / matrix_as_graph.ipynb
Created January 29, 2024 16:48 — forked from V0XNIHILI/matrix_as_graph.ipynb
Matrix multiplication in graph form
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@dmikushin
dmikushin / cppminify.py
Created January 2, 2024 12:24
Minify C++ code
import re
import sys
def minify_cpp_code(code):
# Remove comments:
# Turn single-line comments into multi-line comments
code = re.sub(re.compile(r'//(.*?)\n'), '/*\\1*/', code)
# Remove multi-line comments
code = re.sub(re.compile(r'/\*.*?\*/', re.DOTALL), '', code)
# Preprocessing directives must remain on separate lines.
@dmikushin
dmikushin / README.md
Created December 18, 2023 09:43
Example of using .branchtargets in PTX

Example of using .branchtargets in PTX

This code snippet demonstrates how to jump to a label by its index with brx.idx instruction.

Unlike the regular if (a == 2) { ... } else { ... } code (as well as switch (...) { ... }), the brx.idx solution avoids multiple setp.ne.s32 comparisons.

Building

> make
@dmikushin
dmikushin / match_nested.py
Created December 4, 2023 14:34
A simple python program showing how to use regular expressions to write a paren-matching recursive parser.
"""
A simple python program showing how to use regular
expressions to write a paren-matching recursive parser.
This parser recognises items enclosed by parens, brackets,
braces and <> symbols, but is adaptable to any set of
open/close patterns. This is where the re package greatly
assists in parsing.
Published by Gene Olson at
@dmikushin
dmikushin / mkimage_neo3-freebsd.sh
Created April 20, 2023 11:18
Make a FreeBSD bootable sdcard for NanoPi Neo3
#!/bin/bash
#
# Make a FreeBSD bootable sdcard for NanoPi Neo3.
# The idea is to mix an official ROCK64 snapshot with U-Boot for Neo3 board from Armbian project.
# This script is based on the original forum post at
# https://forums.FreeBSD.org/threads/nanopi-neo-3-rockchip-rk3328.76449/post-493043
#
set -e
if [[ $UID != 0 ]]; then
@dmikushin
dmikushin / migrate1.pl
Created January 26, 2023 09:52
Submodules batch migration scripts
# Clone all branches individually
my(@branches) = (
"eskew",
"combinations",
"distributed",
"earnest",
"emax",
"engine-hpc",
"engine-trivial",
@dmikushin
dmikushin / raspberryPiImageAutoShrinker.sh
Created January 24, 2023 14:03 — forked from free5ty1e/raspberryPiImageAutoShrinker.sh
Updated Raspberry Pi image auto shrinker script will shrink the ext4 filesystem down so you can restore the image on a smaller card
#!/bin/bash
# Automatic Image file resizer
# Written by SirLagz
# Fixed 2016.04.17 by @ChrisPrimeish
strImgFile=$1
if [[ ! $(whoami) =~ "root" ]]; then
echo ""
echo "**********************************"
echo "*** This should be run as root ***"
@dmikushin
dmikushin / raspberryPiImageAutoShrinker.sh
Created January 24, 2023 14:03 — forked from free5ty1e/raspberryPiImageAutoShrinker.sh
Updated Raspberry Pi image auto shrinker script will shrink the ext4 filesystem down so you can restore the image on a smaller card
#!/bin/bash
# Automatic Image file resizer
# Written by SirLagz
# Fixed 2016.04.17 by @ChrisPrimeish
strImgFile=$1
if [[ ! $(whoami) =~ "root" ]]; then
echo ""
echo "**********************************"
echo "*** This should be run as root ***"
@dmikushin
dmikushin / android-select-device
Last active September 15, 2021 17:30 — forked from dtmilano/android-select-device
Script to select one connected device or emulator when running ADB
#!/bin/bash
#=====================================================================
# Selects an android device
# Copyright (C) 2012-2020 Diego Torres Milano. All rights reserved.
#
# See:
# - http://dtmilano.blogspot.ca/2013/01/android-select-device.html
# - http://dtmilano.blogspot.ca/2012/03/selecting-adb-device.html
# for details on usage.
#=====================================================================
@dmikushin
dmikushin / earnestrank.cpp
Last active July 2, 2021 09:52
C++ implementation of an algorithm proposed by Mike Earnest on math.stackexchange
// Given all possible combinations of K values, each no greater than M, and whose sum is exactly N
// (zeros and different orderings are accounted, that is 1 + 4 and 4 + 1 are different combinations),
// for the known combination, reconstruct back its index (the order of enumeration does not matter).
//
// C++ implementation of an algorithm proposed by Mike Earnest.
//
// Compile: g++-11 earnestrank.cpp -o earnestrank
// Run: ./earnestrank
//
//