Skip to content

Instantly share code, notes, and snippets.

@Shikugawa
Shikugawa / progress_bar.cpp
Created December 15, 2019 15:18
マルチスレッドな進捗バー
#include <iostream>
#include <string>
#include <thread>
#include <atomic>
#include <unistd.h>
#include <mutex>
std::atomic<bool> end_flag = false;
std::atomic<bool> out_flag = false;
std::atomic<double> current_time = 0;
@Shikugawa
Shikugawa / simple-grpc-routing.yaml
Created January 6, 2020 02:18
Simple gRPC routing with Envoy
static_resources:
listeners:
- address:
socket_address:
address: 0.0.0.0
port_value: 8000
filter_chains:
- filters:
- name: envoy.http_connection_manager
typed_config:
@Shikugawa
Shikugawa / go_cpp_swig_linkage.md
Created January 26, 2020 17:54
Call C++ Library from Go using shared library with SWIG

Introduction

SWIG can generate interface for other languages to call C++ functions. If C++ codes are separeted to mutiple directories, we may have some trouble.

Build Flow

  1. Prepare directories like this.
- invoke
 - invoke.cpp
@Shikugawa
Shikugawa / distance.rs
Created February 1, 2020 17:58
†編集距離†
use std::cmp;
fn main() {
let base: &str = "kitten";
let changed: &str = "sitting";
let mut dp: Vec<Vec<i8>> = vec![];
let x_len: usize = base.len() + 1;
let y_len: usize = changed.len() + 1;
for _ in 0..y_len {
let elem: Vec<i8> = vec![-1; x_len];
#include <iostream>
#include <string>
#include <vector>
class Record {
public:
// continueフラグは、msecに変換する際、初期値から換算するか否かを区別するのに用いる
Record(const std::string &record_str) : record_str_(record_str) {
parse();
calculateTimestamp();
@Shikugawa
Shikugawa / rl_template.cpp
Last active May 28, 2020 03:29
強化学習のテンプレ(オセロ+ミニマックスAI)
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <iostream>
#include <optional>
#include <ostream>
#include <set>
#include <vector>
@Shikugawa
Shikugawa / pubsub.go
Created August 19, 2020 15:04
PubSub
package main
import (
"fmt"
"sync"
"time"
)
type PubSub struct {
mux sync.RWMutex
# <op> ::= + | - | *
# <number> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
# <factor> ::= <number> | '(' <expr> ')'
# <expr> ::= <factor> [<op> <factor>]*
class Parser():
def __init__(self, eq):
self.idx = 0
self.eq = list(eq)
self.nums = list("0123456789")
self.op = list("+-*")
enum class InstructionSymbol : Byte {
// ==== Control Instructions ====
UNREACHABLE = 0x00,
NOP = 0x01,
BLOCK = 0x02,
LOOP = 0x03,
IF = 0x04,
ELSE = 0x05,
END = 0x0B,
BR = 0x0C,
#include <iostream>
int main() {
int a = 0;
int l = 1;
printf("%i | ", l);
for (auto s : cs->value.elem) {
printf("0x%.2x ", s);
if (a == 7) {
std::cout << std::endl;