Skip to content

Instantly share code, notes, and snippets.

@doshiraki
doshiraki / toggle_mount.sh
Last active September 27, 2025 06:15
bash for remount when adb remount fails because permission or read-only.
#!/system_ext/bin/bash
pwd=$(dirname $0)
cd ${pwd} 2> /dev/null
# toggle_mount.sh: Toggles specified Device Mapper device(s) between read-only (ro) and read-write (rw) on Pixel 7a (LineageOS)
# Usage:
# Single device: toggle_mount <device> <ro|rw> (e.g., toggle_mount system_a rw)
# All system/product/vendor: toggle_mount --all rw
# Features: Compares dmctl table before/after; avoids lsblk; converts multiple devices to rw
@doshiraki
doshiraki / addcolums.py
Created September 12, 2024 23:13
add cloumns
from enum import Enum, auto
import os
def list_directories_recursively(path):
for root2, dirs, files in os.walk(path):
root = root2 + "/"
root = root2[len(path) + 1 :]
# 現在のディレクトリ内のサブディレクトリをリストアップ
for file in files:
@doshiraki
doshiraki / ValidNumberFmt.cc
Last active April 17, 2023 22:38
Valid Size Number Format in C++.
#include <ios>
#include <iostream>
#include <iomanip>
#include <limits>
template <typename _NumberT>
class ValidNumberFmt
{
_NumberT n;
@doshiraki
doshiraki / excel2tsv.py
Last active February 19, 2023 04:33
excel to tsv by python
import sys
from zipfile import ZipFile
from lxml import etree
import datetime
def loopxml(zr:ZipFile, name:str):
parser = etree.XMLPullParser(['start', 'end'])
level = 0
stack = []
with zr.open(zr.getinfo(name)) as reader:
while True:
@doshiraki
doshiraki / cloud-config.yml
Last active December 18, 2022 12:53
How to use kubernetes with k3d in GCE
#cloud-config
mounts:
- [ /dev/mapper/VG_SDB-pv, /mnt/pv, xfs, rw, "0", "1" ]
- [ /dev/mapper/VG_SDB-swap, none, swap, sw, "0", "0" ]
runcmd:
- apt-get update
- apt-get install -y vim less bash-completion
- pvcreate /dev/sdb
- vgcreate VG_SDB /dev/sdb
- lvcreate -L 5G -n swap VG_SDB
@doshiraki
doshiraki / mysql_backup_difference.sh
Last active October 9, 2022 10:56
mysql5.7 backup for difference
#!/bin/bash
BACKUP_LAST=backup_last
BACKUP_CUR=backup_cur
BACKUP_SNAP=backup.sql.gz
BINLOG=binlog-$(date +%Y%m%d-%H%M%S-%N).sql.gz
BINLOGS=binlogs.txt
CONNECT_OPT=" -u root -h docker-db-pc -pexample "
get_binlog_list() {
echo "show binary logs;" | mysql ${CONNECT_OPT} | cut -f 1 | tail -n +2
@doshiraki
doshiraki / pipecyclic.c
Last active August 15, 2022 00:51
Cyclic pipe (you can do "your_pg | program | your_pg" )
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<stdlib.h>
#include<string.h>
void s2p(const char *path) {
char buf[2];
int fd = open(path, O_WRONLY);
while(fread(buf, 1, 1, stdin)) {
int cnt=1;
s/\r$//;
/^--------$/{
d;
}
/^-----$/!{
H;
/^BODY:/,/^COMMENT:/{
/^COMMENT:/{
DROP table testtbl
;
CREATE table
testtbl (id int,
dat datetime,
valuenum int,
valuenum2 int,
value varchar(30),
primary key(id,
dat))
package postgres
import (
"database/sql"
"fmt"
"log"
"time"
_ "github.com/lib/pq"
)