Skip to content

Instantly share code, notes, and snippets.

View bz0's full-sized avatar

(・(ェ)・) bz0

  • japan
View GitHub Profile
@bz0
bz0 / InsertionSort.php
Created September 22, 2019 03:39
ソートアルゴリズム
<?php
//挿入ソート
function insertionSort($a, $n){
for($i=1; $i<$n; $i++){
$v=$a[$i]; //基準
$j=$i-1;
while ($j>=0 && $a[$j]>$v){
//0以上 and 1つ前より数値が小さい場合
$a[$j+1] = $a[$j];
$j--;
@bz0
bz0 / tamesiwari.php
Last active September 19, 2019 15:15
【試し中】Divisors of Power:https://yukicoder.me/problems/no/847
<?php
//素因数分解 試し割法
function p_factor($num){
$factor = [];
$max = ceil(sqrt($num))+1; //√n+1 誤差のおそれがあるので+1する
for($i=2; $i<=$max; $i++){
while($num % $i == 0){ //約数判定
$num = $num / $i;
$factor[$i] = isset($factor[$i]) ? $factor[$i] + 1 : 1;
}
@bz0
bz0 / DfsPractice.php
Created September 17, 2019 09:20
深さ優先探索
<?php
class DfsPractice{
private $size = 2;
private $count = 0;
public function exec(){
$this->dfs(0, 0);
echo sprintf("全部で%d通り", $this->count);
}

goreのインストール

# go get -u -v github.com/motemen/gore

goreのパスが通ってないぽい

# gore -autoimport
@bz0
bz0 / httpd.conf
Created July 9, 2019 14:58
Apache2.4によるロードバランサ
<IfModule mod_proxy.c>
ProxyRequests off
ProxyPass / balancer://samplecluster/ lbmethod=byrequests timeout=10 maxattempts=2
<Proxy balancer://samplecluster/>
BalancerMember http://xxx.xxx.xxx.xxx loadfactor=3
BalancerMember http://xxx.xxx.xxx.xxx loadfactor=2
</Proxy>
</IfModule>
@bz0
bz0 / ロードバランサ.md
Last active July 6, 2019 12:20
ロードバランサ(ipvsadm+keepalived)の実装について

構成

さくらVPS3台(CentOS6.10)

・ロードバランサ1台
 eth1のIPを192.168.0.1を設定(実サーバのゲートウェイ)

・実サーバ2台
 eth1のIPを192.168.0.2,192.168.0.3を設定

"| /usr/bin/php -f /path/parse.php"
@bz0
bz0 / firebase-messaging-sw.js
Last active May 13, 2019 14:39
webプッシュ通知(FCM)
// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here, other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/4.8.1/firebase-messaging.js');
// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
firebase.initializeApp({
'messagingSenderId': '送信者IDを指定'