Skip to content

Instantly share code, notes, and snippets.

I may be slow to respond.

Serge Bedzhyk smileart

I may be slow to respond.
View GitHub Profile
smileart /
Last active May 19, 2020
gemspec cli tools
# deps and their versions in gemspec
cat name.gemspec | ack -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~"
# deps and their version on RubyGems
cat british.gemspec | ack -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~" | awk '{ print $1 }' | xargs gem info -r | ack '\(\d+\.\d+\.\d+\)'
# gemspec and current remote versions side-by-side
paste <(cat $(ls | ack gemspec) | ack -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~") <(cat $(ls | ack gemspec) | ack -o '(?<=dependency).*(?<=[<>=]\s)(?>\d+\.?\d+)' | tr -d "',><=~" | awk '{ print $1 }' | xargs gem info -r | ack -o '(?<=\()(\d+\.\d+\.\d+)(?!>\))')

How to download your Udemy course videos using youtube-dl

$ youtube-dl --list-extractors | grep udemy


  1. Get link to the course to download. e.g.
  2. Login into udemy website, save the cookie from chrome using Chrome (Cookie.txt)[1] export extension. Save it to file udemy-cookies.txt
  3. Get the link of the video that you want to download. usually in format. Use the command provided below where you have to replace the {course_link} and {path_to_cookies_file} with respective paths.
$ youtube-dl {course_link} --cookies {path_to_cookies_file}
smileart / ranged_hash.rb
Created Jul 10, 2018
Benchmarking different RangedHash implementations
View ranged_hash.rb
require 'benchmark/ips'
class RangedHashSelect
def initialize(hash)
@data = Hash[ do |el|
el.respond_to?(:member?) ? el : (el..el)
smileart / epub_zip.rb
Created Jan 29, 2017
EPUB dirs re-zipping (iBooks → Nook)
View epub_zip.rb
#! /usr/bin/env ruby
require 'fileutils'
require 'shellwords'
dir = File.absolute_path ARGV[0]
results = "#{dir}/results"
Dir.mkdir(results) unless File.exist?(results)
puts "Working on: #{dir}"
smileart / hacker_data_loader.rb
Created Dec 11, 2016
HackerRank STDIN data loader
View hacker_data_loader.rb
class HackerDataLoader
SKIP_WORDS = [:ignore, :skip, :next].freeze
def self.load(input, quantifiers, format = {})
io = $stdin === input ? input :
result = {}
format.each_pair do |name, val|
smileart / mini_ruby.rb
Created Dec 10, 2016
Ruby "minification" script
View mini_ruby.rb
# Usage:
# 1) Require this script
# 2) Call MiniRuby.minify
# 3) Get one line as STDOUT
class MiniRuby
def self.minify
code =$0)
code.sub! /^([^#\R\n]*?)MiniRuby.minify(.*)$/, ''
code.sub! /require(_relative)? ["|'](.*?)mini_ruby(\.rb)?["|']/, ''
smileart /
Last active Jan 10, 2017
’Interactive’ / offline / CLI Ruby Regexp tester as an alternative to


Problem 1: Not many online/offline Regexp testing/debugging tools support Ruby Regexp syntax. But at the same time it's not very convenient to test Regexes right in your code or in the irb/pry (they are not interactive enough). Luckily we have Rubular, but…

Problem 2: Try to open Rubular and paste sample_data.txt content as a test string and regex.txt content as a regular expression. After matching highlight process is done (yeah, you have to be patient enough to see that) try to edit anything in Regexp…

Problem 3: Rubular currently supports Ruby 1.8.7 / 1.9.3 and 2.1.5, but it would be great to test your Regexes in your current Ruby version (just in case, to be 100% sure)

Problem 4: Sometimes highlighting ins't enough (because of a huge amount of the test data) it would be great to know exact count of occurrences.

smileart /
Last active Nov 2, 2015
MySQL DB backup script
#! /usr/bin/env bash
if [ ! -z $1 ] && [ ! -z $2 ] && [ ! -z $3 ] && [ ! -z $4 ]; then
archive_name="$(date +\%m\%d\%Y-\%H\%M\%S)_$db_name.sql.bz2"
You can’t perform that action at this time.