Skip to content

Instantly share code, notes, and snippets.

Avatar
👽

Adrian Rowbotham aderowbotham

👽
View GitHub Profile
@aderowbotham
aderowbotham / stripe-intent.php
Last active Sep 16, 2021
PHP / Stripe payment
View stripe-intent.php
<?php
// uses "stripe/stripe-php": "6.37.0",
// this is in the body of an API controller function that my stripe form posts to
// frontend uses https://js.stripe.com/v3/
// **the js posts a body with `payment_method_id` or `payment_intent_id` depending on the step of the process**
// this is captured as a property of $input
function the_post_method()
{
@aderowbotham
aderowbotham / replace-content-not-attributes.js
Created Sep 6, 2021
Javascript replace HTML text but not affect attribute values in double quotes
View replace-content-not-attributes.js
// javascript (ES5)
function highlight(content, term, startWrapper, endWrapper){
// negative match for the pattern surrounded by quotes ""
// followed by positive match for the term on its own
// the required pattern is as follows but we have to use RegExp() to set the term dynamically
// regex = /(?!"*term*")(?:term)/ig
var expression = new RegExp('(?!"*' + term + ' *")(?:' + term + ')', "i");
return content.replace(expression, startWrapper + content.match(expression) + endWrapper);
}
@aderowbotham
aderowbotham / Cache-bust Gruntfile.js
Last active May 11, 2020
Set cache-busing file revision using Grunt
View Cache-bust Gruntfile.js
/*
Example using grunt-contrib-concat, but this should work with any package
Inject string-based timestamp into an output filename, e.g. vendor-min.ka2bct2u.js
*/
module.exports = function(grunt) {
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.initConfig({
@aderowbotham
aderowbotham / spreadsheet-concatenate.md
Last active Nov 2, 2015
Spreadsheet concatenation formulae
View spreadsheet-concatenate.md

Spreadsheet concatenation formulae

These are tested in Open Office. May need modifying for Excel.

Combine multiple address fields into one

Contatenate cells B5 - F5, inserting a comma and line break, only if the cell is not blank

=IF(TRIM(LEN(B5));B5&","&CHAR(10);"")&IF(TRIM(LEN(C5));C5&","&CHAR(10);"")&IF(TRIM(LEN(D5));D5&","&CHAR(10);"")&IF(TRIM(LEN(E5));E5&","&CHAR(10);"")&IF(TRIM(LEN(F5));F5;"")

View distribute_integers.js
// distribute a large integer as evenly as possible between any number of integer positions
// inputs
var total = 6;
var parts = 5;
var fractionFloored = Math.floor(total/parts);
var mod = total % parts;
var output = [];
@aderowbotham
aderowbotham / boolean-radio.html
Created Mar 16, 2015
Use Radio buttons for a boolean with Angular 1.3
View boolean-radio.html
<h1>How to use radio buttons to represent a boolean?</h1>
<!-- It's important to use `ng-value` for the boolean value and not just `value` -->
<h3>Enable some setting?</h3>
<label><input type="radio" ng-model="myBoolean" ng-value="false"> Yes</label>
<label><input type="radio" ng-model="myBoolean" ng-value="true"> No</label>
@aderowbotham
aderowbotham / keybase.md
Created Mar 5, 2015
Keybase proof of ID
View keybase.md

Keybase proof

I hereby claim:

  • I am aderowbotham on github.
  • I am aderowbotham (https://keybase.io/aderowbotham) on keybase.
  • I have a public key whose fingerprint is 00C0 9F60 154C 2381 73D6 16D3 E7F4 1CEC 1EFA 15CD

To claim this, I am signing this object:

@aderowbotham
aderowbotham / angular-debounce-wrapper.html
Created Feb 13, 2015
Debounce function wrapped in an Angular service
View angular-debounce-wrapper.html
<!DOCTYPE html>
<html xmlns:ng="http://angularjs.org" xmlns:svg="http://www.w3.org/2000/svg">
<head>
<meta charset="utf-8" />
<!--
NOTE: Angular has a debounce directive built in as of AngularJS 1.3 in the form
of ng-model-options: https://docs.angularjs.org/api/ng/directive/ngModelOptions
@aderowbotham
aderowbotham / pancake-simplify-menu.js
Created Nov 6, 2014
Hide items from the admin menu in Pancake (http://pancakeapp.com/)
View pancake-simplify-menu.js
// this works as of 6 Nov 2014, Pancake 4.6.10
// set the names of menu items you want to hide here (either the href or text content of each top-level link)
var itemsToHide = ["#proposals", "credit notes"];
$( document ).ready(function(){
hideMenuItems();
// run again after Pancake's JS has run
setTimeout(hideMenuItems, 50);
@aderowbotham
aderowbotham / cordova-setup.md
Last active Aug 29, 2015
Getting started with Cordova
View cordova-setup.md

#Setting up a Cordova Project #####HMTL London, 2014-07-23

Apache Cordova is a set of device APIs that allow a mobile app developer to access native device function such as the camera or accelerometer from JavaScript

PhoneGap is Adobe's implementation of Cordova. PhoneGap also offers the PhoneGap Build service. This is not covered here.