Skip to content

Instantly share code, notes, and snippets.

View RicoP's full-sized avatar
🎯
Focusing

Rico P RicoP

🎯
Focusing
View GitHub Profile
@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 / 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 / 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 / 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) {
@RicoP
RicoP / RIP.bat
Created March 18, 2018 13:05
Rip Audio CD with VLC
@ECHO OFF
setlocal ENABLEDELAYEDEXPANSION
SET /a x=0
FOR /R H:\ %%G IN (*.cda) DO (CALL :SUB_VLC "%%G")
GOTO :eof
:SUB_VLC
@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;
(function () {
var links = document.getElementsByTagName("a")
var regex = /imgur.com.*gif$/ig
for(var i = 0; i != links.length; ++i) {
var href = links[i].href;
if(regex.test(href))
{
links[i].setAttribute('href', href + "v");
console.log(href)
/*
* 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;