Skip to content

Instantly share code, notes, and snippets.

@siritori
siritori / test.rs
Created December 9, 2021 22:37
Binary parsing test
use bytes::Buf;
pub trait BinaryRead: Sized {
fn read<T: bytes::Buf>(reader: &mut BinaryReader<T>) -> Option<Self>;
}
pub struct BinaryReader<T: bytes::Buf> {
pub buf: T,
}
@siritori
siritori / filter-map.ts
Created January 17, 2021 14:58
operator習作
import { strict as assert } from 'assert';
import { Operator, OperatorFunction, Subscriber } from "rxjs";
export type FilterMap<T, U> = (e: T, index: number) => U | null;
class FilterMapSubscriber<T, U> extends Subscriber<T> {
private count = 0;
private readonly thisArg: any;
constructor(
destination: Subscriber<U>,
import { EventEmitter, Injectable } from '@angular/core';
import { Overlay, OverlayConfig } from '@angular/cdk/overlay';
import { ComponentPortal, ComponentType } from '@angular/cdk/portal';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
export interface DialogNeed<Return> {
close$: EventEmitter<Return>;
}
@siritori
siritori / srp.md
Last active November 10, 2020 13:59

単一責任の原則 (SRP)

意味

1つのクラス・モジュール・関数を変更する理由は1つ以上存在してはならない。

なぜこの原則がある?

  • いろいろなものをモックしないといけないのでテストしづらくなる
  • 1つ修正したときに周辺確認がやたら多くなり工数が増える
@siritori
siritori / jsonArchive.cpp
Created February 4, 2020 22:32
SFINEでオーバーロード
#include <functional>
#include <iostream>
#include <vector>
#include <map>
#include <initializer_list>
class JsonArchive {
public:
explicit JsonArchive(std::ostream &stream)
@siritori
siritori / main.cpp
Created November 10, 2019 10:54
SegmentTreeによるRMQ
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <list>
@siritori
siritori / CallbackStreamBuffer.hpp
Created October 6, 2019 22:09
std::basic_streambufを使って独自streamを作る
#pragma once
/**
* @brief コールバックストリームバッファ
* @note 出力をバッファリングし、書き込み用の関数をコールバックする
*/
class CallbackStreamBuffer : public std::basic_streambuf<char>
{
/**
* @brief 親クラス
type updator<T> = (prev: T) => T;
class PartialUpdate<Props>
{
private _props: Props;
protected get props(): Props {
return this._props;
}
constructor(props: Props | updator<Props>, prev?: Props) {
class PartialUpdate<Props>
{
constructor(protected props: Props) {
PartialUpdate.deepFreeze(this);
}
private static deepFreeze(o: any) {
Object.freeze(o);
var oIsFunction = typeof o === "function";
public class ProductMain {
public boolean executeMain(ResourceHolder resourceholder) {
Log log = BCLogFactory.getLog(ProductMain.class);
CommonPrinter commonPrinter = null;
Statement statement = null;
ResultSet resultSet = null;
try {
String outputileName = resourceHolder.getOutputFileName();
commonPrinter = new CommonPrinter(outputFileName, "UTF-8");
Connection connection = resourceHolder.getConnection();