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 / 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 / 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 / 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 / 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 / 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 / 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 / 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;