Skip to content

Instantly share code, notes, and snippets.

@hb3p8
hb3p8 / pattern.hpp
Created April 28, 2016 07:27
C++14 pattern matching
/*
std::string s = "12";
cout << match(s
,[](int& i) { return "int"; }
,[](bool& b) { return "bool"; }
,[](std::string& s) -> auto& { s += " GAV"; return s; }
,[](auto j) { cout << "default one"; return j; }
);
*/
float aProgress = 0.0;
while (aProgress < 1.0) {
int aBarWidth = 70;
std::cout << "[";
int aPos = (int) (aBarWidth * aProgress);
for (int i = 0; i < aBarWidth; ++i) {
if (i < aPos) std::cout << "=";
else if (i == aPos) std::cout << ">";
else std::cout << " ";
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
# Copyright (c) 2015, Nicolas P. Rougier. All Rights Reserved.
# Distributed under the (new) BSD License.
# -----------------------------------------------------------------------------
# This is a python implementation of the "Weighted Blended Order-Independent
# Transparency" technique by Morgan McGuire and Louis Bavoil
#
# This implementation use the glumpy python framework available from:

Warning: the following will delete all your containers and all your images. Make sure that you backup any precious data!

Remember what we said above: Docker will create the data and metadata files if they don’t exist. So the solution is pretty simple: just create the files for Docker, before starting it!

  • Stop the Docker daemon, because we are going to reset the storage plugin, and if we remove files while it is running, Bad Things Will Happen©.
  • Wipe out /var/lib/docker. Warning: as mentioned above, this will delete all your containers all all your images.
  • Create the storage directory: mkdir -p /var/lib/docker/devicemapper/devicemapper.
  • Create your pool: dd if=/dev/zero of=/var/lib/docker/devicemapper/devicemapper/data bs=1G count=0 seek=250 will create a sparse file of 250G. If you specify bs=1G count=250 (without the seek option) then it will create a normal file (instead of a sparse file).
const size_t MAX_SIZE = 1<<24;
char* binary = new char[MAX_SIZE];
GLenum format;
GLint length;
theGlContext->core44->glGetProgramBinary (myRaytraceProgram->ProgramId(), MAX_SIZE, &length, &format, binary);
std::ofstream file ("D:/asm.bin", ios::out | ios::binary );
file.write (binary, length);
file.close();
else if (aData.x < 0) // leaf node (containg triangles)
{
ivec4 aTrg0 = texelFetch (uGeometryTriangTexture, (aData.y + 0) + TRG_OFFSET (aSubTree));
ivec4 aTrg1 = texelFetch (uGeometryTriangTexture, (aData.y + 1) + TRG_OFFSET (aSubTree));
ivec4 aTrg2 = texelFetch (uGeometryTriangTexture, (aData.y + 2) + TRG_OFFSET (aSubTree));
ivec4 aTrg3 = texelFetch (uGeometryTriangTexture, (aData.y + 3) + TRG_OFFSET (aSubTree));
vec3 aTrg0Vrt0 = texelFetch (uGeometryVertexTexture, aTrg0.x += VRT_OFFSET (aSubTree)).xyz;
vec3 aTrg0Vrt1 = texelFetch (uGeometryVertexTexture, aTrg0.y += VRT_OFFSET (aSubTree)).xyz;
vec3 aTrg0Vrt2 = texelFetch (uGeometryVertexTexture, aTrg0.z += VRT_OFFSET (aSubTree)).xyz;
struct Noise3D
{
static const int size = 8;
sf::mesh::RealVector3 gradients[size][size][size];
float Drop(float dist)
{
float val = fabs (dist);
{
"keys": ["ctrl+alt+w"],
"command": "reopen", "args": {"encoding": "Cyrillic (Windows 1251)" }
},
@hb3p8
hb3p8 / text-textinput.cpp
Created December 22, 2016 08:13
Question regarding custom UnformatedText-like widget implementation #949
// Create text input in place of a text
static void TextAsWidgetReplacement(const ImRect& aabb, const char* label, ImGuiID id)
{
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow();
// Our replacement widget will override the focus ID (registered previously to allow for a TAB focus to happen)
SetActiveID(g.ScalarAsInputTextId, window);
SetHoveredID(0);
FocusableItemUnregister(window);
@hb3p8
hb3p8 / getBufferSubData.cpp
Created April 19, 2017 11:21
getBufferSubData for Emscripten
int size = ...
void* data = new char[size];
EM_ASM_(
{
Module.ctx.getBufferSubData(Module.ctx.ARRAY_BUFFER, 0, HEAPU8.subarray($0, $0 + $1));
}, data, size);