Skip to content

Instantly share code, notes, and snippets.

View RicoP's full-sized avatar
🎯
Focusing

Rico P RicoP

🎯
Focusing
View GitHub Profile
/*
* Coroutines.
*
* To make a (fake) coroutine we use these macros. A coroutine method must be static,
* return bool and needs a parameter (Generator & generator).
*
* Generator must follow this schema:
* struct Generator {
* int line;
* float time;
@RicoP
RicoP / defer.h
Created September 2, 2018 12:04
defer macro
//from https://pastebin.com/3YvWQa5c
#define CONCAT_INTERNAL(x,y) x##y
#define CONCAT(x,y) CONCAT_INTERNAL(x,y)
template<typename T>
struct ExitScope {
T lambda;
ExitScope(T lambda):lambda(lambda){}
~ExitScope(){lambda();}
@RicoP
RicoP / repeat.h
Created August 7, 2022 11:38
fast repeat
#pragma once
inline float repeat(float v, float min, float max)
{
v -= min;
v *= 1.0f / (max - min);
v -= (float)(int)(v);
v += 1.0f;
v -= (float)(int)(v);
@RicoP
RicoP / main.cpp
Created February 23, 2021 11:15
Get random template paramter
#include <cstdlib>
#include <ctime>
template<typename Head, typename... Tail>
constexpr int count_template_parameter(const Head &) {
return 1;
}
template<typename Head, typename... Tail>
constexpr int count_template_parameter(const Head &, const Tail & ...tail) {
@RicoP
RicoP / midi.cpp
Last active March 11, 2020 17:47
A minimal MIDI keyboard interface for windows.
#include <Windows.h>
#include <iostream>
#include <conio.h> // _getch
#pragma comment(lib, "winmm.lib")
HMIDIOUT omidi;
HMIDIIN imidi;
void CALLBACK MidiInProc(HMIDIIN hMidiIn, UINT wMsg, DWORD dwInstance, DWORD dwParam1, DWORD dwParam2)
@RicoP
RicoP / block.js
Last active May 31, 2019 09:24
youtube mini ad block (When you don't want to use ad block, but still don't want to manually click the close button for the ad)
// ==UserScript==
// @name youtube mini ad block
// @namespace Violentmonkey Scripts
// @grant none
// @include https://www.youtube.com/*
// ==/UserScript==
var started = false;
var adWholeTime = 0;
@RicoP
RicoP / gist:7357080
Last active May 1, 2019 00:02
NES Rescources
http://www.6502.org/tutorials/6502opcodes.html
http://www.thealmightyguru.com/Games/Hacking/Wiki/index.php?title=6502_Opcodes
http://nesdev.com/6502.txt
http://mystuffisallhere.com/blog/post/2008/08/24/Page-boundary-crossings-on-the-6502.aspx
@RicoP
RicoP / btnd.lua
Last active December 11, 2018 15:33
-- helper function for buttons state
-- call btn_update ONCE per update
-- btnd returns true once the button is pressed down
-- btnu returns true when the button is released
do
local state = {0,0,0,0,0,0}
-- call this in _update!
btn_update=function ()
for b=0,6 do
@RicoP
RicoP / server.sh
Created June 5, 2012 10:32
simple server script
#!/bin/sh
#copy directly into /usr/bin
if [ -s /tmp/__pserver ]; then
kill `cat /tmp/__pserver`
fi
python -m SimpleHTTPServer 1>>/dev/null 2>>/tmp/log.pserver &
echo -n $! > /tmp/__pserver
@RicoP
RicoP / strexpr.h
Created July 11, 2018 10:28
check string equality with const expressions [c++11]
constexpr bool constStringEquals(const char * lhs, const char * rhs) {
return (*lhs) != (*rhs)
? false
: ((*lhs) == 0
? true
: constStringEquals(lhs + 1, rhs + 1)
);
}
constexpr bool constStringEndsWith(const char * str, const char * suffix) {