Skip to content

Instantly share code, notes, and snippets.

@BrockReece
BrockReece / gulpfile.js
Last active November 1, 2015 10:54
Simple gulp file for linting and minifying js, compiling sass and deploying all to dist dir
var gulp = require('gulp');
var jshint = require('gulp-jshint'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
minifycss = require('gulp-minify-css'),
del = require('del');
@BrockReece
BrockReece / ArticleRoute.php
Created November 1, 2015 12:00
CakePHP custom Article routes with article title instead of Id
<?php
App::uses('CakeRoute', 'Routing/Route');
App::uses('ClassRegistry', 'Utility');
class ArticleRoute extends CakeRoute {
/**
* Default model to load for the Article routes
*
* @var string
@BrockReece
BrockReece / ReactBoostrapModalMixin.jsx
Created November 1, 2015 12:02
React Bootstrap Modal using custom mixin of common modal functions
ModalMixin = {
getInitialState: function() {
return { showModal: false };
},
close: function() {
this.setState({ showModal: false });
},
open: function() {
this.setState({ showModal: true });
},
@BrockReece
BrockReece / AnalyticsComponent.php
Created November 1, 2015 12:36
Generic CakePHP component to get basic Google analytics data for a page
<?php
App::uses('Component', 'Controller');
class AnalyticsComponent extends Component {
/**
* Default actions for component
*
* @var array
*/
public $actions = array('edit');
@BrockReece
BrockReece / BootstrapFormHelper.php
Last active November 1, 2015 12:48
Drop-in helper to extend cake form helper to work with bootstrap
<?php
App::uses('FormHelper', 'View/Helper');
class BootstrapFormHelper extends FormHelper {
/**
* Overide parent method to use bootstrap input classes
*
* @param string $fieldName name of field to pass to parent method
* @param array $options list of options to pass to parent method
*
<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
/**
* Handle an incoming request.
this.$http.post(this.resource, data, {
beforeSend(xhr) {
if (this.lastRequest) {
this.lastRequest.cancel()
}
this.lastRequest = xhr
},
}).then(response => {
//do something with request
})
@BrockReece
BrockReece / cloudwatch-pipeline.conf
Last active September 10, 2020 18:16
Logstash cloudwatch output sample pipeline
input {
http_poller {
urls => {
node => {
method => get
url => "http://localhost:9200/_cluster/health"
headers => {
Accept => "application/json"
}
}
@BrockReece
BrockReece / close-server-logs.yml
Created July 25, 2016 07:50
Curator script for closing old indices
actions:
1:
action: close
description: >-
Close indices older than 2 days (based on index name), for logstash
and beat indices.
options:
delete_aliases: False
timeout_override:
continue_if_exception: False
@BrockReece
BrockReece / Capitalize.js
Created October 26, 2016 11:33
Split slug into separate words and capitalise
field.field_slug.split('_').join(' ').replace(/\b\w/g, l => l.toUpperCase())