Skip to content

Instantly share code, notes, and snippets.

View yytyd's full-sized avatar

ToyodaYuki yytyd

  • CyberAgent, inc.
View GitHub Profile
@yytyd
yytyd / to_string_bench.rs
Created September 12, 2020 15:01
f64 の to_string のベンチマーク(通常の to_string vs Ryu を使った to_string)
#![feature(test)]
fn main() {
println!("Hello, world!");
}
fn from_f64_to_string(value: f64) -> String {
value.to_string()
}
fn from_f64_to_string_by_ryu(value: f64) -> String {
@yytyd
yytyd / black_scholes.py
Created September 8, 2020 07:15
Black Scholes Model implementation example written in Python
from scipy.stats import norm
from math import exp, log, sqrt
def BS_Call(S0, sigma, r, q, T, K):
d1 = (log(S0 / K) + (r - q) * T) / (sigma * sqrt(T)) + sigma * sqrt(T) / 2
d2 = (log(S0 / K) + (r - q) * T) / (sigma * sqrt(T)) - sigma * sqrt(T) / 2
call = S0 * exp(-q * T) * norm.cdf(x=d1, loc=0, scale=1) - K * exp(-r * T) * norm.cdf(x=d2, loc=0, scale=1)
return call
def BS_Put(S0, sigma, r, q, T, K):
@yytyd
yytyd / example_quadratic.rs
Last active September 6, 2020 15:45
minituna の実装を移行して理解する
use crate::minituna_v1::Objective;
use crate::minituna_v1::Trial;
use crate::minituna_v1::TrialError;
struct Quadratic;
impl Objective for Quadratic {
fn objective(&self, trial: Trial) -> Result<f64, TrialError> {
let x = trial.suggest_uniform("x", 0.0, 10.0);
let y = trial.suggest_uniform("y", 0.0, 10.0);
@yytyd
yytyd / cpp.asm
Last active May 27, 2020 02:06
C++ raw pointer vs Rust
foo(int*): # @foo(int*)
push rbx
mov rbx, rdi
cmp dword ptr [rdi], 43
jl .LBB0_2
mov rdi, rbx
call bar(int*)
mov dword ptr [rbx], 42
.LBB0_2:
mov rdi, rbx
@yytyd
yytyd / DualNumbers.scala
Last active November 9, 2019 16:16
DualNumbers
package model
case class DualNumbers(a: Double = 0d, b: Double = 0d) {
def + : DualNumbers = this
def - : DualNumbers = DualNumbers(-a, -b)
def <(rhs: DualNumbers): DualNumbers = this < rhs
@yytyd
yytyd / Parser.hs
Last active November 2, 2019 09:19
Packrat Parsing
data Result v = Parsed v Derivs
| NoParse
data Derivs = Derivs {
dvAdditive :: Result Int,
dvMultitive :: Result Int,
dvPrimary :: Result Int,
dvDecimal :: Result Int,
dvChar :: Result Char}
@yytyd
yytyd / call.rs
Last active October 13, 2019 16:23
普通の macro でちょっとボイラープレートをなくす
use crate::domain::repository::task::{MixInTaskRepository, TaskRepository};
use crate::infra::mysql::mysqlcon::{
MixInMySqlConnection, MySqlConnection, MySqlConnectionDependencies,
};
use crate::infra::redis::pool_ctxt::{MixInRedisContext, RedisContext, RedisContextDependencies};
use crate::infra::repository::task::TaskRepositoryDependencies;
use crate::{add_deps, add_mixin_impl};
pub struct TaskBootstrap {}
use crate::domain::repository::task::{MixInTaskRepository, TaskRepository};
use crate::infra::mysql::mysqlcon::{MixInMySqlConnection, MySqlConnectionDependencies};
use crate::infra::redis::pool_ctxt::{MixInRedisContext, RedisContextDependencies};
use crate::infra::repository::task::TaskRepositoryDependencies;
pub struct Bootstrap {}
impl Bootstrap {
pub fn call(&self) {
let a = self.task_repository().find_task_by_id("aaa".to_string());
@yytyd
yytyd / main.rs
Created April 28, 2019 15:41
main.rs
use std::io;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct Loc(usize, usize);
impl Loc {
fn merge(&self, other: &Loc) -> Loc {
use std::cmp::{max, min};
Loc(min(self.0, other.0), max(self.1, other.1))
}
@yytyd
yytyd / BuildStatus.java
Last active March 16, 2019 07:40
Java で,幽霊型を使って builder を書く??
package com.github.yytyd.status;
public interface BuildStatus {
}