Skip to content

Instantly share code, notes, and snippets.

@Trass3r
Trass3r / gist:6713302
Created September 26, 2013 12:13
quickly dump OpenGL texture
glBindTexture(GL_TEXTURE_2D, textureID);
glPixelStorei(GL_PACK_ALIGNMENT, 1);
GLint width, height, level = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_WIDTH, &width);
glGetTexLevelParameteriv(GL_TEXTURE_2D, level, GL_TEXTURE_HEIGHT, &height);
std::unique_ptr<unsigned short[]> data(new unsigned short[width * height]);
glGetTexImage(GL_TEXTURE_2D, level, GL_RED, GL_UNSIGNED_SHORT, data.get());
glPixelStorei(GL_PACK_ALIGNMENT, 4);
@Trass3r
Trass3r / gist:8774345
Created February 2, 2014 20:22
C++ Ranges
#include <cstdint>
#include <iostream>
template <typename T>
class DInputRange
{
public:
struct iterator
{
const T* r;
{
connect(ui.actionDarkOrangeTheme, &QAction::triggered, this, &MainWindow::activateDarkOrangeTheme);
connect(ui.actionDarkFusionTheme, &QAction::triggered, this, &MainWindow::activateDarkFusionTheme);
}
#include <QStyleFactory>
#define raw(...) #__VA_ARGS__
#pragma region qss
@Trass3r
Trass3r / FlattenedRange.cpp
Last active August 29, 2015 14:10
fun with range templates
#include <type_traits>
//! range spanned by 2 iterators
template <typename Iterator>
struct IteratorRange
{
IteratorRange(Iterator begin, Iterator end)
: _begin(std::move(begin)),
_end(std::move(end))
{
@Trass3r
Trass3r / range_zip
Created May 18, 2015 10:49
C++ range zip
#include <boost/iterator/zip_iterator.hpp>
#include <boost/range.hpp>
template <typename... T>
auto zip(T&&... containers) -> boost::iterator_range < boost::zip_iterator<decltype(boost::make_tuple(std::begin(containers)...))> >
{
auto&& zip_begin = boost::make_zip_iterator(boost::make_tuple(std::begin(containers)...));
auto&& zip_end = boost::make_zip_iterator(boost::make_tuple(std::end(containers)...));
return boost::make_iterator_range(zip_begin, zip_end);
}
@Trass3r
Trass3r / devirtualization list
Created June 4, 2015 08:26
list top gcc devirtualization warnings
cat build.log | fgrep suggest-final | sed -r 's/.+Declaring (.+) final [^0-9]+([0-9]+) calls?.+/\2 \1/g' | sort -k1,1 -nr | head -n25
@Trass3r
Trass3r / cudamem.h
Created August 19, 2015 16:41
CUDA simple memory wrapper class
template <typename T>
struct CUDAMem
{
T* ptr;
CUDAMem()
: ptr(0)
{
cudaError_t err = cudaMallocArray(&ptr, sizeof(T));
if (err != cudaSuccess)
@Trass3r
Trass3r / git-magic.sh
Last active November 28, 2017 14:16
git magic
# merge into subdir
git config --global mergeintosubdirectory "!sh -c 'git merge -s ours --no-commit $1 && git read-tree --prefix=$2 -u $1 && git status' -"
# fix line endings
# use RAM disk since this is slow
# added benefit of creating .gitattributes in the first commit
FASTDISKWORKDIR=$TEMP/workdir
time git filter-branch -d "$FASTDISKWORKDIR" -f --tree-filter "echo '* text=auto' > .gitattributes && rm $FASTDISKWORKDIR/index && git reset && git add -u" --tag-name-filter cat --prune-empty -- --all
# rewrites with commands other than filter-branch alter the committers
@Trass3r
Trass3r / svn2git.sh
Last active December 5, 2017 14:24
svn to git conversion steps
#git conversion:
# init: see 'subgit help configure'
subgit configure --layout auto -T trunk/Project http:/baseurl... FooSubGit
# edit FooSubGit/subgit/config and authors.txt
# in particular take care of
#[svn]
# url = http:/.../trunk/...
# trunk = :refs/heads/master
# # Note: if repos have been moved around you can define the old locations as branches and subgit will connect the dots!
@Trass3r
Trass3r / test.sh
Last active July 20, 2021 16:55
Generate compile_commands.json from MSBuild
# first rebuild solution
# then
echo '[' > compile_commands.json
find obj/v140/x64/Debug/ -name 'CL.command.*' | xargs iconv -f utf-16 -t utf-8 | grep -hF '/c' | sed -r -e 's#\\#/#g' -e 's/"/\\"/g' -e 's#/c .+ ((.:/.+)/[^/]+\.[^/]*)$#{\r\n\t"command": "clang-cl.exe -m64 --driver-mode=cl \0 -Wno-error",\r\n\t"file": "\1",\r\n\t"directory": "\2"\r\n},#g' >> compile_commands.json
echo ']' >> compile_commands.json
# example use
"C:\Program Files\Git\usr\bin\find.exe" src -name "*.cpp" | "C:\Program Files\Git\usr\bin\xargs.exe" -n1 -P1 -t "C:\Program Files\LLVM\bin\clang-check.exe" -p . -fixit
find src -name '*.cpp' | xargs -n1 -P1 -t 'C:\Program Files\LLVM\bin\clang-tidy.exe' -p . -header-filter=.* -fix -checks=cppcoreguidelines-pro-type-member-init