Skip to content

Instantly share code, notes, and snippets.

View smileart's full-sized avatar
:octocat:

Serge Bedzhyk smileart

:octocat:
View GitHub Profile
@smileart
smileart / parse_fields.rb
Last active February 3, 2021 16:22
A little AWK-like method to parse fields in a string of text
text = <<~DOC
ID Name Type Size Date
735557379 Mitch Murder - Kung Fury (Lost Tapes) - 2015 FOLDER 38.37 MB 8 months ago
589243897 A Game Of Thrones ~ Books 1-5 EPUB,MOBI & PDF [GrYff0N] FOLDER 83.36 MB 2 years ago
735557525 VA - Kung Fury (2015) FOLDER 109.84 MB 8 months ago
819683233 19000 FOLDER 1.77 GB 2 days ago
819682329 18000 FOLDER 3.12 GB 2 days ago
819681592 17000 FOLDER 4.23 GB 2 days ago
784060241 Doctor.Who.2005.S12.1080p.BluRay.x264-SHORTBREHD FOLDER 31.73 GB 2 months ago
601795129 chill.institute FOLDER 51.66 GB 2 days ago
@smileart
smileart / docker_volumes_backup.sh
Last active October 13, 2020 23:20
Backing up and Restoring named Docker volumes
# Based on
https://stackoverflow.com/questions/38298645/how-should-i-backup-restore-docker-named-volumes
# Dependencies
brew install fzf fx
# Backup (docker-compose running and we're in the same dir)
export CONTAINER_NAME=$(docker ps --format '{{.Names}}' | fzf) && \
export VOLUME_NAME=$(docker inspect $CONTAINER_NAME | fx '.[0].Mounts[0].Name') && \
docker stop $(docker inspect $CONTAINERNAME | fx '.[0].Id') && \
@smileart
smileart / tapp_amazing_print.rb
Created September 22, 2020 07:04
tapp + amazing_print
require 'tapp'
require 'tapp/printer'
require 'amazing_print'
# Module to define own Tapp printer
module Tapp::Printer
# Custom AmazingPrint based printer for Tapp
class AmazingPrint < Base
# Prints the object using custom (AmazingPrint) printer
#
@smileart
smileart / gemspec.sh
Last active September 15, 2023 21:50
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

Steps

  1. Get link to the course to download. e.g. https://www.udemy.com/course-name/
  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
smileart / ranged_hash.rb
Created July 10, 2018 14:51
Benchmarking different RangedHash implementations
require 'benchmark/ips'
class RangedHashSelect
def initialize(hash)
@data = Hash[
hash.keys.map do |el|
el.respond_to?(:member?) ? el : (el..el)
end.zip(hash.values)
]
end
@smileart
smileart / epub_zip.rb
Created January 29, 2017 12:11
EPUB dirs re-zipping (iBooks → Nook)
#! /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
smileart / hacker_data_loader.rb
Created December 11, 2016 20:47
HackerRank STDIN data loader
class HackerDataLoader
SKIP_WORDS = [:ignore, :skip, :next].freeze
def self.load(input, quantifiers, format = {})
io = $stdin === input ? input : StringIO.new(input)
result = {}
format.each_pair do |name, val|
@smileart
smileart / mini_ruby.rb
Created December 10, 2016 20:37
Ruby "minification" script
# Usage:
# 1) Require this script
# 2) Call MiniRuby.minify
# 3) Get one line as STDOUT
class MiniRuby
def self.minify
code = File.read($0)
code.sub! /^([^#\R\n]*?)MiniRuby.minify(.*)$/, ''
code.sub! /require(_relative)? ["|'](.*?)mini_ruby(\.rb)?["|']/, ''