Skip to content

Instantly share code, notes, and snippets.

View sooch's full-sized avatar
🏠
Working from home

Sooo sooch

🏠
Working from home
View GitHub Profile
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sooch
//
// TradingViewのMACDストラテジーに期間指定パラメータを追加したPineScriptです.
//
//@version=4
strategy("MACD Strategy", overlay=true)
// Input parameters
import pandas as pd
import numpy as np
from pandas import DataFrame, Series
def sma(ohlc: DataFrame, period=9) -> Series:
return Series(
ohlc['close'].rolling(period).mean(),
name=f'SMA {period}',
)
extension String {
func asHtmlAttributedString() -> NSAttributedString? {
guard let htmlData = self.data(using: String.Encoding.utf8, allowLossyConversion: true) else { return nil }
let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue
]
return try? NSAttributedString(data: htmlData, options: options, documentAttributes: nil)
}
@sooch
sooch / random.php
Created December 28, 2018 08:31
random number between a float range for PHP
/**
* 範囲内の値をランダムで返す
*
* @param float $min 最小値
* @param float $max 最大値
* @return float
*/
function random_float($min, $max, $mul = 1000000): float
{
return random_int($min * $mul, $max * $mul) / $mul;
@sooch
sooch / laravel_query_builder_lock.md
Last active July 4, 2022 06:53
Laravelの悲観的ロックについて

共有ロック

クエリビルダは、SELECT文で「悲観的ロック」を行うための機能をいくつか持っています。SELECT文を実行する間「共有ロック」をかけたい場合は、sharedLockメソッドをクエリに指定して下さい。共有ロックはトランザクションがコミットされるまで、SELECTしている行が更新されることを防ぎます。

DB::table('users')
  ->where('votes', '>', 100)
  ->sharedLock()
  ->get();
@sooch
sooch / builder_example.py
Last active October 3, 2018 01:04
effective java builder pattern for python
#-*- coding: utf-8 -*-
class NutritionFacts(object):
def __init__(self, builder):
self.serving_size = builder.serving_size
self.servings = builder.servings
self.calories = builder.calories
self.fat = builder.fat
self.sodium = builder.sodium