Skip to content

Instantly share code, notes, and snippets.

View a-chernykh's full-sized avatar

Andrey Chernykh a-chernykh

View GitHub Profile
@a-chernykh
a-chernykh / test_upload_speed.rb
Created April 2, 2014 12:41
Amazon S3 speed test
require 'fog'
require 'benchmark'
storage = Fog::Storage.new({:provider => 'AWS', :aws_access_key_id => ENV['AWS_ACCESS_KEY_ID'], :aws_secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'], :region => 'eu-west-1'})
directory = storage.directories.get('roadar-test1')
puts Benchmark.realtime {
directory.files.create(
:key => 'test.jpg',
:body => File.open("test.jpg"),
@a-chernykh
a-chernykh / example.rb
Created April 8, 2014 12:00
em-http-request batch downloader with configurable concurrency level
class Downloader
CONCURRENCY = 50
def initializer(urls)
@urls = urls
end
def download
EventMachine.run do
EM::Iterator.new(@urls, CONCURRENCY).each do |url, iterator|
@a-chernykh
a-chernykh / run.sh
Created April 17, 2014 13:16
Debug state leak with Rspec (wait till it fails and re-run with last random seed)
#!/bin/bash
rspec spec --order rand:$RANDOM
while [ $? -eq 0 ]; do
rspec spec --order rand:$RANDOM
done
@a-chernykh
a-chernykh / Gemfile
Created June 15, 2014 17:39
Import delicious bookmarks from 1 user to another
source 'https://rubygems.org'
gem 'delicious', '~> 1.0.0'
@a-chernykh
a-chernykh / BufferedWritableFileByteChannel.java
Last active August 29, 2015 14:03
Buffered WritableByteChannel implementation
private static class BufferedWritableFileByteChannel implements WritableByteChannel {
private static final int BUFFER_CAPACITY = 1000000;
private boolean isOpen = true;
private final OutputStream outputStream;
private final ByteBuffer byteBuffer;
private final byte[] rawBuffer = new byte[BUFFER_CAPACITY];
private BufferedWritableFileByteChannel(OutputStream outputStream) {
this.outputStream = outputStream;
@a-chernykh
a-chernykh / MediaCodecConfiguration.java
Created June 28, 2014 10:03
MediaCodec configuration sample
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN
&& MediaCodecFormatSelector.forDevice().isSupported()) {
binder.bind(VideoEncoder.class).to(MediaCodecVideoEncoder.class);
} else {
binder.bind(VideoEncoder.class).to(JpegVideoEncoder.class);
}
@a-chernykh
a-chernykh / MediaCodecFormatSelector.java
Created June 28, 2014 10:03
MediaCodecFormatSelector
public class MediaCodecFormatSelector {
public static MediaCodecFormatSelector forDevice() {
String deviceName = Device.getDeviceName();
if (deviceName.equalsIgnoreCase("samsung gt-i9300")
&& isBadMediaCodecSupport()) {
return new SamsungGalaxyS3MediaCodecFormatSelector();
else if (isBadMediaCodecSupport() && isAffectedDevice(deviceName)) {
return new NoMediaCodecSupportFormatSelector();
} else {
return new MediaCodecFormatSelector();
public interface VideoEncoder {
boolean prepare(Context context);
boolean sendFrame(@NotNull byte[] frame);
Frame receiveFrame() throws VideoEncoderError;
}
public static byte[] NV21toYUV420Planar(byte[] input, byte[] output, int width, int height) {
final int frameSize = width * height;
final int qFrameSize = frameSize/4;
System.arraycopy(input, 0, output, 0, frameSize); // Y
byte v, u;
for (int i = 0; i < qFrameSize; i++) {
v = input[frameSize + i*2];
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) {