Skip to content

Instantly share code, notes, and snippets.

View stukennedy's full-sized avatar
💭
getting stuff done

Stu Kennedy stukennedy

💭
getting stuff done
View GitHub Profile
@stukennedy
stukennedy / thankyou.php
Created October 12, 2016 18:21
WooCommerce Continuata Integration
<?php
include('continuata.php');
$continuata = new Continuata(COMPANY_ID, COMPANY_PASSWORD);
$email = $order->billing_email;
$name = $order->billing_first_name.' '.$order->billing_last_name;
$price = $order->get_total();
$items = $order->get_items();
$num_items = count($items);
foreach ( $items as $line_item_data ) {
@stukennedy
stukennedy / riot-flux.md
Last active April 29, 2019 22:05
Implementing Flux architecture in RiotJS

Implementing Flux architecture in RiotJS

RiotControl seems an unnecessary dependency and has a critical issue whereby registering multiple stores causes any event to be triggered multiple times. I decided to create a minimal dispatcher.

Create a very simple dispatcher singleton called dispatcher.js:

import riot from 'riot'
@stukennedy
stukennedy / buffer-moore.js
Created November 12, 2016 00:47
A simple implementation of the Boyer-Moore string search algorithm for use with node.js' Buffer objects.
'use strict'
module.exports = {
alphabetSize: 256,
/*
Returns the index of the first occurence of
the `needle` buffer within the `haystack` buffer.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script src="https://cdn.jsdelivr.net/g/lodash@4(lodash.min.js+lodash.fp.min.js)"></script>
</head>
<body>
@stukennedy
stukennedy / path.md
Last active May 24, 2017 08:28
convert a path and resourcePath string into an object of parameters

take a path string and resourcePath string and parse into Object

import _ from 'lodash/fp'

const convertPath = (event) => {
  const path = _.flow(
    _.get('path'),
    _.split('/')
 )(event)
@stukennedy
stukennedy / numbersToWords.js
Created October 3, 2017 09:06
Javascript code to convert numbers to words
/* demo on JSBIN https://jsbin.com/hunagoj/7/edit?js,console */
// jshint esnext: true
const mapIndex = _.map.convert({ cap: false })
const units = ['', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
const tens = ['', 'ten', 'twenty', 'thirty', 'forty', 'fifty', 'sixty', 'seventy', 'eighty', 'ninety']
const thous = ['', 'thousand', 'million', 'billion', 'trillion']
const mapTens = ([u='0', t='']) =>
Number(t + u) < 20 ? units[Number(t + u)] : u === '0' ? tens[t] : `${tens[t]}-${units[u]}`
const mapSubBlocks = ([t, h='']) => [mapTens(t), !_.isEmpty(units[h]) ? `${units[h]} hundred` : '']
@stukennedy
stukennedy / fpbox.js
Last active April 25, 2018 22:55
FP Box - functional lodash style tools written in ES6
// jshint esnext: true
const curry = (f) => (...a) => (a.length < f.length) ? curry(f.bind(this, ...a)) : f(...a)
const clone = (obj) => Object.assign({}, obj)
const chain = (...fs) => (a) => fs.reduce((o, f) => f(o), a)
const isEmpty = curry((a) => !a || a === null || a === '' || Object.values(a).length === 0)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
/* eslint-disable no-console */
const { readdirSync } = require('fs')
const packageJson = require('./package.json');
const fs = require('fs');
const { exec } = require('child_process');
require('colors');
const args = process.argv.slice(2);
const getDirectories = source =>