Skip to content

Instantly share code, notes, and snippets.

@srayhunter
srayhunter / FetchContactsAsync.java
Last active April 26, 2024 20:22
Android - Get phone number and email address from Contacts
private class FetchContacts extends AsyncTask<Void, Void, ArrayList<Contact>> {
private final String DISPLAY_NAME = Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB ?
ContactsContract.Contacts.DISPLAY_NAME_PRIMARY : ContactsContract.Contacts.DISPLAY_NAME;
private final String FILTER = DISPLAY_NAME + " NOT LIKE '%@%'";
private final String ORDER = String.format("%1$s COLLATE NOCASE", DISPLAY_NAME);
@SuppressLint("InlinedApi")
@srayhunter
srayhunter / dp-to-pixels.md
Created January 6, 2016 06:59
Android - Convert DP to Pixels

Android - Convert DP to Pixels

Convert 32dp to pixels

Resources r = getResources();
float pixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, r.getDisplayMetrics());
@srayhunter
srayhunter / retrofit-callback-string.md
Created December 30, 2015 05:16
Retrofit Callback String Example
// notice the callback here
git.getFeed(new Callback<String>() {
	@Override
	public void success(String result, Response response) {
		Log.d("success" , "Data received: " + result);
	}
	
	@Override

public void failure(RetrofitError error) {

@srayhunter
srayhunter / android-adb-over-wifi.md
Last active June 22, 2022 16:41
Android ADB over Wifi

Android ADB over Wifi

Here is a simple way to use ADB over wifi with your device. Make sure that ADB can reach your device over the network.

  1. Connect device to usb

  2. Restart the ADB daemon to listening on TCP port

adb tcpip 5555

@srayhunter
srayhunter / android-update-commandline.md
Last active September 18, 2023 13:13
Android - Update Android SDK from the commandline

Android - Update Android SDK from the commandline

Update the installed packages

sdkmanager --update

List all items (--all is needed to show obsolete, build tools and other items)

sdkmanager --list
@srayhunter
srayhunter / gradle.properties
Created August 29, 2015 05:38
Android Gradle Build Properties for Mac OSX
# project gradle.properties by srayhunter@github
# run the daemon on builds
org.gradle.daemon=true
org.gradle.jvmargs=-Djava.awt.headless=true -Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
@srayhunter
srayhunter / listlayer.xml
Created August 29, 2015 05:32
Android List-Layer Drawable with VectorDrawable Text
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<solid android:color="@android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
<item android:drawable="@drawable/vector"/>
</layer-list>
100% — FF
95% — F2
90% — E6
85% — D9
80% — CC
75% — BF
70% — B3
65% — A6
60% — 99
55% — 8C

Keybase proof

I hereby claim:

  • I am srayhunter on github.
  • I am srayhunter (https://keybase.io/srayhunter) on keybase.
  • I have a public key whose fingerprint is BC4A 7F1D 19EF F5A9 D37E D7D9 A48E 7049 D73A B026

To claim this, I am signing this object:

@srayhunter
srayhunter / configure-apache-path-environment-variable-on-macosx.md
Last active April 27, 2022 12:56
Configure Apache on Mac OSX with Environment Variables

Configure Apache Path Environment Variable on Mac OSX

Problem: Apache2/PHP did not find a program to execute on its configured path

Solution: Add a new path of /usr/local/bin to Apache2's path where the program was installed

  1. Edit the Apache2 plist file with whatever editor you like (example using vim):

     $ sudo vim /System/Library/LaunchDaemons/org.apache.httpd.plist