Skip to content

Instantly share code, notes, and snippets.

View benvium's full-sized avatar

Ben Clayton benvium

  • Bristol, UK
View GitHub Profile
benvium /
Created February 20, 2015 16:14
How to change the version number on an existing APK without re-building

This requires the latest version of apktool.


# Open the apktool.yml text file
# Alter the versionCode and versionName entries

# now rebuild!
apktool build $OUTPUT_FOLDER 
benvium / smartReadFile.php
Created September 19, 2012 12:08
PHP File to allow seeking in HTML5 <audio> tag. NOTE: I did not write this, check links in code for credits.
* Reads the requested portion of a file and sends its contents to the client with the appropriate headers.
* This HTTP_RANGE compatible read file function is necessary for allowing streaming media to be skipped around in.
* @param string $location
* @param string $filename
* @param string $mimeType
* @return void
benvium / search-array.swift
Last active March 29, 2024 22:29
searching arrays in apple swift. Search for matching strings and strings containing other strings.
class Person {
var name = ""
var age = 0
init(name: String, age:Int) { = name
self.age = age
benvium /
Created July 2, 2013 08:09
Playing HTML5 video on fullscreen in android webview. Note: I did not write this, it has been taken from
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.webkit.WebChromeClient;
import android.widget.FrameLayout;
import android.widget.VideoView;
benvium /
Created August 29, 2014 10:49
Remove underlines from TextView links. Based on stackoverflow code.
package com.util.util;
import android.text.Spannable;
import android.text.TextPaint;
import android.widget.TextView;
public class TextViewUtils {
private static final String TAG = TextViewUtils.class.getSimpleName();
benvium / TextA11y.tsx
Created December 15, 2023 14:42
React Native <Text/> wrapper for accessibility font sizes with automatically-calculated maximum font size
// Maximum font size. Note For WCAG we should support at least 200% default font scale
* Use to calculate a maxFontSizeMultiplier for Text components to ensure
* the text size doesn't go beyond MAXIMUM_FONT_SIZE.
* Pass the style or a fixed number.
* If the original size is already bigger than 32, then the size will be unchanged.
export function getMaxFontSizeMultiplier(params: number | StyleProp<TextStyle>) {
benvium / useReducedMotion.tsx
Last active December 2, 2023 09:32
useReducedMotion hook - get if user has requested Prefers reduced motion (iOS) or Remove animations (Android). Live updates values
import {AccessibilityInfo} from 'react-native';
import {createContext, PropsWithChildren, useContext, useEffect, useState} from 'react';
type AccessibilitySettingsT = {
isReduceMotionEnabled: boolean;
const ReducedMotionContext = createContext<AccessibilitySettingsT>({isReduceMotionEnabled: false});
benvium / ios-xcassets-parser.ts
Created October 9, 2023 09:00
Xcode .xcassets color parser. Exports xcassets-format colors into a single hex format, with separate light and dark mode values.
import fs from 'fs';
import * as path from 'path';
import * as z from 'zod';
// Outputs all xcassets-format colors into hex format, with separate light and dark mode values.
// IMPORTANT: this only covers a couple of the color formats Xcode uses, and may not properly handle color spaces etc.
// Usage:
benvium / MyTabBar.m
Created March 5, 2015 11:22
UITabBarController slide animation. Slide left and right when tabs are selected. Based on code from StackOverflow (linked in code)
- (BOOL) tabBarController:(UITabBarController *)tabBarController
shouldSelectViewController:(UIViewController *)viewController {
NSUInteger controllerIndex = [self.viewControllers indexOfObject:viewController];
if (controllerIndex == tabBarController.selectedIndex) {
return NO;
benvium /
Created August 29, 2014 19:45
Fairly simply Retrofit custom error handling example. Is set up so that you don't need to do much work in the 'failure' handler of a retrofit call to get the user-visible error message to show. Works on all endpoints. There's lots of exception handling as our server folks like to keep us on our toes by sending all kinds of random stuff..!
// on error the server sends JSON
{ "error": { "data": { "message":"A thing went wrong" } } }
// create model classes..
public class ErrorResponse {
Error error;