Skip to content

Instantly share code, notes, and snippets.

Avatar

Ben Clayton benvium

  • www.calvium.com
  • Bristol, UK
View GitHub Profile
@benvium
benvium / react-native-parse-xml-example.js
Last active Jun 4, 2020
Parse XML Example using React Native.xmldom is a pure JavaScript implementation of an XML Parser. I've added it to window so that browser modules that require it will work. Tested on iOS and Android.
View react-native-parse-xml-example.js
/**
*
* Before use, type:
* ```
* npm install xmldom --save
* ```
*/
window.DOMParser = require('xmldom').DOMParser;
@benvium
benvium / react-native-ios-splash.m
Created Feb 23, 2016
React Native iOS Smooth Splash Screen (when using LaunchScreen.xib)
View react-native-ios-splash.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
...
...
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MyAwesomeApp"
initialProperties:@{}
launchOptions:launchOptions];
@benvium
benvium / convert.sh
Created Feb 15, 2016
Convert all WAVs in folder to mono 22050khz
View convert.sh
for file in *.wav; do ffmpeg -i "$file" -ac 1 -ar 20050 "../WAVout/$file"; done
@benvium
benvium / index.ios.js
Created Dec 18, 2015
React Native: Enable Login Button when username and password fields are filled in
View index.ios.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var signalr = require('react-native-signalr');
@benvium
benvium / .sh
Last active Mar 18, 2016
Gitignore file for Android Studio projects in Calvium
View .sh
########################################
#
# Calvium Android .gitignore
#
########################################
# Android NDK
**/src/main/obj
**/src/main/libs
@benvium
benvium / jsonExport.js
Last active Nov 27, 2015
Google Apps script JSON export. Adapted from http://blog.pamelafox.org/2013/06/exporting-google-spreadsheet-as-json.html. The only actual difference so far is that if the user has an array literal with a missing comma etc, an error is thrown with the details. Previously the script would just fail.
View jsonExport.js
// Includes functions for exporting active sheet or all sheets as JSON object (also Python object syntax compatible).
// Tweak the makePrettyJSON_ function to customize what kind of JSON to export.
// Adapted from http://blog.pamelafox.org/2013/06/exporting-google-spreadsheet-as-json.html
var FORMAT_ONELINE = 'One-line';
var FORMAT_MULTILINE = 'Multi-line';
var FORMAT_PRETTY = 'Pretty';
var LANGUAGE_JS = 'JavaScript';
var LANGUAGE_PYTHON = 'Python';
@benvium
benvium / getPackageName.sh
Last active Jan 7, 2021
Script to extract the android package id (app id) from an android apk file, and another to uninstall an app when you have the apk handy.
View getPackageName.sh
# extract the android package id from a built apk file
# usage ./getPackageName.sh <path-to-apk>
line=`aapt dump badging "$1" | grep package:\ name`
# above returns:
# package: name='com.calvium.myapp' versionCode='1' versionName='1.0'
if [[ $line =~ name=\'(.+)\'\ versionCode ]]; then
echo ${BASH_REMATCH[1]}
else
echo "Failed to find package name"
@benvium
benvium / update-build-number.sh
Created Oct 15, 2015
Script to update the build number stored in the plist file for an iOS project
View update-build-number.sh
#!/bin/sh
#
# SETUP INSTRUCTIONS
#-----------------------
#
# Add this file to a folder called 'scripts' at the same level as your xcodeproj file
# Open XCode
# Select Project on left-hand view
# TARGETS / your target
@benvium
benvium / indexPathAtEndOfScroll.m
Last active Sep 24, 2015
Which UICollectionViewCell will be visible once scrolling finishes? Below assumes a horizontally-oriented UICollectionView.
View indexPathAtEndOfScroll.m
- (void)scrollViewWillEndDragging:(UIScrollView *)scrollView
withVelocity:(CGPoint)velocity
targetContentOffset:(CGPoint *)targetContentOffset {
CGPoint point = *targetContentOffset;
// Get point in the Center of the view
CGPoint centerPoint = CGPointMake(point.x + CGRectGetWidth(scrollView.bounds) / 2, point.y);
NSIndexPath *path = [self.collectionView indexPathForItemAtPoint:centerPoint];
@benvium
benvium / generateAppIcon.sh
Last active Jan 12, 2021
Generate app icons and xcassets file from a single image. To use this, place script in `appname` folder inside your project (i.e. the folder that Xcode generates for you containing your source code, it's named after whatever you called the app). Create folder there called `RawImages`. Source icon should 1024x1024 and be called appIcon.png. If th…
View generateAppIcon.sh
#!/bin/bash -e
# --------------------------------------------------------
# Generate app icons and xcassets file from a single image
# Ben Clayton, Calvium Ltd.
# --------------------------------------------------------
# To use this, place script in `appname` folder inside your project (i.e. the folder that Xcode generates for you containing your source code, it's named after whatever you called the app).
# Create folder there called `RawImages`.
# Source icon should 1024x1024 and be called appIcon.png. If the icon changes, you can just run this again to regenerate everything.
# This script assumes that you have the default setup of an Images.xcassets file containing the AppIcon.appiconset.