This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef DATA_STACK_H // Include guard | |
#define DATA_STACK_H | |
#include <stdlib.h> // size_t, NULL, malloc, free | |
// Stack node | |
typedef struct data_stack_node{ | |
void* data; // Userdata | |
size_t data_len; // Userdata byte length | |
struct data_stack_node* prev; // Reference to previous node |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Frequency analyzer | |
local function goertzel(samples, sample_rate, freq) | |
-- Get coefficient from target and maximal frequency | |
local coeff = 2 * math.cos(2 * math.pi * freq / sample_rate) | |
-- Process samples | |
local s_prev, s_prev2, s = 0, 0 | |
for i=1, #samples do | |
s = samples[i] + coeff * s_prev - s_prev2 | |
s_prev2, s_prev = s_prev, s | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Lua 5.1 or 5.2 table unpacker | |
local unpack = table.unpack or unpack | |
-- Bytes to unsigned integer | |
local function bton(s) | |
local bytes, n = {s:byte(1,-1)}, 0 | |
for i=0, #s-1 do | |
n = n + bytes[1+i] * 256^i | |
end | |
return n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <stdlib.h> | |
// Replace string in string by creating a new one | |
char* str_replace(char* original, const char* find, const char* replacement, const char free_original){ | |
// Initializations | |
int found_count = 0; | |
const size_t find_len = strlen(find), replacement_len = strlen(replacement); | |
char* result, *presult; | |
const char* poriginal = original, *found; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdint.h> // uint8_t, uint16_t, uintptr_t | |
#include <string.h> // memset | |
// Data are dirty? | |
int is_dirty_naive(const uint16_t width, const uint16_t height, const uint16_t stride, const uint8_t* data){ | |
for(uint16_t row = 0; row < height; ++row){ | |
for(uint16_t col = 0; col < width; ++col) | |
if(data[col] > 0) | |
return 1; | |
data += stride; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?PHP | |
function timeout_exec($cmd, $stdin = "", &$stdout, &$stderr, $timeout = 0){ | |
// Initialize output | |
$stdout = ""; | |
$stderr = ""; | |
// Start process | |
$pipes = array(); | |
$process = proc_open($cmd, array(array('pipe','r'),array('pipe','w'),array('pipe','w')), $pipes); | |
if(!is_resource($process)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <deque> | |
#include <algorithm> | |
template<typename Key, typename Value> | |
class Cache{ | |
private: | |
std::deque<std::pair<Key,Value>> data; | |
const unsigned int max_size; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getScrollbarSize() { | |
var hiddenScroll = jQuery('<div />', { | |
css: { | |
visibility: 'hidden', | |
width: 100, | |
'overflow-y': 'scroll' | |
} | |
}).appendTo('body'), | |
hiddenScrollContentWidth = jQuery("<div />").css('width', '100%').appendTo(hiddenScroll).outerWidth(); | |
hiddenScroll.remove(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "image_display.h" | |
#include <windows.h> | |
#include <gdiplus.h> | |
#include <iostream> | |
#include <memory> | |
static LRESULT CALLBACK wndProc(HWND wnd, UINT msg, WPARAM wParam, LPARAM lParam){ | |
switch(msg){ | |
case WM_CREATE: | |
SetWindowLongPtrA(wnd, GWL_USERDATA, reinterpret_cast<LONG_PTR>(reinterpret_cast<CREATESTRUCTA*>(lParam)->lpCreateParams)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lua C API | |
#include <lua.hpp> | |
// C++ input/output streams | |
#include <iostream> | |
// MyObject as C++ class | |
class MyObject{ | |
private: | |
double x; | |
public: |
OlderNewer