Skip to content

Instantly share code, notes, and snippets.

View aleskiontherun's full-sized avatar

Aleksei Vesnin aleskiontherun

View GitHub Profile
@aleskiontherun
aleskiontherun / cw2es.py
Last active July 23, 2020 08:53
Copy existing logs from CloudWatch to Elasticsearch
import json
import boto3
import gzip
import base64
import time
# AWS account ID
AWS_ACCOUNT_ID = "001234567890"
# CloudWatch log group name
@aleskiontherun
aleskiontherun / ClassFinder.groovy
Last active December 23, 2019 09:59
Find groovy classes in a package and all its subpackages. Scans the package directory and subdirectories. Works when running from a jar or the filesystem.
class ClassFinder {
static List<Class> findClasses(Class clazz) {
URL srcLocation = clazz.getProtectionDomain().getCodeSource().getLocation()
String packageName = clazz.package.name
List<String> classNames
if (srcLocation.toString().endsWith('.jar')) {
String packagePath = packageName.replaceAll(/\./, '/')
classNames = loadClassNamesFromJar(srcLocation, packagePath)
} else {
File dir = new File(clazz.getResource('').toURI())
@aleskiontherun
aleskiontherun / bulkDeleteJobs.groovy
Last active April 6, 2020 10:10
Groovy script to delete old disabled Jenkins jobs.
/*** BEGIN META {"name" : "Bulk Delete Jobs",
"comment" : "Delete jobs disabled and where last build is older than specified param",
"parameters" : [ 'dryRun', 'numberOfDays', 'excludeRegexp' ],
"core": "2.0",
"authors" : [{ name : "Benjamin Francisoud" }, { name : "Aleksei Vesnin" }]} END META**/
import jenkins.model.*
import java.util.regex.Pattern
@aleskiontherun
aleskiontherun / haproxy-ec2-register.sh
Created August 28, 2019 14:49
Register AWS EC2 instance in HAProxy.
#!/bin/bash
set -e
region=eu-central-1
haproxy_url=http://haproxy.internal:5555
haproxy_username=admin
haproxy_password=password
cluster_size=3
@aleskiontherun
aleskiontherun / _ctl.sh
Last active June 10, 2022 13:24
Pause/resume/stop process control in bash.
#!/usr/bin/env bash
TASK=$@
FAIL_CNT=0
RUN=
TASK_PID=
LOOPID=1
_ctl() {
@aleskiontherun
aleskiontherun / pritunl-backup.sh
Last active February 19, 2024 15:31
Backup and restore Pritunl database.
sudo service pritunl stop
mongodump -d pritunl -o pritunl-bkp
tar -czvf pritunl-bkp.tar.gz pritunl-bkp

Useful knife commands for a local Chef repo

Generate Chef secret

openssl rand -base64 512 | tr -d '\r\n' > /path/to/secret

Create encrypted data bag

export EDITOR=nano; knife data bag create BAG_NAME ITEM_NAME -z --secret-file /path/to/chef_secret
@aleskiontherun
aleskiontherun / yii-session-timeouts
Last active August 29, 2015 14:12
Yii login/session timeouts
CHttpSession.timout - session data will be cleaned up (default - 1440)
CHttpSession.cookieParams.lifetime - session cookie lifetime (default - 0 means "until the browser is closed.")
CWebUser.authTimeout - user is logged out if inactive (not set - after the current session expires)
CWebUser.absoluteAuthTimeout - user is logged out regardless of activity (not set - ommited)
==
CWebUser.allowAutoLogin = true
CWebUser.autoRenewCookie = false
@aleskiontherun
aleskiontherun / ffmpeg.sh
Last active September 5, 2016 04:56
Creating HTML5 video files with ffmpeg
# Based on https://blog.mediacru.sh/2013/12/23/The-right-way-to-encode-HTML5-video.html
# ogv
ffmpeg -i input.mp4 -q 5 -pix_fmt yuv420p -vcodec libtheora -vf "crop=1200:680:360:200" -an output.ogv
# Cropped WebM without audio
ffmpeg -i input.mp4 -c:v libvpx -pix_fmt yuv420p -quality good -b:v 2M -crf 5 -vf "crop=1200:680:360:200,scale=trunc(in_w/2)*2:trunc(in_h/2)*2" -an -f webm output.webm
# Same mp4
ffmpeg -i input.mp4 -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slower -b:v 2M -crf 18 -maxrate 4000k -bufsize 1835k -vf "crop=1200:680:360:200,scale=trunc(in_w/2)*2:trunc(in_h/2)*2" -an -movflags faststart -f mp4 output.mp4
#!/bin/bash
#
# The MIT License (MIT)
#
# Copyright (c) 2014 Mathias Leppich <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell