Skip to content

Instantly share code, notes, and snippets.

View r0adkll's full-sized avatar

Drew Heavner r0adkll

View GitHub Profile

Keybase proof

I hereby claim:

  • I am r0adkll on github.
  • I am r0adkll (https://keybase.io/r0adkll) on keybase.
  • I have a public key whose fingerprint is 2BDD 0597 7238 19D0 0075 18FB FEEE 9236 FBB6 9F6B

To claim this, I am signing this object:

@r0adkll
r0adkll / release.gradle
Last active January 22, 2018 12:19
Gradle script for releasing Android build. Auto-Incrementing the build numbers and tagging in git then pushing back into version control so those numbers stay consistent across machines. CAVEAT: You will probably need to modify the release tasks to suit your build flavors (or lack thereof)
/*
* Copyright © 52inc 2015.
* All rights reserved.
*/
apply plugin: 'org.ajoberstar.grgit'
import groovy.json.*
def versionFile = file("../version.json")
@r0adkll
r0adkll / battery_reader.java
Created June 19, 2015 18:32
Get cached battery level
private static float mCurrentBatteryPct;
private static long mCurrentBatteryPctDateMs;
/**
* A flavor of {@link #getCurrentBatteryLevel(Context)} that only polls the battery level from the OS
* every once in a while in an attempt to limit battery drain vs battery data freshness.
*
* @param readingPeriodMs the reading period (ms)
* @return the current battery level(%)
@r0adkll
r0adkll / nickname.java
Created June 3, 2015 16:56
Get a users name from their Contact card
String nickName;
try {
Cursor c = getActivity().getContentResolver().query(ContactsContract.Profile.CONTENT_URI, null, null, null, null);
c.moveToFirst();
nickName = c.getString(c.getColumnIndex("display_name")).concat("'s Android");
c.close();
}catch (Exception e){
Timber.e("Unable to load user's contact information, reverting to default device name");
nickName = Build.MANUFACTURER + " - " + Build.PRODUCT;
}
@r0adkll
r0adkll / kerning.java
Created June 1, 2015 20:30
Small helper function for doing kerning on android texts
/**
* Apply kerning to a string
*
* @param src the source string
* @param kerning the amount of kerning
* @return the spannable output
*/
public static Spannable applyKerning(CharSequence src, float kerning) {
if (src == null) return null;
final int srcLength = src.length();
@r0adkll
r0adkll / lolconfigure.sh
Last active April 24, 2019 16:29
52inc lolcommits install and configure script
#!/bin/bash
# Post-Commit hook text
post_commit_hook_base='#!/bin/sh
### lolcommits hook (begin) ###
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export PATH="/usr/bin:/usr/local/bin:$PATH"\n'
post_commit_hook_suffix='\n### lolcommits hook (end) ###'
@r0adkll
r0adkll / slack.php
Last active December 15, 2015 14:41
Slack Incoming Webhook script for lolcommits plugin "uploldz"
<?php
/***************************************************************************************************
*
* Step 1: Save the sent file locally on the server
*
*/
$file_name = basename($_FILES["file"]["name"]);
$target_file = "images/".basename($_FILES["file"]["name"]);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
@r0adkll
r0adkll / appbar.xml
Last active August 29, 2015 14:15
stackoverflow_28632372
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.Toolbar
android:id="@+id/appbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:elevation="6dp"
@r0adkll
r0adkll / wrong_instance.java
Created October 9, 2014 03:03
isWrongInstance() for Android Main Activities
/**
* Dev tools and the play store (and others?) launch with a different intent, and so
* lead to a redundant instance of this activity being spawned. <a
* href="http://stackoverflow.com/questions/17702202/find-out-whether-the-current-activity-will-be-task-root-eventually-after-pendin"
* >Details</a>.
*/
private boolean isWrongInstance() {
if (!isTaskRoot()) {
Intent intent = getIntent();
boolean isMainAction = intent.getAction() != null && intent.getAction().equals(ACTION_MAIN);
@r0adkll
r0adkll / material_colors.xml
Created October 5, 2014 04:35
Material Design Colors
<!-- Colors specific to Material themes. -->
<resources>
<!-- RED -->
<color name="red_50">#fde0dc</color>
<color name="red_100">#f9bdbb</color>
<color name="red_200">#f69988</color>
<color name="red_300">#f36c60</color>
<color name="red_400">#e84e40</color>