Skip to content

Instantly share code, notes, and snippets.

View getvictor's full-sized avatar

Victor Lyuboslavsky getvictor

View GitHub Profile
@getvictor
getvictor / scripts_performance_test.go
Created September 4, 2025 17:26
Test to analyze Fleet's GetHostScriptDetails performance
package mysql
import (
"context"
"fmt"
"testing"
"time"
"github.com/fleetdm/fleet/v4/server/fleet"
"github.com/fleetdm/fleet/v4/server/ptr"
@getvictor
getvictor / create_package.zsh
Last active May 9, 2025 21:44
Create a wrapper macOS package for InstallEnterpriseApplication MDM command
#!/bin/zsh
#
# Prerequisites:
# 0. Developer ID Installer certificate and NotaryProfile in the keychain.
# 1. Installers/fleet-osquery.pkg (will be signed and notarized if needed)
# 2. postinstall script that installs the above package
#
# Script to create, sign, and notarize a macOS package that:
# 1. Checks if fleet-osquery.pkg is signed and notarized, and processes it if needed
# 2. Installs the Installers directory to /Library
@getvictor
getvictor / arch_test.go
Last active February 7, 2025 19:51
How to find package dependencies of a Go package. Full article: https://victoronsoftware.com/posts/go-package-dependencies/
package arch_test
import (
"container/list"
"go/build"
"slices"
"strings"
"testing"
"golang.org/x/tools/go/packages"
@getvictor
getvictor / after.go
Last active January 17, 2025 16:51
Refactoring example
func (ds *Datastore) batchSetMDMAppleDeclarations(ctx context.Context, tx sqlx.ExtContext, tmID *uint,
incomingDeclarations []*fleet.MDMAppleDeclaration) (updatedDB bool, err error) {
enrichedDeclarations := enrichDeclarations(incomingDeclarations)
existingDecls, err := ds.getExistingDeclarations(ctx, tx, enrichedDeclarations, tmID)
if err != nil {
return false, ctxerr.Wrap(ctx, err, "load existing declarations")
}
@getvictor
getvictor / create-cloudfront-signed-url.go
Created January 6, 2025 15:01
Create a CloudFront signed URL
package main
import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
@getvictor
getvictor / edit-google-sheets.go
Last active December 18, 2024 19:26
Edit Google Sheets spreadsheets using API key of a service account. Full article: https://victoronsoftware.com/posts/google-sheets-api/
package main
import (
"context"
"fmt"
"log"
"os"
"strconv"
"time"
@getvictor
getvictor / ndes-test.ps1
Last active October 2, 2024 13:17
Test NDES SCEP server using PowerShell. Full article: https://victoronsoftware.com/posts/test-ndes-scep-server/
$NDESUrl = "http://10.0.0.74/certsrv/mscep/mscep.dll"
$ChallengePassword = "57D866A6E517F840"
$CommonName = "TestNDESWithPS"
$KeyLength = 2048
$SCEPProcessDefault = 0x0
$Pkcs10 = New-Object -ComObject "X509Enrollment.CX509CertificateRequestPkcs10"
# The certificate is intended for a computer.
# See X509Enrollment.X509CertificateEnrollmentContext enumeration.
$Pkcs10.Initialize([Int](2))
package main
import (
"flag"
"fmt"
"io"
"os"
"github.com/kballard/go-shellquote"
)
services:
mysql_source:
image: mysql:8.4.3
volumes:
- mysql-source:/tmp
command:
[
"mysqld",
"--datadir=/tmp/mysqldata-source",
"--log-bin=bin.log",
@getvictor
getvictor / calendar.go
Created March 5, 2024 21:39
Using domain-wide delegation with Google calendar events
package main
import (
"context"
"golang.org/x/oauth2/google"
"golang.org/x/oauth2/jwt"
"google.golang.org/api/calendar/v3"
"google.golang.org/api/option"
"log"
"time"