Skip to content

Instantly share code, notes, and snippets.

View kevboutin's full-sized avatar

Kevin Boutin kevboutin

View GitHub Profile
@kevboutin
kevboutin / project.xml
Created April 5, 2013 01:08
This is a custom target to use with any ant build. The idea is that this file should be included into your build script and reference the dependency target where appropriate (ex. <import file="./project.xml" /> ). This step should be used after the publish directory is loaded up with all assets and ready to be deployed/packaged. Once this target…
<target name="-tarball">
<condition property="publish.exists">
<available file="${dir.publish}" type="dir"/>
</condition>
<condition property="dist.exists">
<available file="${dir.dist}" type="dir"/>
</condition>
<if>
<equals arg1="${publish.exists}" arg2="true"/>
<then>
@kevboutin
kevboutin / security.conf
Created April 8, 2013 21:41
This is a default addition to httpd.conf via Include for security purposes.
# ----------------------------------------------------------------------
# A little more security
# ----------------------------------------------------------------------
# To avoid displaying the exact version number of Apache being used, add the
# following to httpd.conf (it will not work in .htaccess):
# ServerTokens Prod
# "-Indexes" will have Apache block users from browsing folders without a
# default document Usually you should leave this activated, because you
@kevboutin
kevboutin / performance.conf
Last active December 15, 2015 23:29
This is a default addition to httpd.conf via Include for performance purposes.
# ----------------------------------------------------------------------
# Better website experience for IE users
# ----------------------------------------------------------------------
# Force the latest IE version, in various cases when it may fall back to IE7 mode
# github.com/rails/rails/commit/123eb25#commitcomment-118920
# Use ChromeFrame if it's installed for a better experience for the poor IE folk
<IfModule mod_headers.c>
Header set X-UA-Compatible "IE=Edge,chrome=1"
@kevboutin
kevboutin / gist:5768004
Created June 12, 2013 18:48
This Javascript will print out response headers to the console.
// https://github.com/bgrins/devtools-snippets
// Print out response headers for current URL
(function() {
var request=new XMLHttpRequest();
request.open('HEAD',window.location,false);
request.send(null);
var headers = request.getAllResponseHeaders();
@kevboutin
kevboutin / shop.html
Last active December 19, 2015 01:39
An example of how to handle the display of multiple products/items on a page in reponsive grid system. The media queries are not really required but they are there in case other things on the page will interact responsively.
<!DOCTYPE html>
<html>
<head>
<title>Product Shopping View Example</title>
<style>
/*
Original idea:
http://www.barrelny.com/blog/text-align-justify-and-rwd/
http://codepen.io/patrickkunka/pen/GECBF
*/
@kevboutin
kevboutin / calculateDistance.js
Last active January 30, 2016 15:22
Calculate shortest distance between two points
function calculateDistance(lat1, lon1, lat2, lon2) {
var R = 6371; // km
var dLat = (lat2 - lat1).toRad();
var dLon = (lon2 - lon1).toRad();
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) *
Math.sin(dLon / 2) * Math.sin(dLon / 2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
var d = R * c;
return d;
@kevboutin
kevboutin / webWorker.js
Created January 30, 2016 15:51
Example webworker library
// simple implementation of a thread pool
function Pool(size) {
var _this = this;
// set some defaults
this.taskQueue = [];
this.workerQueue = [];
this.poolSize = size;
this.addWorkerTask = function(workerTask) {
@kevboutin
kevboutin / hapi-cookies.js
Created February 26, 2016 20:57
Shows how to use hapi within node to manage state with cookies.
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ port: 8000 });
server.state('hello', {
//ttl = time to live
ttl: 60 * 60 * 1000,
isHttpOnly: true,
encoding: 'iron',
@kevboutin
kevboutin / hapi-request-validation.js
Created February 26, 2016 21:07
Shows how to use joi for request validation when using hapi within Node.js.
'use strict';
const Hapi = require('hapi');
const Joi = require('joi');
const server = new Hapi.Server();
server.connection({ port: 8000 });
// test by calling:
// http POST localhost:8000/user/123?id=456
// or for validation failure testing, call:
// http POST localhost:8000/user/123?id=foo
@kevboutin
kevboutin / hapi-friendly-error-pages.js
Last active February 26, 2016 21:21
Shows how to configure and use friendly error pages using extension events in hapi within node.
'use strict';
const Hapi = require('hapi');
const Boom = require('boom');
const server = new Hapi.Server();
server.connection({ port: 8000 });
// test by using this in browser:
// http://localhost:8000
server.register(require('vision'), () => {