Skip to content

Instantly share code, notes, and snippets.

View umihico's full-sized avatar

Umihiko Iwasa umihico

View GitHub Profile
@umihico
umihico / incremental.test.ts
Created December 9, 2023 15:26
Incremental, weighted average, variance, covariance
import { round } from "mathjs"
import { average, sampleCovariance } from "simple-statistics"
const sum = (array: number[]) => {
return array.reduce((a, b) => a + b, 0)
}
const weightAverage = (prices: number[], weights: number[]) => {
const wSum = sum(weights)
const weightedPrices = prices.map((price, index) => {
@umihico
umihico / line-regression.test.ts
Created December 9, 2023 01:28
slopeとinterceptをcovarianceとvarianceから求められるか実践
import { variance } from "mathjs"
import { average, linearRegression, sampleCovariance } from "simple-statistics"
describe("line regression test", () => {
/**
* https://whyitsso.net/math/statistics/statistics1.html
*/
test("実験", () => {
const data = [
[1, 1],
@umihico
umihico / youtube_helper.rb
Created December 2, 2023 23:05
Youtubeのdescriptionの先頭に「提供」と「(引数)」がついている動画を検索する
require "google/apis/youtube_v3"
# rails r 'puts YoutubeHelper.search'
# Youtubeのdescriptionの先頭に「提供」と「(引数)」がついている動画を検索する
module YoutubeHelper
class << self
def service
youtube_service = Google::Apis::YoutubeV3::YouTubeService.new
@umihico
umihico / regression.test.ts
Last active December 2, 2023 23:00
重み付き線形回帰
import { linearRegression } from "simple-statistics"
/**
* 重み付き線形回帰
* https://chemstat.hatenablog.com/entry/2021/01/23/194405
* @param pricesY
* @param pricesX
* @param weights
* @returns expectedY = intercept + slope * x
*/
@umihico
umihico / multi-process.ts
Created November 18, 2023 13:44
Node.js TypeScript multi process (cluster.fork) example
import cluster from "cluster"
import { cpus } from "os"
export const multiProcessHandler = async (
jobConsumer: (job: string) => Promise<void>,
JobQueueGenerator: () => Generator<string, void, unknown>,
) => {
if (cluster.isPrimary) {
console.log(`Primary ${process.pid} is running`)
@umihico
umihico / README.md
Last active July 7, 2023 02:22
日報テンプレ

README

まずエイリアス登録

# 通常bashバージョン
alias nippo="curl -sL \"https://gist.githubusercontent.com/umihico/4b131c0a9a521df40abcde701c90cc67/raw/nippo.sh?v=$(date +'%s')\" | bash -e"

# エラーした人向けdocker利用バージョン 
@umihico
umihico / aws-funcs.sh
Last active June 25, 2022 12:50
Sign in AWS console by CLI credentials
# https://gist.github.com/umihico/3a19974ccb251a01dc870fe39b09749f
function aws-sub() {
aws-main --incognito
}
function aws-main() {
if [ "$1" = "--incognito" ]; then # Sign-out current user
open -na 'Google Chrome' --args --incognito "https://signin.aws.amazon.com/oauth?Action=logout&redirect_uri=https://aws.amazon.com" # Mac, OSX
else
@umihico
umihico / .ssh-config
Last active December 14, 2021 12:24
my lima cofig
Host limadocker
HostName localhost
Port 60006
User lima
NoHostAuthenticationForLocalhost yes
@umihico
umihico / Dockerfile
Created April 15, 2021 12:09
Install amazon-linux-extras on public.ecr.aws/lambda/python:3.8
FROM public.ecr.aws/lambda/python:3.8
RUN yum install -y amazon-linux-extras
RUN cp -r /lib/python2.7/site-packages/amazon_linux_extras /var/lang/lib/python3.8/site-packages/
# TEST COMMAND -> RUN amazon-linux-extras install -y mate-desktop1.x
@umihico
umihico / demo.sh
Last active August 5, 2020 00:03
Generate secret keys whose public keys which contain specific string such as your name
cd $(mktemp -d); while true; do seq 1000 | xargs -P 1000 -I NUM sh -c 'ssh-keygen -t ed25519 -f NUM.pem -N "" -C "" > /dev/null && if grep -vi umihico NUM.pem.pub > /dev/null; then rm NUM.pem NUM.pem.pub;fi' ; if find . -mindepth 1 | read; then for f in *.pem.pub; do echo $f >> files.txt; done; test -f files.txt && head -n1 files.txt | xargs -I F curl -s -X POST -d '{"text":"F"}' https://hooks.slack.com/services/XXXXXXXXX/YYYYYYYYYYY/zzzZZZzZzzZzzZZzz; break; fi ; date ; done