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
#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
#include <ext/stdio_filebuf.h> // fstream (all sorts of IO stuff) + stdio_filebuf (=streambuf) | |
#include <fcntl.h> // _O_RDONLY | |
#include <iostream> // cout | |
int main(){ | |
__gnu_cxx::stdio_filebuf<char> wfile_buf(_wopen(L"D:\\...\\の.txt", _O_RDONLY), std::ios_base::in); | |
std::istream wfile_stream(&wfile_buf); | |
wfile_stream.seekg(0, std::ios_base::end); | |
std::cout << wfile_stream.tellg(); | |
return 0; |
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
@echo off | |
rem Set console appearance | |
title Java environment (%cd%) | |
color 0C | |
rem Set console environment | |
if "%~1"=="" ( | |
set JAVA_BIN=C:\Program Files\Java\jdk1.8.0_45\bin | |
) else ( | |
set JAVA_BIN=%~1 | |
) |
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 <emmintrin.h> // SSE2 | |
static unsigned short x[8] = {0, 55, 2, 62003, 786, 5555, 123, 32111}; // Dividend | |
__attribute__((noinline)) static void test_div_x86(unsigned i){ | |
for(; i; --i) | |
x[0] /= i, | |
x[1] /= i, | |
x[2] /= i, | |
x[3] /= i, |
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 <stdlib.h> | |
#include <stdio.h> | |
#ifdef __SSE2__ | |
#include <emmintrin.h> | |
#endif | |
static double calc_pi(unsigned n){ | |
double pi, x; | |
#ifdef __SSE2__ | |
const __m128d four = _mm_set1_pd(4.0); |
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; |
OlderNewer