Skip to content

Instantly share code, notes, and snippets.

View rayworks's full-sized avatar
:octocat:

rayworks rayworks

:octocat:
  • Shanghai, China
  • 14:31 (UTC +08:00)
View GitHub Profile
@rayworks
rayworks / CompatibleSSLSockFactory.java
Created July 21, 2020 10:39
The compatible version of SSLSocketFactory for resolving SNI issue when using library android-async-http with version 1.4.x
import android.util.Log;
import java.io.IOException;
import java.lang.reflect.Method;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
@rayworks
rayworks / main.dart
Last active January 8, 2020 12:10 — forked from collinjackson/main.dart
Demonstrates scrolling a focused widget into view
// Copyright 2017, the Flutter project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:meta/meta.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
/// A widget that ensures it is always visible when focused.
@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();