Skip to content

Instantly share code, notes, and snippets.

View davinctor's full-sized avatar
🎯
Focusing

Viktor Ponomarenko davinctor

🎯
Focusing
View GitHub Profile
@davinctor
davinctor / frames_with_timestamps.sh
Created July 3, 2017 15:44
Extract frames from gifs with timestamps
# Regular expression definitions to get frame number, and to get video duration from ffmpeg -i
FRAME_REGEX="frame-([0-9]*)\.jpeg"
LEN_REGEX="Duration: ([0-9]*):([0-9]*):([0-9]*)\.([0-9]*), start"
# Loops through the files passed in command line arguments,
# example: videotoframes video-*.mp4
# or: videotoframes file1.mp4 file2.mp4 file3.mp4
for vf in "$@"; do
video_info=$(ffmpeg -i $vf 2>&1) # Get the video info as a string from ffmpeg -i
[[ $video_info =~ $LEN_REGEX ]] # Extract length using reges; Groups 1=hr; 2=min; 3=sec; 4=sec(decimal fraction)
@davinctor
davinctor / RetryWithDelayTransformer.java
Last active February 3, 2020 23:39
Observable.Transformer to add retry feature to source observable if it fails. Every retry can be delayed.
import android.support.annotation.IntRange;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import com.petcube.android.helpers.Log;
import java.util.concurrent.TimeUnit;
import rx.Observable;
import rx.Subscriber;
@davinctor
davinctor / sample.js
Created July 19, 2018 15:02
Redux using sample
// Easily run on `https://stephengrider.github.io/JSPlaygrounds/`
const reducer = (state = [], action) => {
switch (action.type) {
case 'split_string':
return action.payload.split('');
case 'add_character':
return [ ...state, action.payload ];
default:
return state;
@davinctor
davinctor / ScalableVideoView.java
Created June 21, 2018 08:41 — forked from anry200/ScalableVideoView.java
Android : How to stretch video to use whole area of VideoView (code snippets)
import android.content.Context;
import android.util.AttributeSet;
import android.widget.VideoView;
public class ScalableVideoView extends VideoView {
private int mVideoWidth;
private int mVideoHeight;
private DisplayMode displayMode = DisplayMode.ORIGINAL;
@davinctor
davinctor / convert_to_4mat_dump.sh
Created August 1, 2017 10:25
Convert android studio dump HPROF to MAT compatible format dump
~/Android/Sdk/platform-tools/hprof-conv ~/Downloads/dump.hprof ~/Downloads/4mat_dump.hprof
@davinctor
davinctor / video2gif.sh
Created July 3, 2017 15:43
Convert video to gif
palette="/tmp/palette.png"
filters="fps=60,scale=1024:-1:flags=lanczos"
ffmpeg -i shoot.mov -vf "$filters,palettegen" -y $palette
ffmpeg -i shoot.mov -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y output.gif
@davinctor
davinctor / RxRetryWithDelaySample.java
Created April 27, 2017 10:21
How to make N-retries with D-delay when observable fail with RxJava
Observable.<Integer>error(new RuntimeException("Hey, try to catch it!"))
.doOnError(new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
Log.e("TEST", "DO ON ERROR CALLBACK");
}
})
.compose(new Observable.Transformer<Integer, Integer>() {
@Override
public Observable<Integer> call(Observable<Integer> integerObservable) {
@davinctor
davinctor / Sample.java
Created March 31, 2017 15:38
Inner enum
public enum UpdateMode {
UPDATE_SIMPLE_MODE(ConnectivityMode.WIFI, ConnectivityMode.ETHERNET),
UPDATE_FAST_MODE(ConnectivityMode.ETHERNET)
}
public enum ConnectivityMode {
WIFI,
ETHERNET
}
@davinctor
davinctor / AmazonS3RequestFactory.java
Created March 14, 2017 11:59 — forked from NightlyNexus/AmazonS3RequestFactory.java
Creates okhttp3.Requests for uploading files to an Amazon S3 storage bucket. Implements https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-authentication-HTTPPOST.html
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
import okio.BufferedSource;
import okio.ByteString;
@davinctor
davinctor / AddWifiNetwork.java
Created February 13, 2017 22:45 — forked from tiwiz/AddWifiNetwork.java
Add your Wi-Fi Network to Android Things
String networkSSID = "Your Network SSID here";
String networkPasskey = "YourNetworkPasswordHere";
WifiConfiguration wifiConfiguration = new WifiConfiguration();
wifiConfiguration.SSID = "\"" + networkSSID + "\"";
wifiConfiguration.preSharedKey = "\"" + networkPasskey + "\"";
WifiManager manager = (WifiManager) getSystemService(WIFI_SERVICE);
manager.addNetwork(wifiConfiguration);