Skip to content

Instantly share code, notes, and snippets.

View mosra's full-sized avatar

Vladimír Vondruš mosra

View GitHub Profile
@mosra
mosra / bt.sh
Last active November 6, 2024 20:10
Print a backtrace of the last failed command
#!/bin/bash
# Save into /usr/local/bin/bt and make the file executable. On Ubuntu you may
# need to additionally perform the following:
#
# sudo apt install systemd-coredump
#
# Calling `bt` then non-interactively prints a backtrace of last program that
# exited with a SIGABRT or SIGSEGV. Makes use of systemd's builtin coredumpctl,
# causes no core files littered around on the filesystem.
@mosra
mosra / README.md
Last active October 9, 2024 03:47 — forked from ColCh/README.md
Git pre-push hook to confirm pushing to master

Git pre-push hook

Checks if the remote branch is master, then asks a confirmation. Based on https://gist.github.com/ColCh/9d48693276aac50cac37a9fce23f9bda, but modified to check the remote name instead of local, making it work also for the really dangerous accidents like below:

git push -f origin e09b7418a310114f6aaf495f969c3859095a99af:master

Further info: https://dev.ghost.org/prevent-master-push/, https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook, https://git-scm.com/docs/githooks#_pre_push, https://stackoverflow.com/questions/22585091/git-hooks-pre-push-script-does-not-receive-input-via-stdin

// g++ -std=c++11 sdl-setwindowtitle.cpp -lSDL2
#include <SDL2/SDL.h>
int main() {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* w = SDL_CreateWindow(
/* If you flip this, SDL_SetWindowTitle() below starts working */
#if 1
@mosra
mosra / main.cpp
Created March 21, 2019 07:24
Triangle, but windowless
#include <Magnum/DebugTools/Screenshot.h>
#include <Magnum/GL/Buffer.h>
#include <Magnum/GL/Framebuffer.h>
#include <Magnum/GL/Mesh.h>
#include <Magnum/GL/Renderbuffer.h>
#include <Magnum/GL/RenderbufferFormat.h>
#ifdef MAGNUM_TARGET_HEADLESS
#include <Magnum/Platform/WindowlessEglApplication.h>
#elif defined(CORRADE_TARGET_IOS)
#include <Magnum/Platform/WindowlessIosApplication.h>
@mosra
mosra / main.cpp
Last active February 24, 2019 12:20
First Triangle in Vulkan
#include <Corrade/Utility/Assert.h>
#include <Corrade/PluginManager/Manager.h>
#include <Magnum/Magnum.h>
#include <Magnum/ImageView.h>
#include <Magnum/PixelFormat.h>
#include <Magnum/Math/Color.h>
#include <Magnum/Trade/AbstractImageConverter.h>
#include <MagnumExternal/Vulkan/flextVk.h>
#include <MagnumExternal/Vulkan/flextVkGlobal.h>
@mosra
mosra / diff.patch
Created October 18, 2016 20:27
Quick'n'dirty NV conservative raster support
diff --git a/src/MagnumExternal/OpenGL/GL/extensions.txt b/src/MagnumExternal/OpenGL/GL/extensions.txt
index 82b268d..18e158d 100644
--- a/src/MagnumExternal/OpenGL/GL/extensions.txt
+++ b/src/MagnumExternal/OpenGL/GL/extensions.txt
@@ -34,3 +34,5 @@ extension KHR_texture_compression_astc_hdr optional
extension KHR_blend_equation_advanced optional
extension KHR_blend_equation_advanced_coherent optional
extension KHR_no_error optional
+
+extension NV_conservative_raster optional
@mosra
mosra / README.md
Created May 25, 2015 08:43
Voldemort types in C++14

Inspired with real D language feature: http://wiki.dlang.org/Voldemort_types

Compile in GCC/Clang with -std=c++14.

#include <iostream>
#include <typeinfo>

auto eh() {
	struct Voldemort {
@mosra
mosra / constexpr.md
Last active August 29, 2015 14:01
Compile-time matrix/vector computations in Magnum

Magnum now has compile-time matrix/vector library. With full C++14 support in Clang 3.4 you can throw out nearly all manual precomputations, just slap constexpr on the result and be done with it:

#include <Magnum/Magnum.h>
#include <Magnum/Math/Matrix4.h>

using namespace Magnum;

int main() {
 constexpr auto a = Matrix4::scaling(Vector3::xScale(3.0f))*
@mosra
mosra / README.md
Last active December 17, 2017 15:57
cosi, minimal stuff for easier soci + picojson usage

Usage

First, create the named tuple from list of cosi::field instances. First parameter is name in resulting JSON, second is optional field name in SQL query. If not used, the same name is used for both JSON and SQL.

auto t = cosi::make(
    cosi::string_f  {"data"},
    cosi::int_f     {"integerData", "COUNT(data)"},
    cosi::double_f  {"moreData", "another_table.data"}

);

@mosra
mosra / CMakeLists.txt
Created November 1, 2013 10:58
Very simple 2D scenegraph example. Based on `scenegraph2D` branch of https://github.com/mosra/magnum-bootstrap and `triangle` example at https://github.com/mosra/magnum-examples.
find_package(Magnum REQUIRED
SceneGraph
Shaders
Sdl2Application)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CORRADE_CXX_FLAGS}")
include_directories(${MAGNUM_INCLUDE_DIRS} ${MAGNUM_APPLICATION_INCLUDE_DIRS})
add_executable(MyApplication MyApplication.cpp)
target_link_libraries(MyApplication