Skip to content

Instantly share code, notes, and snippets.

@MVKozlov
MVKozlov / sysv.init.script.to.systemd.unit.file.md
Created January 26, 2024 07:33 — forked from houtianze/sysv.init.script.to.systemd.unit.file.md
Convert SysV Init scripts to Systemd Unit File

Let's say you have a SysV Init Script named foo

  1. Copy the file to /etc/init.d/foo

  2. Enable the SysV service: chkconfig --add foo

  3. Enable the SysV service: chkconfig foo on

  4. Start the service: service foo start. After this, systemd-sysv-generator will generate this file /run/systemd/generator.late/foo.service, copy this file to /etc/systemd/system by running: cp /run/systemd/generator.late/foo.service /etc/systemd/system/foo.service

  5. Edit /etc/systemd/system/foo.service by running systemctl edit foo.service, add in the following line to foo.servie (this makes the service installable)

[Install]

@MVKozlov
MVKozlov / New-JwtToken.ps1
Last active November 13, 2023 09:37
New-JwtToken implementation in powershell
function New-JwtToken {
<#
.SYNOPSIS
Creates a JWT token.
.DESCRIPTION
Creates a JWT token.
.PARAMETER Algorithm
A string containing the algorithm to use.
.PARAMETER Issuer
A string containing the issuer to use.
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
using System.Text;
namespace DetectSsd
{
public class Program
{
// For CreateFile to get handle to drive
@MVKozlov
MVKozlov / README.md
Created March 24, 2023 12:29 — forked from tannerlinsley/README.md
Replacing Create React App with the Next.js CLI

Replacing Create React App with the Next.js CLI

How dare you make a jab at Create React App!?

Firstly, Create React App is good. But it's a very rigid CLI, primarily designed for projects that require very little to no configuration. This makes it great for beginners and simple projects but unfortunately, this means that it's pretty non-extensible. Despite the involvement from big names and a ton of great devs, it has left me wanting a much better developer experience with a lot more polish when it comes to hot reloading, babel configuration, webpack configuration, etc. It's definitely simple and good, but not amazing.

Now, compare that experience to Next.js which for starters has a much larger team behind it provided by a world-class company (Vercel) who are all financially dedicated to making it the best DX you could imagine to build any React application. Next.js is the 💣-diggity. It has amazing docs, great support, can grow with your requirements into SSR or static site generation, etc.

So why

@MVKozlov
MVKozlov / get-sshfingerprint.ps1
Created July 26, 2022 08:27 — forked from RulerOf/get-sshfingerprint.ps1
Get SSH host key fingerprint using PowerShell. Requires the WinSCP .Net assembly.
function Get-SshFingerprint {
param( [string]$ssh_server )
# Load WinSCP .NET assembly
Add-Type -Path "${env:ProgramFiles(x86)}\WinSCP\WinSCPnet.dll"
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Sftp
HostName = $ssh_server
@MVKozlov
MVKozlov / tokens.md
Created July 7, 2022 17:24 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Last major update: 25.08.2020

  • Что такое авторизация/аутентификация
  • Где хранить токены
  • Как ставить куки ?
  • Процесс логина
  • Процесс рефреш токенов
  • Кража токенов/Механизм контроля токенов
@MVKozlov
MVKozlov / Import-SelfContainedCertificate.ps1
Created April 12, 2022 06:09
Import self contained certificate into certificate store
#Cert content:
# PSv7 $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -AsByteStream), 'InsertLineBreaks')
# PSv5.1 $cert = [Convert]::ToBase64String((Get-Content D:\Path\To\Certificate.pfx/cer -Encoding Byte), 'InsertLineBreaks')
$Cert = @"
MIILYgIBAzCCCx4GCSqGSIb3DQEHAaCCCw8EggsLMIILBzCCBjAGCSqGSIb3DQEHAaCCBiEEggYd
.....
/+1y1lZqkQICB9A=
"@
#Cdert location: #LocalMachine, CurrentUser
@MVKozlov
MVKozlov / server.py
Created February 15, 2022 20:11 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class S(BaseHTTPRequestHandler):
@MVKozlov
MVKozlov / Invoke-DataCollector.ps1
Last active December 19, 2023 13:27
Run selected script for computer list and save results in a file. Can be used multiple times until all collected
<#
.SYNOPSIS
Run selected script for computer list and save results in a file. Can be used multiple times until all collected
.DESCRIPTION
Run the specified script for the list of computers and save the launch results to the Clixml file
The result file contains the script being launched (Script) and the results of previous executions (Data).
Restarting works only for computers with no success
If the file has already been created, only the path to the file is needed for repeated runs
PoshRSJob module required for parallel script execution
.PARAMETER Path
@MVKozlov
MVKozlov / Convert-PfxToPem.ps1
Created April 14, 2021 06:39 — forked from rmbolger/Convert-PfxToPem.ps1
Convert-PfxToPem.ps1
# Adapted from Vadims Podāns' amazing work here.
# https://www.sysadmins.lv/blog-en/how-to-convert-pkcs12pfx-to-pem-format.aspx
#
# Also, if you need a more complete PKI PowerShell module, he has authored one here:
# https://github.com/Crypt32/PSPKI
#
# This version of the function includes a few fixes from the module's version of the
# function and changes up the output options so you get separate .crt/.key files by
# default named the same as the pfx file (or thumbprint if directly referencing a cert).
# -IncludeChain adds an additional -chain.pem. Relative paths are now