Skip to content

Instantly share code, notes, and snippets.

View pezholio's full-sized avatar

Stuart Harrison pezholio

  • Birmingham / London
View GitHub Profile
@pezholio
pezholio / CreateCouncils.rb
Created January 27, 2012 16:24
CreateCouncils
class CreateCouncils < ActiveRecord::Migration
def change
create_table :councils do |t|
t.name :string
t.code :string
t.address :text
t.tel :text
t.fax :text
t.email :text
t.logo :text
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config (first_time)
** Invoke rails_env (first_time)
** Execute rails_env
** Execute db:load_config
** Execute db:migrate
== CreateCouncils: migrating =================================================
-- create_table(:councils)
@pezholio
pezholio / xml2array
Created February 25, 2012 20:26
PHP XML to Array
function xml2array($contents, $get_attributes=1) {
if(!$contents) return array();
if(!function_exists('xml_parser_create')) {
//print "'xml_parser_create()' function not found!";
return array();
}
//Get the XML parser of PHP - PHP must have this module for the parser to work
$parser = xml_parser_create();
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
@pezholio
pezholio / README.markdown
Created March 5, 2012 11:34 — forked from gudbergur/README.markdown
Bootstrap's Typeahead plugin extended (allowing for AJAX functionality) among other things

This is a fork of a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

I've added a couple of lines to the original fork to stop the default behaviour when tabbing. For the proper source, please see the original gist.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
@pezholio
pezholio / edubasekml.php
Created March 23, 2012 11:08
Parsing SPARQL results form eductation.data.gov.uk into KML
<h1>KML Generator for Edubase data</h1>
<?php
require_once("xmlparse.php");
if (!$_POST) {
$query = "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?authority ?label
WHERE {
?authority
@pezholio
pezholio / FFS
Created April 4, 2012 15:22
FFS
...
# For crying out loud
gem 'rake', '0.9.2.2'
...
@pezholio
pezholio / README.markdown
Created April 30, 2012 10:00
jq-wysihat fixes for IE

jq-wysihat is a great tool for wysiwyg if you want to sidestep ugly wysiwyg editors and roll your own. Unfortunately in my experience it wasn't working in IE.

After some fiddling, I managed to get it to work by removing the IE range stuff and including selection.js instead. It now works like a charm!

@pezholio
pezholio / app.rb
Created July 23, 2012 13:17
Mongomapper Geo maxDistance problems
get "/search" do
require 'mapit'
date_from = Date.to_mongo(Date.parse(params[:date_from])) rescue nil
date_to = Date.to_mongo(Date.parse(params[:date_to])) rescue Date.to_mongo(Date.today)
if params[:postcode] != ""
mapit = Mapit.GetPostcode(params[:postcode])
applications = Application.where(:latlng => {'$near' => [mapit["lat"], mapit["lng"]], '$maxDistance' => params[:within].to_i}, :refval => /#{params[:refval]}/i, :address => /#{params[:address]}/i)
else
@pezholio
pezholio / deploy.rb
Created July 25, 2012 16:58
Capistrano deploy recipe for Padrino and Passenger with symlinked database.rb and Github hosting
set :domain, "licensing.lichfield-001.vm.brightbox.net"
set :application, "licensing"
set :deploy_to, "/home/rails/#{application}"
set :user, "rails"
set :use_sudo, false
ssh_options[:forward_agent] = true
set :scm, :git
@pezholio
pezholio / app.rb
Created August 17, 2012 13:32
More Mongomapper Geo problems
mapit = Mapit.GetPostcode(params[:postcode])
EARTH_RADIUS_M = 3959
query[:latlng] = {'$nearSphere' => [mapit["lat"], mapit["lng"]], '$maxDistance' => Float(params[:within].to_i) / EARTH_RADIUS_M }
applications = Application.where(query)
@applications = applications.paginate({:order => :receiveddate.desc, :per_page=> 10, :page => params[:page]})