Skip to content

Instantly share code, notes, and snippets.

Avatar

Aleksandar N. Kostadinov akostadinov

View GitHub Profile
@akostadinov
akostadinov / split.sh
Last active Feb 18, 2022
ffmpeg split by chapter
View split.sh
#!/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 Feb 17, 2022
ffmpeg chapters creation
View FFMETADATAFILE.example
;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 Jan 14, 2022
Cucumber list-only filter. Will only print list of feature files that were selected for testing. Needs to be registered as a last filter.
View print_only_cuke_filter.rb
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
View rack_server.rb
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 Aug 19, 2021
represent Rails configuration as YAML
View rails_dump_config.rb
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
shows fonts containing character
View fonts_find.sh
#!/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={}"
View amicable.rb
# 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 Jan 26, 2021
Pretty print JSON-like exercise
View pretty_print_json.rb
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)}") +
@akostadinov
akostadinov / jenkins cancel running builds
Created Dec 22, 2020
Cancel all running Jenkins builds with system groovy script
View jenkins cancel running builds
import jenkins.model.Jenkins
def numCancels = 0;
Jenkins.instance.getAllItems(Job.class).each{
def job = it
for (build in job.builds) {
if (build.isBuilding()) { build.doStop(); numCancels++; }
}
}
@akostadinov
akostadinov / CSV-from-facebook-friends-export.rb
Last active Jan 22, 2021
Fix facebook broken exported UTF
View CSV-from-facebook-friends-export.rb
require 'json'
require 'uri'
require 'csv'
# too bad we lack variable size lookbehind
bytes_re = /((?:\\\\)+|[^\\])(?:\\u[0-9a-f]{4})+/
friends_txt = File.read('friends.json').gsub(bytes_re) do |bad_unicode|
$1 + eval(%Q{"#{bad_unicode[$1.size..-1].gsub('\u00', '\x')}"}).to_json[1...-1]
end