Skip to content

Instantly share code, notes, and snippets.

View ducalpha's full-sized avatar

Duc Bui ducalpha

View GitHub Profile
Sub CopyMultipleDiscreteCells()
'
' Copy multiple dicrete cells
'
'
Dim i As Long
For i = 1 To 9
Selection.Copy
ActiveCell.Offset(10, 0).Select
@ducalpha
ducalpha / AsyncTask.java
Created August 14, 2013 05:32
AsyncTask example
/* wrapper of Java thread */
public void onButtonClicked() {
new RxBytesCheck().execute();
}
private class RxBytesCheck extends AsyncTask<Void, Void, Long> {
@Override
protected Long doInBackground(Void... params)
{
return TrafficStats.getTotalRxBytes();
@ducalpha
ducalpha / new_gist_file
Created August 14, 2013 05:35
HTTP request on Android
private class HTTPRequestTest extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params)
{
String url = "http://cps.kaist.ac.kr/index.html";
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet(url);
#built application files
*.apk
*.ap_
# files for the DEX VM
*.dex
# Java class files
*.class
@ducalpha
ducalpha / ManuallyHidingMediaController.java
Created August 16, 2013 08:44
prevent MediaController from hiding automatically Read MediaController.java for more details
MediaController mediaController = new MediaController(videoView.getContext(), false) {
@Override
public void show() {
show(0);
}
};
@ducalpha
ducalpha / mRunnable.java
Created August 18, 2013 05:55
multithreading on Android
/* Tradditional Java thread */
Handler mHandler = new Handler();
private final Runnable mRunnable = new Runnable() {
public void run()
{
updateTotalRxBytes();
mHandler.postDelayed(mRunnable, 1000); // repeat after 1000ms
}
};
@ducalpha
ducalpha / RunnableAndroid.java
Created August 19, 2013 04:46
Multithreading in android
public static void start(int streamingMode) {
new Thread(new GproxyStart(streamingMode)).start();
}
private static class GproxyStart implements Runnable {
int streamingMode;
public GproxyStart(int streamingMode) {
this.streamingMode = streamingMode;
}
@ducalpha
ducalpha / setup_via.sh
Created August 20, 2013 08:32
extract IP address, default gateway, and add/del rule to routing table on Android/Linux
#!/system/bin/sh
IF=$1
CMD=$2
SERVER_NET='143.248.140.0/24'
IP=`ip -4 addr show $IF | grep 'inet ' | awk '{print $2}' | sed -e 's/\/[0-9]*//'`
DEF_GW=`ip ro show | grep -o "default.*$IF" | head -n1 | awk '{print $3}'`
if [ $# -ne 2 ]
then
echo "Usage: `basename $0` <network_name> <add|del>"
@ducalpha
ducalpha / Makefile
Created January 15, 2014 00:55
demonstrate the difference between user space PID, TID, and kernel space light-weight process (LWP) id
all:
gcc pid_tid.c -lpthread
./a.out
@ducalpha
ducalpha / functor_example.cc
Created January 19, 2014 04:47
functor example
// Source: http://stackoverflow.com/questions/356950/c-functors-and-their-uses
#include <assert.h>
#include <vector>
#include <algorithm>
#include <iostream>
struct add_x {
add_x(int x) : x(x) {}
int operator()(int y) {return x+y;}
private: int x;