Skip to content

Instantly share code, notes, and snippets.

View takamin's full-sized avatar
🏢

Koji Takami takamin

🏢
View GitHub Profile
@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);
@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 / 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) {
#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)
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);
@takamin
takamin / TimerThread.h
Last active August 29, 2015 14:06
TimerThread
#pragma once
#include <windows.h>
#ifdef _DEBUG
#include <deque>
#endif
class TimerThread {
@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 / .wait_jquery.RawGit.html
Last active August 29, 2015 14:06
jqueryが読み込まれる前のSCRIPTでjqueryが使えるようになるまで待つ
<!-- load a gist directly by using RawGit -->
<script
type="text/javascript"
src="https://cdn.rawgit.com/takamin/d39bf8ccff805baecb1b/raw/faf22f4f507673ce3143b82ee842dcf5b2130c2a/wait_jquery.js"
></script>
@takamin
takamin / jma_get.php
Last active October 15, 2019 23:33
気象庁のサイトから情報を得るPHPスクリプト
<?php
/**
* 気象庁のサイトから都府県・地方データの一覧を得る
* @return array ('name'=>名称,'prec_no'=>都府県・地方No)
*/
function jma_get_prec_list() {
$url = "http://www.data.jma.go.jp/obd/stats/etrn/select/prefecture00.php";
/**
* timespinner "hh:mm"
*/
$.widget( "ui.timespinner", $.ui.spinner, {
options: { step: 1, page: 1 },
_parse: function( value ) {
if ( typeof value === "string" ) {
if ( Number( value ) == value ) {
return Number( value );
}