Skip to content

Instantly share code, notes, and snippets.

View a-chernykh's full-sized avatar

Andrey Chernykh a-chernykh

View GitHub Profile
public class Mp4ParserAudioMuxer implements AudioMuxer {
@Override
public boolean mux(String videoFile, String audioFile, String outputFile) {
Movie video;
try {
video = new MovieCreator().build(videoFile);
} catch (RuntimeException e) {
e.printStackTrace();
return false;
} catch (IOException e) {
require 'net/http'
def download_net_http(urls, thread_count)
queue = Queue.new
urls.map { |url| queue << url }
threads = thread_count.times.map do
Thread.new do
Net::HTTP.start('our-s3-bucket.s3.amazonaws.com', 80) do |http|
while !queue.empty? && url = queue.pop
require 'em-http'
def download_em_http(urls, concurrency)
EventMachine.run do
multi = EventMachine::MultiRequest.new
EM::Iterator.new(urls, concurrency).each do |url, iterator|
req = EventMachine::HttpRequest.new(url).get
req.callback do
write_file url, req.response
require 'typhoeus'
def download_typhoeus(urls, concurrency)
hydra = Typhoeus::Hydra.new(max_concurrency: concurrency)
urls.each do |url|
request = Typhoeus::Request.new url
request.on_complete do |response|
write_file url, response.body
end
%i(net_http em_http typhoeus).each do |method|
Benchmark.bm(15) do |x|
(5..100).step(5) do |c|
x.report("#{method} #{c}") { send("download_#{method}", urls, c) }
end
end
end
class MyHashMap
BUCKETS = 100
attr_reader :iterations
def initialize
@values = []
@iterations = 0
end
class RomanToInt
def initialize(roman)
@roman = roman.downcase
end
def to_int
result = 0
roman = @roman
exceptions.each do |exception, exception_value|
@a-chernykh
a-chernykh / results.txt
Created July 3, 2014 17:19
Ruby linear search and binary search performance testing
Searching for 648248 in sorted array
user system total real
linear 34.070000 0.040000 34.110000 ( 34.127835)
native binary 0.000000 0.000000 0.000000 ( 0.000203)
binary recursive 0.000000 0.000000 0.000000 ( 0.000334)
binary iterative 0.000000 0.000000 0.000000 ( 0.000258)
@a-chernykh
a-chernykh / delicious_graph.rb
Last active August 29, 2015 14:03
Delicious tags to graph edges
require 'delicious'
require 'json'
require 'csv'
TAGS_FILE = 'tags.json'
EDGES_FILE = 'tags.csv'
def get_tags
cache_tags unless File.exist?(TAGS_FILE)
JSON.parse(File.read(TAGS_FILE))
Source Target Weight Type
video android 2 Undirected
video mediacodec 1 Undirected
video mediamuxer 1 Undirected