Skip to content

Instantly share code, notes, and snippets.

🐢
I may be slow to respond.

Serge Bedzhyk smileart

🐢
I may be slow to respond.
Block or report user

Report or block smileart

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View udemy-courses-download-using-cookies.md

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 Jul 10, 2018
Benchmarking different RangedHash implementations
View ranged_hash.rb
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 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
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 : StringIO.new(input)
result = {}
format.each_pair do |name, val|
@smileart
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 = File.read($0)
code.sub! /^([^#\R\n]*?)MiniRuby.minify(.*)$/, ''
code.sub! /require(_relative)? ["|'](.*?)mini_ruby(\.rb)?["|']/, ''
@smileart
smileart / README.md
Last active Jan 10, 2017
’Interactive’ / offline / CLI Ruby Regexp tester as an alternative to http://rubular.com
View README.md

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.

@smileart
smileart / db_backup.sh
Last active Nov 2, 2015
MySQL DB backup script
View db_backup.sh
#! /usr/bin/env bash
PRESERVE_FILES_COUNT=3
ARCHIVE_EXTENSION='.sql.bz2'
if [ ! -z $1 ] && [ ! -z $2 ] && [ ! -z $3 ] && [ ! -z $4 ]; then
backup_dir=$1
db_user=$2
db_pass=$3
db_name=$4
archive_name="$(date +\%m\%d\%Y-\%H\%M\%S)_$db_name.sql.bz2"
View boot2docker-use-nfs.sh
#!/bin/bash
#
# This script will mount /Users in the boot2docker VM using NFS (instead of the
# default vboxsf). It's probably not a good idea to run it while there are
# Docker containers running in boot2docker.
#
# Usage: sudo ./boot2docker-use-nfs.sh
#
You can’t perform that action at this time.