Skip to content

Instantly share code, notes, and snippets.

View Trass3r's full-sized avatar

Trass3r Trass3r

View GitHub Profile

Base idea:

  • readable, maintainable, reusable code

C/C++:

  • no copy-paste excesses
    • use variables
    • use functions
  • use functions instead of abusing function macros
  • use enums and constants instead of abusing #defines
  • use stdint.h or similar typedefs as appropriate
@Trass3r
Trass3r / CoverageToTeamCity.xslt
Last active September 12, 2017 13:58
OpenCppCoverage for TeamCity
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="text" encoding="utf-8"/>
<xsl:variable name='nl'>
<xsl:text>&#xa;</xsl:text>
</xsl:variable>
<xsl:template match="/">
@Trass3r
Trass3r / TeamCity C++ Builds.bat
Last active April 18, 2018 11:26
with coverage, warnings
@echo off
%~d0
cd %~dp0
msbuild /nologo /nr:false /m /p:Configuration="%build.buildconfig%" /p:Platform=x64 /fl /flp:logfile=BuildWarnings.txt;warningsonly
set warningCount=0
for /F %%%%a in ('findstr "." BuildWarnings.txt') do (set /A warningCount=warningCount+1)
echo ##teamcity[buildStatus text='{build.status.text}; Build warnings: %%warningCount%%']
echo ##teamcity[buildStatisticValue key='buildWarnings' value='%%warningCount%%']
# put generated files into a separate VS folder
source_group("Generated Files" "(qrc_.+\\.cpp)|(.+_automoc\\.cpp)|(ui_.+\\.h)")
# for finding generated headers in CMAKE_CURRENT_BINARY_DIR
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# run moc automatically when needed
set(CMAKE_AUTOMOC ON)
# imported targets are created for each Qt module
find_package(Qt5Widgets)
@Trass3r
Trass3r / fastsincos.jl
Created November 29, 2017 16:26
vectorizable sincos
function sine(x)
x2 = x.*x
return x .* (1.5707963235 - 0.645963615 * x2 + 0.0796819754 * x2 .* x2 - 0.0046075748 * x2 .* x2 .* x2)
end
function cose(x)
x2 = x.*x
return 1 - 1.2336977925 * x2 + 0.2536086171 * x2 .* x2 - 0.0204391631 * x2 .* x2 .* x2
end
#ifdef _WIN32
#include <wincon.h>
#include <cstring>
#endif
static void setupUtf8Console()
{
#ifdef _WIN32
// set UTF8 code page
private static IEnumerable<SP_DEVINFO_DATA> GetDeviceInfoData(SafeDeviceInfoSetHandle devInfoSet)
{
var did = default(SP_DEVINFO_DATA);
uint didSize = (uint)Marshal.SizeOf(did);
did.cbSize = didSize;
uint index = 0;
while (SetupDiEnumDeviceInfo(devInfoSet, index, ref did))
{
yield return did;
++index;
#!/bin/bash
#set -x
# internal field separator
IFS=$'\n';
# list objects by size
if [ -d .git ]; then
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -v chain | sort -k3nr | head -n500`
elif [ -d objects ]; then
// C#:
// var serialPort = new SerialPort("COM7", 115200, Parity.None, 8, StopBits.One);
// serialPort.Open();
// Console.Write(serialPort.ReadChar());
// C++:
#include "clara.hpp"
#include <windows.h>
@Trass3r
Trass3r / xbootmgr.bat
Last active October 2, 2022 21:08
profile boot sequence
%~d0
cd %~dp0
REM -trace rebootCycle may also be useful
REM Base = PROC_THREAD+LOADER+DISK_IO+HARD_FAULTS+PROFILE+MEMINFO+MEMINFO_WS
REM FileIO = PROC_THREAD+LOADER+DISK_IO+HARD_FAULTS+FILE_IO+FILE_IO_INIT
xbootmgr -trace boot -traceFlags Base+Latency+DISPATCHER+FileIO+CSWITCH+PROFILE+DISK_IO_INIT -postBootDelay 100 -stackWalk Profile+ProcessCreate+CSwitch+ReadyThread+Mark+SyscallEnter+ThreadCreate
REM xperf -merge oldtrace.etl newtrace.etl -compress
pause