Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Viktor Ponomarenko davinctor

🎯
Focusing
View GitHub Profile
@davinctor
davinctor / sample.js
Created Jul 19, 2018
Redux using sample
View sample.js
// 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 Jun 21, 2018 — forked from anry200/ScalableVideoView.java
Android : How to stretch video to use whole area of VideoView (code snippets)
View ScalableVideoView.java
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 Aug 1, 2017
Convert android studio dump HPROF to MAT compatible format dump
View convert_to_4mat_dump.sh
~/Android/Sdk/platform-tools/hprof-conv ~/Downloads/dump.hprof ~/Downloads/4mat_dump.hprof
@davinctor
davinctor / frames_with_timestamps.sh
Created Jul 3, 2017
Extract frames from gifs with timestamps
View frames_with_timestamps.sh
# 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 / video2gif.sh
Created Jul 3, 2017
Convert video to gif
View video2gif.sh
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 Apr 27, 2017
How to make N-retries with D-delay when observable fail with RxJava
View RxRetryWithDelaySample.java
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) {
View Sample.java
public enum UpdateMode {
UPDATE_SIMPLE_MODE(ConnectivityMode.WIFI, ConnectivityMode.ETHERNET),
UPDATE_FAST_MODE(ConnectivityMode.ETHERNET)
}
public enum ConnectivityMode {
WIFI,
ETHERNET
}
View AmazonS3RequestFactory.java
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 / RetryWithDelayTransformer.java
Last active Feb 3, 2020
Observable.Transformer to add retry feature to source observable if it fails. Every retry can be delayed.
View RetryWithDelayTransformer.java
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 / AddWifiNetwork.java
Created Feb 13, 2017 — forked from tiwiz/AddWifiNetwork.java
Add your Wi-Fi Network to Android Things
View AddWifiNetwork.java
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);