Skip to content

Instantly share code, notes, and snippets.

View Himura2la's full-sized avatar
💭
Nya?

Himura Kazuto Himura2la

💭
Nya?
View GitHub Profile
@Himura2la
Himura2la / Grafana Alert Template.md
Last active April 26, 2024 10:31
How to use Grafana Alerts with the Telegram
  • Template name: telegram.message
  • Content:
    {{ define "alert_list" }}{{ range . }}{{ .Labels.alertname }}
    {{ range .Annotations.SortedPairs }}<strong>{{ .Name }}</strong>: {{ .Value }}
    {{ end }}| {{ if gt (len .GeneratorURL) 0 }}<a href="{{ .GeneratorURL }}">source</a> | {{ end }}{{ if gt (len .SilenceURL) 0 }}<a href="{{ .SilenceURL }}">silence</a> | {{ end }}{{ if gt (len .DashboardURL) 0 }}<a href="{{ .DashboardURL }}">dashboard</a> | {{ end }}{{ if gt (len .PanelURL) 0 }}<a href="{{ .PanelURL }}">panel</a> |{{ end }}
    —
    {{ end }}{{ end }}
    {{ define "telegram.message" }}
    

{{ if gt (len .Alerts.Firing) 0 }}FIRING!!!

@Himura2la
Himura2la / README-CodiMD-Restore.md
Last active April 25, 2024 13:05
CodiMD Backup and Restore
@Himura2la
Himura2la / requests.py
Last active April 3, 2024 10:49
An alternative for undeservedly popular library
from urllib.request import urlopen, Request, HTTPError
def fetch(url, method=None, data=None, headers={}):
try:
with urlopen(Request(
url,
data=data.encode('ascii') if data else None,
headers=headers,
method=method
)) as resp:
@Himura2la
Himura2la / certs.sh
Created January 10, 2024 12:30
Generate your own TLS certificate chains
# CA
openssl ecparam -genkey -name prime256v1 -out ca.key
cat > ca.conf <<EOF
[req]
prompt = no
x509_extensions = ext
distinguished_name = dn
[ext]
stat /dev/ttyUSB0 # Gid: ( 18/ dialout)
sudo usermod -aG dialout $USER
sudo reboot
@Himura2la
Himura2la / nginx.conf
Created October 13, 2023 20:15
nginx plain text response
server {
listen 80;
server_name nya.nya;
default_type text/plain;
return 200 'nya nyaaaa~\n';
}
@Himura2la
Himura2la / Paginate.cs
Last active September 5, 2023 12:59
Pagination for EF queries
const int batchSize = 50;
async Task Paginate<TEntity>(DbSet<TEntity> dbSet,
Func<int, CancellationToken, Task> action,
CancellationToken cancellationToken = default) where TEntity : class {
var count = await dbSet.CountAsync(cancellationToken);
var remain = count;
while(remain > 0) {
logger.LogInformation($"Processing {batchSize} of {remain} items...");
await action(skip: count - remain, cancellationToken);
@Himura2la
Himura2la / Win11_LocalDB_Fix.reg
Created August 21, 2023 13:12
Fix SQL Server Express LocalDB on Windows 11
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL15E.LOCALDB\MSSQLServer\Parameters]
"SQLArg0"="-T1800"
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL16E.LOCALDB\MSSQLServer\Parameters]
"SQLArg0"="-T1800"
@Himura2la
Himura2la / grow-partition.md
Last active July 17, 2023 14:01
How to grow a mounted partition
  1. Grow the disk in your hypervisor (Hyper-V: Edit Disk in Actions panel)

  2. Apply the disk size change (you can do echo 1 | sudo tee /sys/class/block/sda/device/rescan instead of partprobe)

    $ sudo partprobe /dev/sda
    
    $ sudo dmesg | tail
    ...
    [4688278.217348] sd 2:0:0:0: Capacity data has changed
    

[4688278.217583] sd 2:0:0:0: [sda] 83886080 512-byte logical blocks: (42.9 GB/40.0 GiB)

@Himura2la
Himura2la / csv_sup.py
Last active July 4, 2023 11:38
CSV Supplementer
import json
import os
import csv
from urllib.request import urlopen, Request, HTTPError
csv_path = os.path.expanduser(r"~\Desktop\data.csv")
additional_cols = []
def fetch_additional_data(row):
# TODO