Skip to content

Instantly share code, notes, and snippets.

View tuoxie007's full-sized avatar

Jason Hsu tuoxie007

View GitHub Profile
@tuoxie007
tuoxie007 / gist:6723865
Last active December 24, 2015 01:29
Detect iOS device version
+ (NSString *)platform{
size_t size;
sysctlbyname("hw.machine", NULL, &size, NULL, 0);
char *machine = malloc(size);
sysctlbyname("hw.machine", machine, &size, NULL, 0);
NSString *platform = [NSString stringWithUTF8String:machine];
free(machine);
return platform;
}
@tuoxie007
tuoxie007 / android-debug.sh
Last active February 26, 2018 06:35
android debug from cli
#!/bin/bash
package=<Your Package>
appname=<Your App Name>
level=0
if [ "$1" == "build" ]; then
level=0
if [ "$2" == "java" ]; then
@tuoxie007
tuoxie007 / gist:10224417
Last active August 29, 2015 13:58
convert mkv to mp4 without reencoding
背景:一般的mkv,視頻用的是h264,音頻用的是AC3,蘋果都支持,但mkv這種封裝格式蘋果不支持。
此命令是一個事例,適用于一般的mkv,此處不做視頻和音頻重編碼,只修改封裝格式,同時還把外掛字幕一並打上。
只轉封裝不重編碼的好處是速度快,基本相當于硬盤拷貝。
轉碼前最好先ffmpeg -i a.mkv看一下視頻信息再看要怎樣轉碼,具體信息可參考ffmpeg.org官方文檔
ffmpeg -i a.mkv -i a.eng.srt -map 0:0 -map 0:1 -map 1:0 -vcodec copy -acodec copy -scodec mov_text -metadata:s:s:0 language=eng -y b.mp4
@tuoxie007
tuoxie007 / android-keyboard-listener
Created April 11, 2014 13:18
监听键盘显示和隐藏事件
final View activityRootView = getWindow().getDecorView().findViewById(R.id.post_editor_dialog);
if (activityRootView != null) {
ViewTreeObserver observer = activityRootView.getViewTreeObserver();
if (observer != null) {
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
int lastHeightDiff;
@Override
public void onGlobalLayout() {
View rootView = activityRootView.getRootView();
if (rootView != null) {
@tuoxie007
tuoxie007 / android-themes.xml
Created April 16, 2014 09:55
android themes
<style name="PopupTheme" parent="android:Theme.Holo.Light.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowSoftInputMode">stateAlwaysVisible</item>
<item name="android:windowActionModeOverlay">true</item>
<item name="android:windowIsTranslucent">true</item>
</style>
<style name="PostTheme" parent="@android:style/Theme.Holo.Light">
<item name="android:actionBarStyle">@style/PostTheme.ActionBar</item>
@tuoxie007
tuoxie007 / android get text view size dynamiclly
Created April 17, 2014 12:54
android get text view size dynamiclly
TV.setText("bla");
TV.measure(0, 0); //must call measure!
TV.getMeasuredHeight(); //get width
TV.getMeasuredWidth();
@tuoxie007
tuoxie007 / get-timestamp-in-c-language
Created April 22, 2014 08:02
get-timestamp-in-c-language
#include <sys/time.h>
struct timeval tv;
gettimeofday(&tv, NULL);
double st = tv.tv_sec * 1.0 + tv.tv_usec / 1000000.0;
@tuoxie007
tuoxie007 / android-jni-call-method-in-java
Created April 22, 2014 08:05
android-jni-call-method-in-java
jclass native_class = (*env)->GetObjectClass(env, this);
jmethodID method_decodedFrame = (*env)->GetMethodID(env, native_class, "decodedFrame", "([I)V");
(*env)->CallVoidMethod(env, this, method_decodedFrame, result);
@tuoxie007
tuoxie007 / gist:ce46900f14490be8f82d
Last active August 29, 2015 14:06
linux-config-port-mirror
local_ip=
local_port=
remote_ip=
remote_port=
iptables -t nat -A PREROUTING -d $local_ip -p tcp --dport $local_port -j DNAT --to-destination $remote_ip:$local_port
iptables -t nat -A POSTROUTING -d $remote_ip -p tcp --dport $remote_port -j SNAT --to $local_ip
iptables -A FORWARD -o eth1 -d $remote_ip -p tcp --dport $remote_port -j ACCEPT
iptables -A FORWARD -i eth1 -s $remote_ip -p tcp --sport $remote_port -j ACCEPT
@tuoxie007
tuoxie007 / gist:2461739c087bb7d329c1
Created August 3, 2015 08:52
get current time in seconds since the Epoch on Linux, Bash
date +%s