Skip to content

Instantly share code, notes, and snippets.

View gyakoo's full-sized avatar

Manu Marin gyakoo

View GitHub Profile
@gyakoo
gyakoo / min_max.hh
Created May 18, 2018 18:54 — forked from thomcc/min_max.hh
C++11 variadic max, min, and minmax implementations.
#pragma once
#include <utility>
// varidic max, min, and minmax implementation (named maximum, minimum and min_max to avoid confusion)
// no support for custom comparators (mainly because i'm not sure how they should be specified)
namespace detail {
// max base case
template <class T>
@gyakoo
gyakoo / lua_map.c
Created March 6, 2018 23:21 — forked from randrews/lua_map.c
Example of embedding Lua in C
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdlib.h>
int map_create(lua_State *lua);
int map_slice(lua_State *lua);
int main(int argc, char **argv){
lua_State *lua = lua_open();
@gyakoo
gyakoo / flip.py
Last active June 21, 2017 06:13
Python/Pygame script to flip an image X or Y by Rects and save to disk
import pygame
import sys
def surfaceFlip(img,w,h, fx, fy):
r = img.get_rect()
target = pygame.Surface( r.size, 0, img )
tmp = pygame.Surface( (w,h), 0, img)
ix, iy = r.width/w, r.height/h
dst = pygame.Rect(0,0,w,h)
r.topleft = (0,0)
// lib /def:user32.def
// cl /O2 test.cpp /link user32.lib
#include <Windows.h>
#include <stdio.h>
struct PrecisionTouchPadConfig {
BYTE LegacyParams[3];
BOOL LoadedSettings;
// 0: No delay (always on)
@gyakoo
gyakoo / preprocessor_fun.h
Created January 23, 2017 20:52 — forked from aras-p/preprocessor_fun.h
Things to commit just before leaving your job
// Just before switching jobs:
// Add one of these.
// Preferably into the same commit where you do a large merge.
//
// This started as a tweet with a joke of "C++ pro-tip: #define private public",
// and then it quickly escalated into more and more evil suggestions.
// I've tried to capture interesting suggestions here.
//
// Contributors: @r2d2rigo, @joeldevahl, @msinilo, @_Humus_,
// @YuriyODonnell, @rygorous, @cmuratori, @mike_acton, @grumpygiant,
@gyakoo
gyakoo / ReadEntireFileFromPath_uwp.cpp
Last active January 23, 2017 20:53
Reading an entire file into memory in UWP in an (permission-granted) path.
// This code is WIP and does not reflect the final one, but gets a rough idea on how to use continuation
// task for exception catching when workin with Async operations
inline concurrency::task<std::vector<byte>> ReadEntireFileFromPath(const std::wstring& filename)
{
using namespace Windows::Storage;
using namespace Windows::Foundation;
using namespace Concurrency;
auto taskFileFromPath = create_task(StorageFile::GetFileFromPathAsync(Platform::StringReference(filename.c_str())));
return taskFileFromPath.then([](task<StorageFile^> tfile)
@gyakoo
gyakoo / Fxaa3_11.h
Created December 8, 2016 23:20
NVIDIA FXAA 3.11 by TIMOTHY LOTTES
/*============================================================================
NVIDIA FXAA 3.11 by TIMOTHY LOTTES
------------------------------------------------------------------------------
COPYRIGHT (C) 2010, 2011 NVIDIA CORPORATION. ALL RIGHTS RESERVED.
------------------------------------------------------------------------------
TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, THIS SOFTWARE IS PROVIDED
@gyakoo
gyakoo / tilt.shift.glsl
Created November 22, 2016 22:57 — forked from ruby0x1/tilt.shift.glsl
Tilt shift shader, modified from something @grapefrukt gave me
// Modified version of a tilt shift shader from Martin Jonasson (http://grapefrukt.com/)
// Read http://notes.underscorediscovery.com/ for context on shaders and this file
// License : MIT
uniform sampler2D tex0;
varying vec2 tcoord;
varying vec4 color;
/*
Take note that blurring in a single pass (the two for loops below) is more expensive than separating
@gyakoo
gyakoo / clipboard_w32.cpp
Created October 19, 2016 17:12
Simple snippet to recall how you copy/paste *text* to/from clipboard in c++ win32
// ------- COPY
{
char some[256]; // your text here, zero ended
OpenClipboard(GetDesktopWindow());
EmptyClipboard();
HGLOBAL hg=GlobalAlloc(GMEM_MOVEABLE,ARRAYSIZE(some)+1);
if (!hg)
{
CloseClipboard();
return;
@gyakoo
gyakoo / cpp_test_concurrency_min.cpp
Created October 18, 2016 22:37
Profile 'min' search using sequential, parallel_for_each, combinable and atomic in a concurrent_vector
// The following test measures time to find the minimum value in a huge array using:
// sequential
// parallel_for_each
// parallel_for_each + combinable<>
// VS2015 Update 3
static char toClearCache[256 << 20]; //try to flush!?
static void clearCache()
{