Skip to content

Instantly share code, notes, and snippets.

View cjxgm's full-sized avatar
🦧
Recovering...

Giumo Clanjor (哆啦比猫/兰威举) cjxgm

🦧
Recovering...
View GitHub Profile
@cjxgm
cjxgm / unique_pod.cc
Created December 21, 2014 10:26
unique_pod, just like unique_ptr but is for POD
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
#include <type_traits>
@cjxgm
cjxgm / communicator.cc
Created December 20, 2014 14:58
single rt-safe reader, single rt-UNSAFE writer communication channel, for homogeneous type
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
#include <cmath>
#include <cstdlib>
@cjxgm
cjxgm / osc.cc
Last active August 29, 2015 14:07
a sine wave oscillator without a std::sin call nor a sine table
#include <cstdlib>
#include <thread>
#include <chrono>
#include <iostream>
using std::cout;
using std::endl;
static void rep(char ch, int n)
{
while (n--) cout << ch;
@cjxgm
cjxgm / README.asciidoc
Last active August 29, 2015 14:07
correct(?) audio "capture-then-playback" code (pulseaudio-simple)

so, finally, I fixed the bug.

highlights
auto playback = pa_simple_new(nullptr, "jopa-ng",
		PA_STREAM_PLAYBACK, nullptr, "playback", &ss,
		nullptr,
		nullptr,  // (1)
		nullptr);
@cjxgm
cjxgm / ring.cc
Last active August 29, 2015 14:07
a single-reader single-writer wait-free ring buffer
#include <array>
#include <type_traits>
#include <stdexcept>
#include <thread>
#include <chrono>
#include <string>
#include <iostream>
using std::cin;
using std::cout;
@cjxgm
cjxgm / mixin.hh
Created October 6, 2014 15:41
tranferability constrain mixin
namespace mixin
{
struct no_copy_ctor { no_copy_ctor() = default; no_copy_ctor(no_copy_ctor const&) = delete; };
struct no_copy_assign { no_copy_assign& operator=(no_copy_assign const&) = delete; };
struct non_copyable : no_copy_ctor, no_copy_assign {};
struct no_move_ctor { no_move_ctor() = default; no_move_ctor(no_move_ctor &&) = delete; };
struct no_move_assign { no_move_assign& operator=(no_move_assign &&) = delete; };
struct non_movable : no_move_ctor, no_move_assign {};
@cjxgm
cjxgm / bottleneck.md
Last active August 29, 2015 14:06
bottleneck

original

  • input: undefined [output (n) commands]
  • compiler damage: brute force O(n^2)* -> O(n)
  • compiler merge: brute force O(n^2)* -> O(n) [output (m) rectangles]
  • compiler optimize: brute force O(mn)
  • render: undefined

NOTE:

@cjxgm
cjxgm / unique_res.cc
Created September 8, 2014 10:55
c++ raii unique resource
#include <cstddef>
#include <type_traits>
#include <utility>
#include <functional>
#include <stdexcept>
#include <iostream>
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
@cjxgm
cjxgm / gl.cc
Created September 4, 2014 15:23
opengl lighting test
#include <GL/glut.h>
#include <stdio.h>
#include <stdlib.h>
float spin = 0;
static const float no[] = { 0, 0, 0, 1 };
float pos_x = 0, pos_y = 0, pos_z = 0;
static char key[256] = {0};
@cjxgm
cjxgm / bnd_play.cc
Created August 31, 2014 09:03
a simple module in-code tracker, utilizing the bnd time code, no floating point arithmetic, full of integral type tricks.
// clang++ -o bnd_play bnd_play.cc -std=gnu++1y -O3 -march=native -Wall -Wextra -lpulse-simple
#include <vector>
#include <algorithm>
#include <initializer_list>
#include <stdexcept>
#include <cstdio>
#include <pulse/simple.h>
struct pitch
{