Skip to content

Instantly share code, notes, and snippets.

View r-lyeh-archived's full-sized avatar

r-lyeh-archived

View GitHub Profile
/*(utf8)
1€ Filter, template-compliant version
Jonathan Aceituno <join@oin.name>
25/04/14: fixed bug with last_time_ never updated on line 40
For details, see http://www.lifl.fr/~casiez/1euro
*/
#include <cmath>
// a few color space conversions in c++11, original code by mjijackson.com
// - rlyeh, public domain licensed.
#include <tuple>
#include <algorithm>
#include <stdint.h>
std::tuple<float,float,float> rgb2hsl( float r, float g, float b ) { // ranges: input[0..255], output[0..1]
r /= 255, g /= 255, b /= 255;
float max = std::max(std::max(r, g), b), min = std::min(std::min(r, g), b);
float h, s, l = (max + min) / 2;
if( max != min ) {
/* Mike F */
#include <stdint.h>
void *memalign( int align, size_t size ) {
void *mem = malloc( size + (align-1) + sizeof(void*) );
if(!mem) return 0;
char *amem = ((char*)mem) + sizeof(void*);
amem += (align - ((uintptr_t)amem & (align - 1)) & (align-1));
((void**)amem)[-1] = mem;
/*
Testing read file speed for the three read functions from
http://cpp.indi.frih.net/blog/2014/09/how-to-read-an-entire-file-into-memory-in-cpp/
compile with -std=c++11
*/
#include <type_traits>
#include <ostream>
#include <sstream>
#include <string>
#include <iostream>
#include <utility>
void internal_func(const std::string& s)
{
std::cout << s << '\n';
}
template <typename ... T>
@r-lyeh-archived
r-lyeh-archived / variant2.hpp
Created April 19, 2016 11:47
another small variant class
// another small variant class
// - rlyeh, public domain
#pragma once
#include <string>
#include <sstream>
template< typename T >
inline T as( const std::string &self ) {
T t;
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main( int argc, const char **argv ) {
if( argc >= 3 ) {
float cycle = atof(argv[1]);
float distance = atof(argv[2]);
float excess = fmodf( distance, cycle );
@r-lyeh-archived
r-lyeh-archived / atf.hpp
Last active March 30, 2016 20:54
map<K,V> interpolator
// map<K,V> interpolator (requires keys and values with arithmetical operators)
// - rlyeh, public domain
#pragma once
#include <algorithm>
enum {
// supported easings
at_linear = 0,
at_quadinout = 1,
// default configuration (feel free to customize)
at_interpolator = at_quadinout,
@r-lyeh-archived
r-lyeh-archived / git-tips.md
Last active March 28, 2016 08:54
git-tips

Git tree command

git config --global alias.tree "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative"

git tree
* c3aee36 - (HEAD -> master, tag: DAY01, origin/master, origin/HEAD) '' (2 minutes ago) <r-lyeh>
* 5c978e9 - Initial commit (4 minutes ago) <r-lyeh>
// [ref] https://www.niksula.hut.fi/~hkankaan/Homepages/changeable%20colors.html
// This is my example picture. Now I want to make that red ball to be brown, green to be yellow and blue to be white. Notice that this picture also has antialiased lines.
//slide(x,y) means an array slide(from color,to color)
//these three lines make channel 0 (red channel) brown
//(172 red, 108 green and 48 blue equals brown)
slide(0,0) = 172
slide(0,1) = 108
slide(0,2) = 48