Skip to content

Instantly share code, notes, and snippets.

View rayworks's full-sized avatar
🍉

rayworks rayworks

🍉
  • Shanghai, China
  • 11:00 (UTC +08:00)
View GitHub Profile
@rayworks
rayworks / gist:69b8bb7720b46baa11ffb18b98161496
Last active December 5, 2019 03:31
Foreground DownloadService
import android.app.IntentService;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@rayworks
rayworks / gist:15ba92c2e93bc6b4d6270d52942313e3
Last active October 28, 2021 15:21
ffmpeg in practice
1. Compile configure
configuration: --enable-libass --enable-gpl --enable-libfreetype --enable-libvpx --enable-libx264 --enable-libmp3lame
--enable-libspeex --enable-libx265 --enable-nonfree --enable-videotoolbox --enable-audiotoolbox --enable-fontconfig
--enable-libfdk-aac
2. Add subtitles(字幕)
./ffmpeg -i input.mp4 -vf subtitles=your.srt output.mp4
3. Specify subtitles when playing the video
./ffplay -vf subtitles=your.srt input.mp4

FWIW: I didn't produce the content presented here (the outline from Edmond Lau's book). I've just copy-pasted it from somewhere over the Internet, but I cannot remember what exactly the original source is. I was also not able to find the author's name, so I cannot give him/her the proper credits.


Effective Engineer - Notes

What's an Effective Engineer?

@rayworks
rayworks / gist:428409347a4e1c69ab764da1b60856c8
Created February 2, 2019 05:46
Commands for screen recording and media convertion
adb shell screenrecord --time-limit 3 --bit-rate 2000000 --verbose /sdcard/demo.mp4
ffmpeg -ss 00:00:00.000 -i ./demo.mp4 -pix_fmt rgb24 -r 3 -s 270x480 -t 00:00:3.000 output.gif
@rayworks
rayworks / ViewUtils
Last active May 22, 2018 08:26
Using scaleType 'Matrix' to implement 'center_crop' or 'left_top aligned crop' effect
public static void setImageMatrixWithRatioKept(
ImageView view, Bitmap resource, boolean scaleByActualWidth, boolean alignmentCenter) {
view.setScaleType(ImageView.ScaleType.MATRIX);
int bmpWidth = resource.getWidth();
int bmpHeight = resource.getHeight();
int viewWidth = view.getWidth();
int viewHeight = view.getHeight();
float scaleWidth = 1.0f * viewWidth / bmpWidth;
grep -R --include="*.json" "YOUR-KEYWORDS\":" ./ | cut -d':' -f1 | sort | uniq
@rayworks
rayworks / gist:bd4cd60a728ae761baf81188285ae459
Created April 18, 2018 08:38
Multiple apks generated with different channel ids via Jenkins scripts
next=`cat /jenkins-jobs/your-job/nextBuildNumber`
one='1'
no=`echo $((next - one))`
rc=`ls /jenkins-jobs/your-job/builds/${no}/archive/app/build/outputs/apk/ | grep "app-live-release"`
java -jar /packer-tool-path/packer-ng-plugin/tools/packer-ng-2.0.0.jar generate --channels=google \
--output=/jenkins-jobs/your-job/builds/${no}/archive/app/build/outputs/apk/channel/ \
/jenkins-jobs/your-job/builds/${no}/archive/app/build/outputs/apk/${rc}
@rayworks
rayworks / downloader
Created April 13, 2018 09:49
A simple cancellable downloader
import okhttp3.ResponseBody;
import retrofit2.Call;
public interface Repository {
Call<ResponseBody> download(String url);
}
public void cancelCurrentDownloadingTask() {
if (call != null) {
call.cancel();
@rayworks
rayworks / PlaceHolderFragment
Created February 26, 2018 09:04
Get rid of IllegalStateException when comitting the fragment transaction after the activity’s state had been saved
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import java.util.LinkedList;
import timber.log.Timber;
@rayworks
rayworks / gist:d257306eb5f6d6b14a752d217984b107
Created November 24, 2017 09:51
Reset the view when applying MVP pattern
/**
* Returns the view configured in the presenter which real implementation is an Activity or
* Fragment using this presenter.
*/
public final T getView() {
return view;
}
/**
* Configures the View instance used in this presenter as view.