Skip to content

Instantly share code, notes, and snippets.

View desperius's full-sized avatar
🙃
Weeks of coding can save you hours of planning

desperius

🙃
Weeks of coding can save you hours of planning
View GitHub Profile
@desperius
desperius / permutation.cpp
Last active May 13, 2017 17:50
All permutation of N numbers. Complexity: N!
#include <iostream>
int n = 0;
int* arr;
void swap(int* arr, int a, int b)
{
int c = arr[a];
arr[a] = arr[b];
@desperius
desperius / astyle
Last active June 8, 2022 14:17
Settings for AStyle code formatter
--style=allman
--indent=spaces=4
--indent-switches
--min-conditional-indent=0
--align-pointer=type
--align-reference=type
--max-code-length=120
--break-blocks
--pad-oper
--pad-header
@desperius
desperius / cin_buffer_cleanup.cpp
Last active June 8, 2022 14:10
The way to clean up a standard input buffer in case of a reading error. If such error appears the buffer does not clean up automatically. If application will try to continue then reading will proceeding from already filled buffer and will lead to one more error.
#include <iostream>
int main(void)
{
int i;
std::cin >> i; // Enter from keyboard e.g. the characters string 'hello'
if (std::cin.fail())
{
std::cin.clear();
@desperius
desperius / maximal_odd_divisor.cpp
Last active June 8, 2022 13:52
Simple approach to find Maximal Odd Divisor.
#include <iostream>
int main(void)
{
int x = rand();
std::cout << "Generated number: " << x << std::endl;
/* Count maximal odd divisor */
x /= x & -x;
@desperius
desperius / ifstream_read_text.cpp
Last active June 8, 2022 13:36
Reading text file using ifstream.
#inlcude <iostream>
#include <fstream>
int main(void)
{
std::ifstream file;
/* Read file */
file.open("file.txt", std::ios::in);
@desperius
desperius / openal_wav_load.cpp
Last active June 8, 2022 13:30
Trivial example of loading and playback of audio file in WAV format using OpenAL library and ALUT.
#include <iostream>
#include <stdlib.h>
#include <alut.h>
const unsigned NUM_BUFFERS = 1;
const unsigned NUM_SOURCES = 1;
int main(int argc, char* argv[])
{
/* Sound buffer variable */