Skip to content

Instantly share code, notes, and snippets.

@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;
@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)
void decrypt(short* src, short* dest, int size)
{
int x=0xA2C2A, y=0;
for (int i = 0; i < size; ++i)
{
x = x*0x343FD + 0x269EC3;
y = x >> 0x10 & 0x7FFF;
dest[i] = src[i] ^ LOWORD(y);
}
}
@Trass3r
Trass3r / EnableVisualStudioProjectRebuildReasonLogging.reg
Created November 17, 2016 15:23
Get Visual Studio logging for 'fast up-to-date checker'
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\General]
"U2DCheckVerbosity"=dword:00000001
@Trass3r
Trass3r / CheckProjectFileHeadersExist.cs
Last active January 12, 2017 18:02
check vcxproj files for non-existent header files causing MSBuild to rebuild
using System;
using System.IO;
using System.Xml.Linq;
static class Program
{
static void check(string fileName)
{
XDocument project = XDocument.Load(fileName);
XNamespace msbuild = XNamespace.Get("http://schemas.microsoft.com/developer/msbuild/2003");
@Trass3r
Trass3r / VLDSnippet.cpp
Created January 18, 2017 12:48
quick and dirty VLD enable
#pragma comment(lib, "D:\\Visual Leak Detector\\lib\\Win64\\vld.lib")
#include <D:\Visual Leak Detector\include\vld.h>
static int dummy = (VLDSetReportOptions(VLD_OPT_REPORT_TO_FILE | VLD_OPT_UNICODE_REPORT, nullptr), 0);
@Trass3r
Trass3r / dl.py
Created February 4, 2017 13:08
download aerial imagery from Geoportal TH
import requests
from urllib.request import *
import sys
import os.path
def getDetails(type, id):
url = 'http://geoportal.geoportal-th.de/gaialight-th/_apps/dladownload/_ajax/details.php'
params = dict(
type = type,
id = id