Skip to content

Instantly share code, notes, and snippets.

@mikhailnov
mikhailnov / rosa-repos-stats.sh
Created November 17, 2022 13:37
Скрипт подсчета статистики по репозиторию ROSA Linux
#!/bin/bash
set -e
set -o pipefail
trap 'echo ОШИБКА' ERR
# список пакетов в репах
# --disablerepo '*i686*' т.к. большинство пакетов есть и в 32, и в 64 битных вариантах
pkgs_list="$(dnf --disablerepo '*i686*' repoquery --qf '%{name} %{sourcerpm}' 2>/dev/null | sort -u)"
# кол-во пакетов в этом списке
pkgs_num="$(echo "$pkgs_list" | grep -c .)"
@mikhailnov
mikhailnov / calc.py
Created October 31, 2022 13:48
Калькулятор доходности накопительного счета или вклада с ежемесячной капитализацией
#!/usr/bin/env python
a=100000
s=12*1
sum=a
for i in range(0, s):
sum=sum*(1+0.08/12)
print(sum-a)
#!/bin/bash
# install: xdotool, binutils (strings), procps (pgrep), sed, grep
# usage: ./xdotool-sddm-login.sh <username> <password>
set -e
set -f
user="$1"
if [ -z "$user" ]; then
@mikhailnov
mikhailnov / watch_file.c
Created December 8, 2021 11:00
Wait until a file appears in C
#include <unistd.h>
#include <stdio.h>
int main(){
for(;;){
if (access("/tmp/xxx", F_OK) == 0) {
printf("%s", "File exists\n");
break;
} else {
sleep(1);
@mikhailnov
mikhailnov / realm.c
Created November 25, 2021 07:01
Check if libkrb5 understands a realm
// gcc -g realm.c -o realm -lkrb5
// HOST=XXX.LOC ./realm
#include <stdlib.h>
#include <stdio.h>
#include <krb5/krb5.h>
int main(){
// nfs-utils/utils/gssd/krb5_util.c, find_keytab_entry()
krb5_error_code test;
krb5_context context;
@mikhailnov
mikhailnov / assocheck.sh
Created August 18, 2020 10:52
Crazy assocheck.sh from WPS Office 11.x
#!/bin/bash
unset XDG_DATA_HOME
templatedir="/opt/kingsoft/wps-office/office6/asso_template"
if [ ! -d $templatedir ]; then
echo "asso_template not found"
exit 1
fi
mimelist=(".pptx" ".ppt" ".pptm" ".pps" ".pot" ".potm" ".potx" ".ppsx" ".dps" ".dpsx" ".dpt" ".dptx" ".dpss" ".dpso" ".xlsx" ".xls" ".xlsm" ".xlt" ".xltm" ".xltx" ".et" ".etx" ".ett" ".ettx" ".ets" ".eto" ".docx" ".docm" ".doc" ".dot" ".dotm" ".dotx" ".wps" ".wpsx" ".wpss" ".wpso" ".wpt" ".wptx" ".rtf")
#!/usr/bin/env bash
LIST="${LIST:-30 31 32}"
_gen(){
set -e
trap 'echo ERROR $line' ERR
line="$1"
fc="$2"
suffix="$(echo "$line" | tr '.' '\n' | grep ^fc | tail -n1)"
@mikhailnov
mikhailnov / amon.c
Created February 19, 2020 21:18
amon.c -exec override, https://debian.pro/369
/*
*
* Info: amon.so
* Contact: mailto: <luca [at] lucaercoli.it> https://www.lucaercoli.it
* Version: 1.1
* Author: Luca Ercoli
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@mikhailnov
mikhailnov / st.c
Last active February 13, 2020 11:41
Get default selinux user context
// gcc -lselinux st.c -o st.bin
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <selinux/selinux.h>
#include <selinux/get_context_list.h>
int main(){
security_context_t *contextlist = NULL;
int rc = -1;
#!/bin/sh
set -efu
export DEBIAN_FRONTEND=noninteractive
FALLBACK=0
APT_MAIN=0
DONE=0
khpkg=""
kernel="$(uname -r || :)"
if [ -z "$kernel" ]; then
echo "Unable to get kernel version, trying fallback"