Skip to content

Instantly share code, notes, and snippets.

View adamsp's full-sized avatar

Adam Speakman adamsp

View GitHub Profile
@adamsp
adamsp / update.sh
Created February 5, 2014 07:57
Simple script to update my Octopress blog and push changes to git in one go. Now I type one command instead of 5!
#!/bin/bash
ERR_SITE_GEN=1
ERR_SITE_DEPLOY=2
ERR_GIT_ADD=3
ERR_GIT_COMMIT=4
ERR_GIT_PUSH=5
ERR_NO_COMMIT_MESSAGE=6
if [ $# -eq 0 ]; then
@adamsp
adamsp / update.sh
Created February 11, 2014 06:23
Simple bash script for updating & deploying an Octopress site, and committing your changes to git. Usage: "./update.sh This is your commit message"
#!/bin/bash
ERR_SITE_GEN=1
ERR_SITE_DEPLOY=2
ERR_GIT_ADD=3
ERR_GIT_COMMIT=4
ERR_GIT_PUSH=5
ERR_NO_COMMIT_MESSAGE=6
if [ $# -eq 0 ]; then
@adamsp
adamsp / gist:44b075f40ed5ff4e3ca7
Created March 10, 2015 14:48
Pull DB from Android device
adb shell "run-as com.your.app.package chmod 666 /data/data/com.your.app.package/databases/yourDbName.db"
adb pull /data/data/com.your.app.package/databases/yourDbName.db
@adamsp
adamsp / WCFDateTimeParser.java
Last active December 25, 2015 04:08
WCF services supply Dates over JSON in a strange format. This method takes a WCF-formatted Date string and parses it into a JodaTime DateTime object.
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
public class WCFDateTimeParser {
/**
* <p>WCF services supply Dates over JSON in a strange format. This method
* takes a WCF-formatted Date string and parses it into a JodaTime DateTime
* object. Assumes valid input matching a format described below.</p>
*
@adamsp
adamsp / DreamLinkMovementMethod.java
Last active December 26, 2015 17:49
How to create clickable links from TextViews within a DreamService.
/**
* Copyright 2013 Adam Speakman
*
* 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
@adamsp
adamsp / GsonRequest.java
Created November 25, 2013 06:25
A Volley request class for easy parsing of JSON using Gson.
/**
* Copyright 2013 Adam Speakman
*
* 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
@adamsp
adamsp / MainActivity.java
Created December 16, 2013 20:11
Date formatting inconsistencies on Android. Varies across locales, Date format settings, devices, and presumably across Android versions too.
package com.example.dtmformattingexamples;
import java.util.Date;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.DateFormat;
import android.widget.TextView;
@adamsp
adamsp / TextViewLinkHider.java
Created October 28, 2013 00:36
If you've got a TextView with clickable links setup using HTML and LinkMovementMethod ( http://stackoverflow.com/questions/2734270/how-do-i-make-links-in-a-textview-clickable/2746708#2746708 ), this class allows you to hide either the underlines or the entire link - useful, for example, if you're showing tweets and need to link to profiles etc.
/**
* Copyright 2013 Adam Speakman
*
* 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
@adamsp
adamsp / PagedList.kt
Created October 10, 2017 14:45
Paging Lib Blog PagedList.kt
val mainHandler = Handler(Looper.getMainLooper())
val pagedList = PagedList.Builder<Int, Screenshot>()
.setDataSource(dataSource)
.setMainThreadExecutor({ mainHandler.post(it) })
.setBackgroundThreadExecutor(diskExecutor)
.setConfig(PagedList.Config.Builder()
.setPageSize(8)
.setEnablePlaceholders(true)
.build())
@adamsp
adamsp / MainActivity.kt
Last active October 10, 2017 14:52
Paging Lib Blog MainActivity.kt
var screenshotLoader: ScreenshotLoader? = null
var adapter: ScreenshotPickerAdapter? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
screenshotLoader = SAFScreenshotLoader(contentResolver, diskExecutor)
adapter = ScreenshotPickerAdapter(this)
val recycler = findViewById(R.id.main_recycler) as RecyclerView?
recycler?.layoutManager = GridLayoutManager(this, 2)