Skip to content

Instantly share code, notes, and snippets.

View stuartwakefield's full-sized avatar

Stuart Wakefield stuartwakefield

View GitHub Profile
@stuartwakefield
stuartwakefield / template.jsx
Created January 15, 2016 08:08
Basic React template, separating template from logic
'use strict';
// Dependencies for the template, React is
// required for JSX transform.
import React from 'react';
// Other templates and components can be
// imported here
import OtherTemplate from './other';
@stuartwakefield
stuartwakefield / matcher.js
Last active January 6, 2016 14:23
I provide a concise way of matching types in JavaScript
/**
* I provide a concise way of matching types:
*
* matcher(new ReferenceError('Naughty reference'))
* (TypeError, err => console.error('You gone done used the wrong type!'))
* (ReferenceError, err => console.error('There was a reference error'))
* (err => console.error('Dunno what that was...'))
*/
var matcher = function (obj) {
@stuartwakefield
stuartwakefield / ProductViewResponseBean.java
Last active January 6, 2016 07:03
Snippets for Replacing WebSphere JSP / JSTL Data Layer and Display Logic with Beans
package com.example;
public class ProductViewResponseBean implements java.io.Serializable {
public ProductViewResponseBean() {
// Code here
}
public void setResponse(Map response) {
// Code here
@stuartwakefield
stuartwakefield / web.xml
Last active December 6, 2015 21:42
Configuration web.xml for railo
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<servlet-name>cfml</servlet-name>
<description>CFML runtime</description>
@stuartwakefield
stuartwakefield / server.xml
Last active December 6, 2015 21:28
Example basic service section for server.xml for a backend application using AJP
<?xml version="1.0" encoding="UTF-8"?>
<Server
port="8005"
shutdown="SHUTDOWN">
<!-- ... -->
<Service name="MyExampleService">
<Connector
@stuartwakefield
stuartwakefield / example.js
Last active November 17, 2015 13:09
A simple set of functions that allow arbitrary JSObjects / object literals to be queried whilst avoiding undefined TypeErrors
// A mixture of people and gibberish...
var people = [{
name: 'Joe'
}, {
name: 'Greg',
friends: [ 'Joe', 'Sue' ],
attrs: {
age: 42
}
}, {}, null, 12, "Hello"];
@stuartwakefield
stuartwakefield / index.cfm
Created November 15, 2015 16:46
Creating a Java object in ColdFusion 8
<cfset test = CreateObject( "java", "my.custom.TestObject" ) />
@stuartwakefield
stuartwakefield / statsd.js
Last active August 29, 2015 14:22
StatsD InfluxDB blank config file with comments inline
// The statsd.js config file
{
// Leave graphitePort and graphiteHost unset to avoid sending stats to Graphite.
// Set debug flag and leave these unset to run in 'dry' debug mode -
// useful for testing statsd clients without a Graphite server.
// Hostname or IP of Graphite server
//graphitePort: 2003,
// Port of Graphite server
@stuartwakefield
stuartwakefield / digits.js
Created February 20, 2015 18:03
Expression to get number of digits for a number `x`
Math.floor(Math.log10(x)) + 1;
@stuartwakefield
stuartwakefield / sigmoid.py
Created February 17, 2015 10:36
Sigmoid function for logistic regression
import numpy
sigmoid = lambda z: 1/(1+numpy.exp(-z))
# Or for free...
from scipy.special import expit
# https://github.com/scipy/scipy/blob/e758c482efb8829685dcf494bdf71eeca3dd77f0/scipy/special/_logit.c.src#L29
Z = numpy.matrix(((0.0, float('inf')), (1.0, float('-inf'))))
sigmoid(Z)
# matrix([[ 0.5 , 1. ],