Skip to content

Instantly share code, notes, and snippets.

@vuhung3990
vuhung3990 / Format 2digit
Created November 6, 2014 07:48
00, 01,......09
String.format("%02d", num);
@vuhung3990
vuhung3990 / Stream video
Created November 12, 2014 07:56
stream video with fast forward ( nagative PHP )
/**
* Description of VideoStream
*
* @author Rana
* @link http://codesamplez.com/programming/php-html5-video-streaming-tutorial
*/
class StreamVideo {
private $path = "";
@vuhung3990
vuhung3990 / SntpClient.java
Last active August 29, 2015 14:13
Sync time over NTP server.
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@vuhung3990
vuhung3990 / Copy to clipborad
Last active August 29, 2015 14:16
Copy text to clipborad, work on all devices
/**
* copy text to clipboard
* @param context
* @param copiedText
*/
public static void copyToClipBoard(Context context,String copiedText){
if(android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) {
android.text.ClipboardManager clipboard = (android.text.ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
clipboard.setText(copiedText);
} else {
@vuhung3990
vuhung3990 / get mine type of file
Last active August 29, 2015 14:16
get mine type for custom upload file
/**
* get mine type of file
*
* @param path
* @return mine type for upload file
*/
public static String getMimeType(String path, String useThisIfNull) {
String type = useThisIfNull;
String extension = null;
int i = path.lastIndexOf('.');
@vuhung3990
vuhung3990 / check internet connections
Last active August 29, 2015 14:16
check internet connections, permission: <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
/**
* Checks to see if the device is connected to a network (cell, wifi, etc).
*
* @param context The current Context or Activity that this method is called from
* @return true if a network connection is available, otherwise false.
*/
public static boolean isNetworkAvailable(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
return activeNetworkInfo != null && activeNetworkInfo.isConnected();
@vuhung3990
vuhung3990 / FFmpeg Install
Created March 31, 2015 07:12
Install ffmpeg ( tested on centos 7 | 2015-3-31)
# install Dependencies
yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel&&mkdir ~/ffmpeg_sources
# Yasm
cd ~/ffmpeg_sources&&git clone --depth 1 git://github.com/yasm/yasm.git&&cd yasm&&autoreconf -fiv&&./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin"&&make&&make install&&make distclean
# libx264
cd ~/ffmpeg_sources&&git clone --depth 1 git://git.videolan.org/x264&&cd x264&&./configure --prefix="$HOME/ffmpeg_build" --bindir="$HOME/bin" --enable-static&&make&&make install&&make distclean
# libfdk_aac
@vuhung3990
vuhung3990 / android animation loading.java
Created April 21, 2015 07:26
self-rotage animation
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
//Setup anim with desired properties
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE); //Repeat animation indefinitely
anim.setDuration(300); //Put desired duration per anim cycle here, in milliseconds
login_button = (ImageButton) view.findViewById(R.id.login_button);
login_button.setAnimation(anim);
private void setScreenSize() {
Display display = ((Activity) context).getWindowManager().getDefaultDisplay();
if (Build.VERSION.SDK_INT >= 17) {
//new pleasant way to get real metrics
DisplayMetrics realMetrics = new DisplayMetrics();
display.getRealMetrics(realMetrics);
width = realMetrics.widthPixels;
height = realMetrics.heightPixels;
@vuhung3990
vuhung3990 / Convert Px to Dp
Last active August 29, 2015 14:25
This method converts device specific pixels to density independent pixels.
/**
* This method converts device specific pixels to density independent pixels.
*
* @param px A value in px (pixels) unit. Which we need to convert into dp
* @return A float value to represent dp equivalent to px value
*/
public static float convertPixelsToDp(float px){
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
float dp = px / (metrics.densityDpi / 160f);
return dp;