Skip to content

Instantly share code, notes, and snippets.

View BlueSolei's full-sized avatar
💭
C++ --> Web

Shaul Fridman BlueSolei

💭
C++ --> Web
  • Israel
View GitHub Profile
@BlueSolei
BlueSolei / some-script.sh
Last active July 18, 2022 18:51
.sh error handling
#!/usr/bin/env bash
# BASH error handling:
# if you run this script with 'set -x' the below line will remove all trap's line from the trace
exec 2> >(grep -E -v '\+\+ (CURRENT_COMMAND|LAST_COMMAND|ERROR_CODE=|FAILED_COMMAND=|tput setaf 1|tput sgr0)' >&2)
# exit on command failure
set -e
# keep track of the last executed command
trap 'LAST_COMMAND=$CURRENT_COMMAND; CURRENT_COMMAND=$BASH_COMMAND' DEBUG
# on error: print the failed command
@BlueSolei
BlueSolei / cmake-handle-generated-files.cmake
Created November 20, 2021 13:23
How to use cmake to depend on generated files
# ~~~
# Make the generated files depend on the grammer files
# PROBLEM: CMake is difficult in depending on generated files which are
# unknown in configure time. the antlr4 generated files (names and count) depend on the
# parameters & the files it is invoked with.
# SOLUTION: generate once, so we know exactly which files are generated.
# then, we depend on these files with add_custom_target()
# ~~~
message(
STATUS "Antlr4: generating parser for grammer '${ARG_NAME}' - first time")
@BlueSolei
BlueSolei / settings.json
Last active September 5, 2020 18:28
Windows Terminal settings
// This file was initially generated by Windows Terminal Preview 1.1.1812.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
"defaultProfile": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
// You can add more global application settings here.
git filter-branch --tree-filter 'clang-format -i $(\
git show $GIT_COMMIT --name-status | egrep ^[AM] |\
grep -e .cpp -e .h | cut -f2)' -- --all
@BlueSolei
BlueSolei / defer.hpp
Last active March 18, 2019 00:20
defer
#include <memory>
#include <cstdio>
template<typename F>
class defer_finalizer {
F f;
bool moved = false;
public:
template<typename T>
defer_finalizer(T && f_) : f(std::forward<T>(f_)) { }
@BlueSolei
BlueSolei / stl.natvis
Created June 21, 2017 17:54
Visual studio stl.natvis file
<?xml version="1.0" encoding="utf-8"?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
<!-- VC 2015 -->
<Type Name="std::_Compressed_pair&lt;*,*,1&gt;">
<DisplayString>{*($T1 *)this}</DisplayString>
<Expand>
<ExpandedItem>*($T1 *)this</ExpandedItem>
</Expand>
</Type>
@BlueSolei
BlueSolei / LikeConstVersion.h
Created May 18, 2017 17:30
LikeConstVersion
#pragma once
template <typename T>
struct NonConst
{
typedef T type;
};
template <typename T>
struct NonConst<T const>
{