Skip to content

Instantly share code, notes, and snippets.

View NickHolcombe's full-sized avatar

Nick NickHolcombe

View GitHub Profile
@NickHolcombe
NickHolcombe / ListAdapterWithHeader.kt
Last active October 18, 2023 00:16
Example of a RecyclerView Adapter based on ListAdapter with a header
package example
import android.support.v7.recyclerview.extensions.AsyncDifferConfig
import android.support.v7.recyclerview.extensions.AsyncListDiffer
import android.support.v7.util.DiffUtil
import android.support.v7.util.ListUpdateCallback
import android.support.v7.widget.RecyclerView
/**
* {@link RecyclerView.Adapter RecyclerView.Adapter} base class based on
@NickHolcombe
NickHolcombe / twilio-rssfeed.js
Last active April 3, 2020 11:23
Twilio function to turn an RSS feed into menu options that play a podcast - from https://www.brightec.co.uk/blog/podcasting-to-those-without-internet-access
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
let Parser = require('rss-parser');
let parser = new Parser();
// Define the list of sermons and fetch the data
const url = '<enter the URL of RSS feed to read>';
parser.parseURL(url, function (err, feed) {
if (err) {
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
<channel>
<item>
<title>The title of the podcast one</title>
<itunes:author>Author one</itunes:author>
<enclosure url="https://your-host-name/podcast-one.mp3" type="audio/mpeg"></enclosure>
</item>
<item>
<title>The title of the podcast two</title>
{
"sermons":[
{
"id": 1,
"title": "Description for first mp3, e.g. Sunday 9:15",
"url": "<enter URL of first mp3>"
},
{
"id": 2,
"title": "Description for second mp3, e.g. Sunday 10:45",
@NickHolcombe
NickHolcombe / twilio-json.js
Last active April 3, 2020 11:22
Twilio function to turn a JSON object into menu options that play a podcast - from https://www.brightec.co.uk/blog/podcasting-to-those-without-internet-access
exports.handler = function(context, event, callback) {
let twiml = new Twilio.twiml.VoiceResponse();
var fetch = require('node-fetch');
// Define the list of sermons and fetch the data
const url = '<enter the URL of the json object to read>';
fetch(url)
.then(response => response.json())
.then(function(data) {
// Validate we have some sermon data
@NickHolcombe
NickHolcombe / barcode-dimens.xml
Last active October 4, 2019 13:32
Barcode blog Dimens File
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="width_barcode">300dp</dimen>
<dimen name="height_barcode">65dp</dimen>
</resources>
@NickHolcombe
NickHolcombe / barcode-activity_main.xml
Last active October 4, 2019 13:32
Barcode blog activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image_barcode"
@NickHolcombe
NickHolcombe / barcode-MainActivity.kt
Created October 4, 2019 13:31
Barcode blog MainActivity.kt
package uk.co.brightec.barcodeblogpost
import android.graphics.Bitmap
import android.os.Bundle
import androidx.annotation.ColorInt
import androidx.appcompat.app.AppCompatActivity
import com.google.zxing.BarcodeFormat
import com.google.zxing.oned.Code128Writer
import kotlinx.android.synthetic.main.activity_main.*
@NickHolcombe
NickHolcombe / barcode-function-createBarcodeBitmap.kt
Last active October 4, 2019 13:30
Barcode blog createBarcodeBitmap.kt
private fun createBarcodeBitmap(
barcodeValue: String,
@ColorInt barcodeColor: Int,
@ColorInt backgroundColor: Int,
widthPixels: Int,
heightPixels: Int
): Bitmap {
val bitMatrix = Code128Writer().encode(
barcodeValue,
BarcodeFormat.CODE_128,
@NickHolcombe
NickHolcombe / barcode-function-displayBitmap.kt
Created October 4, 2019 13:30
Barcode blog displayBitmap.kt
private fun displayBitmap(value: String) {
val widthPixels = resources.getDimensionPixelSize(R.dimen.width_barcode)
val heightPixels = resources.getDimensionPixelSize(R.dimen.height_barcode)
image_barcode.setImageBitmap(
createBarcodeBitmap(
barcodeValue = value,
barcodeColor = getColor(R.color.colorPrimary),
backgroundColor = getColor(android.R.color.white),
widthPixels = widthPixels,