Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View akostadinov's full-sized avatar

Aleksandar N. Kostadinov akostadinov

View GitHub Profile
@akostadinov
akostadinov / mux.rb
Last active March 3, 2024 22:55
ffmpeg mux video audio and subtitle files with subtitles
#!/bin/env ruby
# License: MIT
require 'shellwords'
require 'tempfile'
class MuxerCLI
attr_reader :dir
@akostadinov
akostadinov / async_tests.rb
Last active November 28, 2023 21:09
async redis playground
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'concurrent-ruby', '~> 1.1.6'
@akostadinov
akostadinov / split.sh
Last active February 18, 2022 11:33
ffmpeg split by chapter
#!/usr/bin/env bash
# based on https://stackoverflow.com/a/61525373/520567
# you can play with -metadata and file name as you see fit
set -efu
videoFile="$1"
ffprobe -hide_banner \
@akostadinov
akostadinov / FFMETADATAFILE.example
Last active October 9, 2022 03:16
ffmpeg chapters creation
;FFMETADATA1
major_brand=mp42
minor_version=0
compatible_brands=mp42mp41
title=Sharks Group Video Film.mp4
comment=some comment
encoder=Lavf58.76.100
[CHAPTER]
TIMEBASE=1/1000
@akostadinov
akostadinov / print_only_cuke_filter.rb
Created January 14, 2022 16:39
Cucumber list-only filter. Will only print list of feature files that were selected for testing. Needs to be registered as a last filter.
require 'cucumber/core/filter'
# put inside features/support/
class PrintOnlyCukeFilter < Cucumber::Core::Filter.new
def test_case(test_case)
announce
print_file_for(test_case)
end
private
@akostadinov
akostadinov / rack_server.rb
Created November 18, 2021 14:18
Rack echo server
require "rack"
def pp(hash)
hash["HTTP_ACCEPT"].include?("text/html") ? pp_html(hash) : pp_plain(hash)
end
def pp_plain(hash)
hash.map {|key,value| "#{key}: #{value}"}.sort.join("\n")
end
@akostadinov
akostadinov / rails_dump_config.rb
Created August 19, 2021 11:18
represent Rails configuration as YAML
def dump_config(object = Rails.application.config.class.class_variable_get(:@@options))
case object
when Array
object.map { |v| dump_config(v) }
when Hash
Hash[ object.map { |key, value| [key, dump_config(value)] } ]
when TrueClass, FalseClass, Numeric
object
else
object.to_s
@akostadinov
akostadinov / fonts_find.sh
Created May 19, 2021 21:10
shows fonts containing character
#!/usr/bin/env bash
# example: ./font_find.sh 🎩︎
# credits: David Baynard, https://unix.stackexchange.com/a/393740/14907
param="$1"
char=${param:0:1}
printf '%x' \'"$char" | xargs -I{} fc-list ":charset={}"
@akostadinov
akostadinov / amicable.rb
Created March 1, 2021 22:05
amicable numbers
# https://www.jdoodle.com/execute-ruby-online/
def amicable?(int1, int2)
sum_proper_divisors(int1) == int2 && sum_proper_divisors(int2) == int1
end
def sum_proper_divisors(num)
(1..num/2).select { |i|
num%i == 0
}.sum
@akostadinov
akostadinov / pretty_print_json.rb
Created January 26, 2021 11:59
Pretty print JSON-like exercise
INDENT_SIZE = 2
def pretty_jsonify(struct, indent=0)
case struct
when Array
"[\n" + indent_str("", indent+INDENT_SIZE) +
struct.map { |value|
pretty_jsonify(value, indent+INDENT_SIZE)
}.join(",\n#{indent_str('', indent+INDENT_SIZE)}") +