Skip to content

Instantly share code, notes, and snippets.

Avatar

Nick NickHolcombe

View GitHub Profile
@NickHolcombe
NickHolcombe / twilio-json.js
Last active Apr 3, 2020
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
View twilio-json.js
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
View podcast-list.json
{
"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",
View example-rss-feed.xml
<?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>
@NickHolcombe
NickHolcombe / twilio-rssfeed.js
Last active Apr 3, 2020
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
View twilio-rssfeed.js
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) {
@NickHolcombe
NickHolcombe / barcode-MainActivity.kt
Created Oct 4, 2019
Barcode blog MainActivity.kt
View barcode-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.*
View barcode-function-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,
@NickHolcombe
NickHolcombe / barcode-function-createBarcodeBitmap.kt
Last active Oct 4, 2019
Barcode blog createBarcodeBitmap.kt
View barcode-function-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-activity_main.xml
Last active Oct 4, 2019
Barcode blog activity_main.xml
View barcode-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-dimens.xml
Last active Oct 4, 2019
Barcode blog Dimens File
View barcode-dimens.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="width_barcode">300dp</dimen>
<dimen name="height_barcode">65dp</dimen>
</resources>
@NickHolcombe
NickHolcombe / ListAdapterWithHeader.kt
Last active May 1, 2022
Example of a RecyclerView Adapter based on ListAdapter with a header
View ListAdapterWithHeader.kt
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