Skip to content

Instantly share code, notes, and snippets.

@yenliangl
yenliangl / Font smoothing settings in Snow Leopard
Last active September 5, 2015 22:25
Tune font smoothing of Snow Leopard in command line
# Open Terminal and enter,
# Replace 2 with a number between 0 and 3.
# 0: Light
# 1: Standard
# 2: Medium
# 3: Bold
defaults -currentHost write -globalDomain AppleFontSmoothing -int 2
@yenliangl
yenliangl / See if an application is installed
Created August 31, 2010 15:54
How to check if an application is installed in Android system
// If no resource for the given package exists, this package is not installed in the phone
try {
mGenieResources = getPackageManager().getResourcesForApplication(GENIE_PACKAGE_ID);
} catch (PackageManager.NameNotFoundException e) {
// no weather info available
Log.w(LOG_TAG, "Can't find "+GENIE_PACKAGE_ID+". Weather forecast will not be available.");
}
@yenliangl
yenliangl / fsnod
Created August 31, 2010 15:57
Build specified package and transfer to connected emulator/device
# build specified package and transfer it to the connected emulator/device.
function fsnod {
mmm -j6 frameworks/base frameworks/base/core/res snod
adb shell stop
adb sync
adb shell start
}
@yenliangl
yenliangl / gist:559257
Created August 31, 2010 16:00
Use jdb to debug Android application
# Use jdb to debug Android application
# Run ddms and select application to forward port.
ddms
# Execute jdb and attach to the listening application
jdb -attach localhost:8700
# Or in windows, need to specify connector explicitly
jdb -connect com.sun.jdi.SocketAttach:hostname=localhost,port=8700
@yenliangl
yenliangl / PerfectNumberFinder.java
Created September 4, 2011 13:08
Perfect number finder
public class PerfectNumberFinder {
public static boolean isPerect(int number) {
// get factors
List<Integer> factors = new ArrayList<Integer>();
factors.add(1);
factors.add(number);
for (int i = 2; i < Matj.sqrt(number); i++) {
if (number % i == 0) {
factors.add(i);
if (number / i != i) {
@yenliangl
yenliangl / gist:1437498
Created December 6, 2011 09:14
Detecting WiFi
private static boolean isConnected(Context context) {
ConnectivityManager connectivityManager = (ConnectivityManager)
context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = null;
if (connectivityManager != null) {
@yenliangl
yenliangl / gist:1437500
Created December 6, 2011 09:14
Check SD card state
Environment.getExternalStorageState()
@yenliangl
yenliangl / emacsclient.c.diff
Created December 27, 2011 13:44
Patch for emacsclient-23.3b
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index 6b7c7c3..c6df02d 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -1479,7 +1479,7 @@ w32_give_focus ()
/* Start the emacs daemon and try to connect to it. */
void
-start_daemon_and_retry_set_socket (void)
+start_daemon_and_retry_set_socket (char* sname)
@yenliangl
yenliangl / customize-compile.el
Created January 5, 2012 07:59
Customize compile command in Emacs
(define-key c++-mode-map [(f8)] 'my-make-compile-command)
(define-key c++-mode-map [(f9)] 'my-make-g-compile-command)
(defun my-make-compile-command ()
(interactive)
(set (make-local-variable 'compile-command)
(concat "make -C " default-directory))
;; (setq current-prefix-arg '(4)) ;C-u
(call-interactively 'compile))
@yenliangl
yenliangl / create_dedicated_emacs_server_for_each_screen.csh
Created January 5, 2012 08:10
Get Emacs workspace for each GNU screen
setenv DEFAULT_WORKSPACE "default"
if ( $?WORKSPACE == 0 ) then
setenv WORKSPACE $DEFAULT_WORKSPACE
endif
# Define alias 'et' to connect to the proper Emacs server identified by EMACS_SEVER_NAME
setenv EDITOR "emacsclient -s $WORKSPACE -t -a ''"
alias et "$EDITOR"
# Create alias 'kill-emacs' to kill proper Emacs server.