Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View smileart's full-sized avatar
:octocat:
Work In Progress

Serge Bedzhyk smileart

:octocat:
Work In Progress
View GitHub Profile
@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)?["|']/, ''
@smileart
smileart / README.md
Last active January 10, 2017 18:03
’Interactive’ / offline / CLI Ruby Regexp tester as an alternative to http://rubular.com

Motivation

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.