Skip to content

Instantly share code, notes, and snippets.

View yarikoptic's full-sized avatar
😠
Pseudo-"Tsar"-made WAR in Europe!

Yaroslav Halchenko yarikoptic

😠
Pseudo-"Tsar"-made WAR in Europe!
View GitHub Profile
@yarikoptic
yarikoptic / fix-hassio-sdcard
Last active June 11, 2024 20:56
fix sdcard squashfs partitions for hassio
#!/usr/bin/env python3
"""
Script I with chatgpt wrote to help myself with hassio sd-card
squashfs images going broken as I decribed on
https://community.home-assistant.io/t/how-to-replace-broken-squashfs-images/738391/5
The idea is to specify sdcard and file image, verify that they are
identical in partitioning (besides last filesystem), and then copy some
partitions from image into the card. Here is protocol of the use:
#!/bin/bash
#
# A little script that given a path would produce a sequence
# of bash (didn't check with posix shell)
# 'echo' and 'mkdir' commands to replicate content of that path.
# Initial motivation -- provide commands to embed into Container file.
set -eu
# Check if the path is provided
@yarikoptic
yarikoptic / walk.py
Created May 15, 2020 16:39
A dirty helper to time traversal of the file tree and collection of os.stat results for files. See https://github.com/con/pyfscacher/issues/1 for more info
#!/usr/bin/env python
import os
from os import stat
from os.path import join, islink
from time import time
from pathlib import Path
from functools import wraps
from joblib import Parallel, delayed
# old openfmri (excluding DataLad revisions)
git)smaug:/mnt/btrfs/datasets/datalad/crawl/openfmri[master]git
$> for ds in ds*; do nver=$(git -C $ds tag | grep -v '+' | wc -l) ; echo "$ds: $nver" ; done
ds000001: 7
ds000002: 7
ds000003: 5
ds000005: 4
ds000006: 4
ds000007: 4
ds000008: 4
import image
import math
angle = 10 # we humans think degrees
angle = angle*math.pi/180 # radians
img = image.Image("golden_gate.png")
height = img.getHeight()
width = img.getWidth()
win = image.ImageWin(width, height)
# An example from https://en.wikipedia.org/wiki/YAML#Advanced_components
# pretty printed as .json after "expansion":
$> cat /tmp/sample.yaml
# sequencer protocols for Laser eye surgery
---
- step: &id001 # defines anchor label &id001
instrument: Lasik 2000
pulseEnergy: 5.4
pulseDuration: 12
repetition: 1000
$> GIT_TRACE=1 'git' 'annex' --debug 'copy' '-c' 'annex.ssh-options="-S /var/run/user/47521/datalad/datalad.org"' 'Banner for bogus1-2' '--to=published15'
11:33:00.660049 git.c:560 trace: exec: 'git-annex' '--debug' 'copy' '-c' 'annex.ssh-options="-S /var/run/user/47521/datalad/datalad.org"' 'Banner for bogus1-2' '--to=published15'
11:33:00.660095 run-command.c:338 trace: run_command: 'git-annex' '--debug' 'copy' '-c' 'annex.ssh-options="-S /var/run/user/47521/datalad/datalad.org"' 'Banner for bogus1-2' '--to=published15'
11:33:00.697220 git.c:348 trace: built-in: git 'config' '--null' '--list'
11:33:00.716531 git.c:348 trace: built-in: git 'show-ref' 'git-annex'
11:33:00.719462 git.c:348 trace: built-in: git 'show-ref' '--hash' 'refs/heads/git-annex'
11:33:00.722880 git.c:348 trace: built-in: git 'log' 'refs/heads/git-annex..47313ce619b66d2b267e48e3d6d12f58e045ac29' '-n1' '--pretty=%H'
11:33:00.728138 git.c:348 trace:
12/07/15 15:44:30 DAEMONCORE: ReadCommand()
12/07/15 15:44:30 DAEMONCORE: EnableCrypto()
12/07/15 15:44:30 DAEMONCORE: VerifyCommand()
12/07/15 15:44:30 DAEMONCORE: SendResponse()
12/07/15 15:44:30 DAEMONCORE: SendResponse() : m_new_session
12/07/15 15:44:30 DAEMONCORE: ExecCommand(m_req == 516, m_real_cmd == 516, m_auth_cmd == 516)
12/07/15 15:44:30 ForkWorker::Fork: New child of 130209 = 138693
12/07/15 15:44:30 Number of Active Workers 0
12/07/15 15:44:30 DaemonCore: No more children processes to reap.
File "/home/buildbot/buildbot/venv/local/lib/python2.7/site-packages/buildbot/steps/source/git.py", line 185, in full
yield self.copy()
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 1097, in _inlineCallbacks
result = result.throwExceptionIntoGenerator(g)
File "/usr/lib/python2.7/dist-packages/twisted/python/failure.py", line 389, in throwExceptionIntoGenerator
return g.throw(self.type, self.value, self.tb)
File "/home/buildbot/buildbot/venv/local/lib/python2.7/site-packages/buildbot/steps/source/git.py", line 204, in incremental
action = yield self._sourcedirIsUpdatable()
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 577, in _runCallbacks
current.result = callback(current.result, *args, **kw)
#!/bin/bash
set -eu
cd $1
# First we will deal with .git/annex/objects
for d in .git/annex/objects/??/??/*; do
[ -d $d ] || continue
chmod +w $d $d/..
# although it must be the same name, let's be uber careful
mv $d ${d}_