Skip to content

Instantly share code, notes, and snippets.

View pandanote-info's full-sized avatar

pandanote-info pandanote-info

View GitHub Profile
@pandanote-info
pandanote-info / mongodb_sysctl_fs.te
Created April 2, 2022 11:40
MongoDB用のType Enforcementファイルの作成例(sysctl_fs_t用)。
module mongodb_sysctl_fs 1.0;
require {
type mongod_t;
type sysctl_fs_t;
class dir search;
class file { getattr read open };
}
#============= mongod_t ==============
@pandanote-info
pandanote-info / uploadToIpfs.js
Created March 25, 2022 08:18
POSTメソッドで受け取ったbodyからバイナリデータを取り出し、IPFSノードにアップロードするNode.jsのプログラムのプログラム片。
// See https://pandanote.info/?p=8723 for details.
import * as fs from 'fs';
import axios from 'axios';
import FormData from 'form-data';
function getBoundary(header) {
var tmpct = header['content-type'].split(/;/);
var boundary = tmpct.filter(function(e) {
return e.trim().startsWith("boundary=");
});
@pandanote-info
pandanote-info / openvpn_start.sh
Created January 13, 2022 13:56
ASUSのTUF-AX5400のシェルプロンプトからOpenVPNを起動するためのシェルスクリプト。
#!/bin/sh
modprobe tun
cd /jffs/openvpn/conf
nohup /usr/sbin/openvpn --config client.conf 2>&1 >/dev/null &
@pandanote-info
pandanote-info / tfidf.py.sample
Created January 7, 2022 07:47
TF-IDFの計算用のサンプルコード片
# TF
aa = bow.copy()
np.set_printoptions(threshold=np.inf,formatter={'float': '{:.8f}'.format})
for i in range(0,dim[0]):
ar = bow.getrow(i)
rowsum = np.matrix.sum(ar.todense())
arr = ar/rowsum
aa[i] = arr
# IDF(ln)
@pandanote-info
pandanote-info / freq2matrix.py.example
Created January 7, 2022 07:45
転置インデックスもどきのデータをベクトル化するためのPython3のプログラム片。
with open(inputfile, encoding='utf-8') as fh:
freqlist = json.load(fh)
words = []
articleids = []
for k,v in freqlist.items():
words.append(k)
for vv in v:
a,f = vv.split(",")
@pandanote-info
pandanote-info / startipfs.sh
Last active December 6, 2021 12:39
IPFS daemonの起動・終了を実行するためのshell script。
#!/bin/bash
#
# See https://pandanote.info/?p=8205 for details.
#
MODE="start"
if [ -n "$1" ]; then
MODE="stop"
fi
@pandanote-info
pandanote-info / ipfs.service
Last active May 4, 2022 13:10
IPFSのdaemonの起動用のサービスユニットファイルのコード例。
[Unit]
Description=Ipfs
After=network-online.target
[Service]
User=panda
WorkingDirectory=/home/panda
OOMScoreAdjust=-1000
ExecStart=/usr/local/bin/ipfs daemon --enable-gc --enable-namesys-pubsub
ExecStop=/usr/bin/pkill --signal SIGINT ipfs
[Install]
@pandanote-info
pandanote-info / adjust_config_sample.sh
Last active April 30, 2023 08:30
Fedora+nginxのアップデートまたはアップグレードを行う際に、nginx用の設定ファイルのownerをnginxユーザに戻すためのシェルスクリプト。
#!/bin/sh
# See https://pandanote.info/?p=8118 for details.
chown -R nginx /etc/wordpress
chown -R nginx /var/lib/php/session
chown -R nginx /var/lib/php/wsdlcache/
chown -R nginx /var/lib/php/opcache/
chown -R nginx /usr/share/wordpress/wp-content/uploads/
chown nginx:nginx /var/log/nginx
@pandanote-info
pandanote-info / Excel2SQLite3_Module.vba
Last active November 4, 2021 08:08
ExcelのシートからSQLite3のCREATE TABLE句が記述されたファイルを生成するためのExcelのアドインの標準モジュールに記述するコード。
' See https://pandanote.info/?p=8075 for details.
'SQLのCreate文を作る。
Option Explicit
Sub Create_CreateClause()
Dim columnname() As Variant
columnname = Array()
Dim rownum As Integer
rownum = Range(Selection.Address).Row
Dim rightMost As Integer
@pandanote-info
pandanote-info / Excel2SQLite3_Worksheet_BeforeRightClick.vba
Last active November 10, 2021 14:33
ExcelのシートからSQLite3のCREATE TABLE句が記述されたファイルを生成するためのExcelのアドインのThisWorkbookに記述するコード。
Option Explicit
Public WithEvents CreateTableStatementForSQLite3 As Application
Private Sub Workbook_Open()
Set CreateTableStatementForSQLite3 = Application
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set CreateTableStatementForSQLite3 = Nothing