Skip to content

Instantly share code, notes, and snippets.

View nsuvorov83's full-sized avatar

Nikolay Suvorov nsuvorov83

  • VTB
  • Moscow
View GitHub Profile
@nsuvorov83
nsuvorov83 / backup_custom_dir.sh
Last active August 3, 2023 11:51
Backups "custom_dir" into git repo with current datetime as a message
#Backups "custom_dir" into git repo with current datetime as a message
today=`date +%Y-%m-%dT%H:%M:%S`
cd ~/custom_dir
git add .
git commit -m "Backup: $today"
#For digest auth
http_port 3128
via off
cache deny all
auth_param digest program /usr/lib/squid/digest_file_auth -c /etc/squid/users
auth_param digest children 5
auth_param digest realm PASS-PLEASE
auth_param basic credentialsttl 1 minute
auth_param basic casesensitive off
@nsuvorov83
nsuvorov83 / set_files_created_date.py
Created October 1, 2022 19:04
Sets obsidian notes creation date based on "created_at" field in metadata. Works for all notes in certain dir recursively. Modify date same as date of creation. Time is always 00:00.
import os
import glob
def modify_file_date(f):
with open(f) as file:
for l in file.readlines():
if (l[:11] == "created_at:"):
try:
dt = l[11:].replace("\n", "").replace('"', '').replace(' ', '').split(".")
dt = dt[2] + dt[1] + dt[0] + '0000.00'
@nsuvorov83
nsuvorov83 / obsidian-note-writer.py
Created September 26, 2022 14:38
Creates a note in an obsidian vault with attachments.
import os
import datetime
import shutil
def writer(folder_to_save, date, time, tags = [], note_name = "", note_text = "", attachments = [], resource_folder = "_resources"):
#Forming a dictionary
props = {}
props['folder_to_save'] = folder_to_save
props['date'] = date
props['time'] = time
@nsuvorov83
nsuvorov83 / yd-syncthing.sh
Created September 15, 2022 21:19
Run containers yandex-disk and syncthing
#See Dockerfile here: https://github.com/nsuvorov83/docker-yandex.disk
#Setup yandex.disk
docker run -it --rm --name yandex-disk -v yd-config:/root/.config/yandex-disk -v yd-data:/root/Yandex.Disk yandex-disk sh -c "yandex-disk --dir=/root/Yandex.Disk setup"
#Run yandex.disk as a daemon
docker run -d --restart always -v yd-config:/root/.config/yandex-disk -v yd-data:/root/Yandex.Disk yandex-disk sh -c "yandex-disk --dir=/root/Yandex.Disk start && tail -f /dev/null"
#Run Syncthing with the same volume as yandex.disk
docker run -d --name=syncthing --hostname=syncthing -e PUID=1000 -e PGID=1000 -e TZ=Europe/Moscow -p 8384:8384 -p 22000:22000/tcp -p 22000:22000/udp -p 21027:21027/udp -v syncthing-conf:/config -v yd-data:/data1 --restart unless-stopped lscr.io/linuxserver/syncthing:latest
@nsuvorov83
nsuvorov83 / Dockerfile
Created September 10, 2022 08:34
Starting docker with two processes: core daemon (yandex-disk) and fake process to prevent docker to stop
FROM ubuntu:22.04
RUN apt-get update \
# Upgrade
&& apt-get upgrade -y \
&& apt-get dist-upgrade -y \
# Install dependencies
&& apt-get install wget -y \
function forEveryCell(sheet, ra, func) {
/*
* Осуществляет вызов func для каждой ячейки диапазона ra на листе sheet
*
* Пример вызова:
* forEveryCell("deals", "G3:G", function (cell) {Logger.log(cell.getValue())});
*
*/
var range = SpreadsheetApp.getActive().getSheetByName(sheet).getRange(ra);
var rows = range.getNumRows();
from openpyxl import load_workbook
import pandas as pd
def load_df_table(filename, worksheet, tablename):
wb = load_workbook(filename)
ws = wb[worksheet]
dfs = {}
for table_name, value in ws.tables.items():
table = ws[value]
(ZIPFile) =>
let
Header = BinaryFormat.Record([
MiscHeader = BinaryFormat.Binary(14),
BinarySize = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
FileSize = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
FileNameLen= BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian),
ExtrasLen = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian)
]),
@nsuvorov83
nsuvorov83 / RenameColumns.m
Created April 2, 2018 15:27
PowerQuery renames all columns with answers except a column "Question" to range "AnswerN". Used to anonymise results of survey.
let
Source = Table1,
Transformed = Table.TransformColumnNames(Source, each if Text.Contains(_,"Question") then _ else Text.Replace(_, _, "Answer"))
in
Transformed