Skip to content

Instantly share code, notes, and snippets.

View takamin's full-sized avatar
🏢

Koji Takami takamin

🏢
View GitHub Profile
@takamin
takamin / Sound.h
Last active August 29, 2015 14:06
PlaySound
#pragma once
#include "windows.h"
#include <string>
class Sound
{
public:
Sound();
Sound(const std::string& filename);
~Sound();
bool Load(const std::string& filename);
@takamin
takamin / TimerThread.h
Last active August 29, 2015 14:06
TimerThread
#pragma once
#include <windows.h>
#ifdef _DEBUG
#include <deque>
#endif
class TimerThread {
template<class InputType, class InnerAvgType=double, class AvgType=InputType>
class LongAverage {
int average_count;
int buffer_count;
InnerAvgType average;
public:
LongAverage() : average_count(100000), buffer_count(0), average(0) { }
LongAverage(int average_count) : average_count(average_count), buffer_count(0), average(0)
{
assert(average_count > 0);
#include <deque>
template<class InputType, class InnerAvgType=double,
class AvgType=InputType>
class MovingAverage {
int average_count;
std::deque<InputType> buffer;
InnerAvgType average;
public:
MovingAverage() : average_count(1), average(0) { }
MovingAverage(int average_count)
@takamin
takamin / string_split.h
Last active August 29, 2015 14:05
split string by char
#include <string>
template<class StorageType>
void split(
char c, const std::string& s,
StorageType& result)
{
size_t pos, offset = 0;
while (true) {
pos = s.find(c, offset);
if (pos == std::string::npos) {
@takamin
takamin / MainActivity.java
Last active August 29, 2015 13:56
dynamic widgets exchanging
public class MainActivity extends Activity {
// @see main_activity.xml
ViewGroup linearLayout1 = null;
Button button1 = null;
Button button2 = null;
Button button3 = null;
Button button4 = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
@takamin
takamin / AvoidsFormInvokingDeadlock.cs
Last active August 29, 2015 13:56
Avoids to fall into the deadlock in `Form.FormClose` when using `Invoke` by worker thread of the `Form` in DotNet 2.0.
public partial class MainForm : Form {
// Avoids dead lock problem when closed in invoking
private bool invoking = false;
private bool closeRequested = false;
public new object Invoke(Delegate program) {
object ret = null;
if (!closeRequested) {
invoking = true;
try {
ret = base.Invoke(program);