Skip to content

Instantly share code, notes, and snippets.

View davidgtonge's full-sized avatar

Dave Tonge davidgtonge

View GitHub Profile
@davidgtonge
davidgtonge / filter_elements.coffee
Created August 30, 2011 20:14
filtering an object with an array in coffeescript
filterElements = (validate, filter) ->
filtered = {}
for key, vars of validate
if key in filter then filtered[key] = value
filtered
@davidgtonge
davidgtonge / wpml_home_ids.php
Created September 19, 2011 20:56
Wordpress Home Piage IDs when using WPML
function get_wpml_home_ids(){
//Globalizse the $wpdb variable (instantiation of the wpdb class)
global $wpdb;
//Get the front-page id from the options table
$home_id = get_option('page_on_front');
//Run the query
$postids=$wpdb->get_col($wpdb->prepare("
@davidgtonge
davidgtonge / gist:1227605
Created September 19, 2011 21:01
home_page_ids
<?php
function get_wpml_home_ids(){
//Globalizse the $wpdb variable (instantiation of the wpdb class)
global $wpdb;
//Get the front-page id from the options table
$home_id = get_option('page_on_front');
//Run the query
@davidgtonge
davidgtonge / templates.coffee
Created September 20, 2011 06:29
Simple CoffeeScript Templating
# Simple Coffeescript Templating
# Global Object to hold the templates
window.simpleCoffeeTemplates =
# An example template
example: (a) ->
"""
<div>
<h1 class='header'>#{a.header}</h1>
@davidgtonge
davidgtonge / ward_from_postcode.php
Created September 20, 2011 22:42
UK Ward from Post Code
<?php
/*
* This function uses the mapit.mysociety.org api to
* retrieve ward names based on postcode
*/
function sc_get_ward_from_postcode($postcode)
{
//remove spaces and plus signs from the postcode
$postcode = str_replace(" ", "", $postcode);
$postcode = str_replace("+", "", $postcode);
@davidgtonge
davidgtonge / gist:1408899
Created November 30, 2011 12:26
simple infinite scroller
scroller = (elem, width, initialised = false) ->
multiple = 1
unless initialised
if width < 960
mutiple += Math.floor(960 / width)
cloned = (elem.text() for i in [1...multiple]).join('...')
elem.text cloned
animateBy = multiple * width
@davidgtonge
davidgtonge / graticules.coffee
Last active December 10, 2015 12:09
D3 Projections Animation
width = 960
height = 500
projections =
"Aitoff": d3.geo.aitoff
"Albers equal": d3.geo.albers
"August conformal": d3.geo.august
"Lambert azimuthal equal": d3.geo.azimuthalEqualArea
"Azimuthal equidistant": d3.geo.azimuthalEquidistant
"Bonne": d3.geo.bonne
@davidgtonge
davidgtonge / README.md
Last active December 10, 2015 12:29 — forked from mbostock/.block

This stacked bar chart is constructed from a CSV file storing the populations of different states by age group. The chart employs conventional margins and a number of D3 features:

@davidgtonge
davidgtonge / README.md
Last active December 12, 2015 00:08 — forked from mbostock/.block

This examples demonstrates how to use D3's brush component to implement focus + context zooming. Click and drag in the small chart below to pan or zoom.

input {
syslog {
add_field => {
"docker" => "true"
}
}
}
output {