Skip to content

Instantly share code, notes, and snippets.

View tomshaw's full-sized avatar
🎯
Focusing

Tom Shaw tomshaw

🎯
Focusing
View GitHub Profile
@tomshaw
tomshaw / raf-engine.js
Created May 3, 2019 13:30
Nuxt.js raf-engine plugin
import RAFEngine from 'raf-engine';
const engine = new RAFEngine();
export default (ctx, inject) => {
ctx.$engine = engine;
inject('engine', engine);
}
@tomshaw
tomshaw / locationService.js
Last active January 23, 2019 17:18
React native geo location service.
let settings = {
enableHighAccuracy: true,
timeout: 2e3,
maximumAge: 0
}
let watchId = null;
let messages = [];
messages['enabled'] = 'Location service is not enabled on your device.';
initDom() {
let output = $('div#m_ver_menu ul.m-menu__nav > li.m-menu__item--submenu').map(this.extractData).get();
console.log('output', output)
}
extractData() {
let $this = $(this);
let anchor = $this.find("a:first")[0];
let text = $(anchor).find("span:first").text();
let icon = $(anchor).find("i:first").attr('class');
@tomshaw
tomshaw / index.js
Created October 8, 2017 01:29
Example using recompose to sort and conditionally render a component.
import React from 'react';
import {
compose,
withProps,
branch,
renderNothing
} from 'recompose';
import List from './list';
import Item from './item';
@tomshaw
tomshaw / Select.js
Created July 10, 2016 23:41
Basic React Select
"use strict";
var React = require('react');
var Select = React.createClass({
propTypes: {
name: React.PropTypes.string.isRequired,
label: React.PropTypes.string.isRequired,
onChange: React.PropTypes.func.isRequired,
@tomshaw
tomshaw / smallest-index-value.js
Created May 31, 2014 17:44
Find the smallest index value in an array.
var array = [22, 44, 17, 47, 75, 26, 81, 15, 31, 23, 78, 95, 84, 29, 134, 64];
function indexOfSmallest(a) {
var lowest = 0;
for (var i = 1; i < a.length; i++) {
if (a[i] < a[lowest]) lowest = i;
}
return lowest;
}
@tomshaw
tomshaw / AdhocController.php
Created May 22, 2014 06:51
ZF2 RandomUser.me Controller/Action
<?php
namespace Application\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Http\Client;
use Zend\Http\Client\Adapter\Curl;
use Zend\Json\Json;
@tomshaw
tomshaw / Model.php
Last active August 29, 2015 13:57
ZF2 DB LOWER LIKE OR
<?php
$select->where
->literal('LOWER(campaign.title) LIKE "%'.strtolower($data['search']).'%"')
->or
->literal('LOWER(campaign.description) LIKE "%'.strtolower($data['search']).'%"');
@tomshaw
tomshaw / Dump.php
Last active December 16, 2015 18:00
ZF2 debug dump controller plugin.
<?php
namespace Application\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
use Zend\Debug\Debug;
class Dump extends AbstractPlugin
{
public function __invoke($var, $label = null, $echo = true)
@tomshaw
tomshaw / Purifier.php
Created April 25, 2013 03:19
ZF2 HTMLPurifier Controller Plugin.
<?php
namespace HTMLPurifier\Controller\Plugin;
use Zend\Mvc\Controller\Plugin\AbstractPlugin;
class Purifier extends AbstractPlugin
{
public function __invoke($data)
{